diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java | 2 | ||||
-rw-r--r-- | src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java | 41 |
2 files changed, 37 insertions, 6 deletions
diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java index 2e742ed..e02757b 100644 --- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java +++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/GradleArtifact.java @@ -20,7 +20,7 @@ public class GradleArtifact { false ); if (files.isEmpty()) return Artifact.none(); - return StreamableArtifact.ofJar(identifier, type, files.iterator().next()); + return StreamableArtifact.ofFile(identifier, type, files.iterator().next()); } } diff --git a/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java b/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java index 4f3df7a..1b4377a 100644 --- a/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java +++ b/src/shared/java/com/amadornes/artifactural/base/artifact/StreamableArtifact.java @@ -1,7 +1,13 @@ package com.amadornes.artifactural.base.artifact; -import com.amadornes.artifactural.api.artifact.*; +import com.amadornes.artifactural.api.artifact.Artifact; +import com.amadornes.artifactural.api.artifact.ArtifactIdentifier; +import com.amadornes.artifactural.api.artifact.ArtifactMetadata; +import com.amadornes.artifactural.api.artifact.ArtifactType; +import com.amadornes.artifactural.api.artifact.MissingArtifactException; +import com.amadornes.artifactural.api.artifact.Streamable; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -10,12 +16,16 @@ import java.net.URL; public class StreamableArtifact extends ArtifactBase { - public static Artifact ofJar(ArtifactIdentifier identifier, ArtifactType type, File file) { - return ofStreamable(identifier, type, () -> new FileInputStream(file)); + public static Artifact ofFile(ArtifactIdentifier identifier, ArtifactType type, File file) { + return new StreamableFileArtifact(identifier, type, file); } public static Artifact ofURL(ArtifactIdentifier identifier, ArtifactType type, URL url) { - return ofStreamable(identifier, type, url::openStream); + return new StreamableArtifact(identifier, type, url::openStream); + } + + public static Artifact ofBytes(ArtifactIdentifier identifier, ArtifactType type, byte[] bytes) { + return new StreamableArtifact(identifier, type, () -> new ByteArrayInputStream(bytes)); } public static Artifact ofStreamable(ArtifactIdentifier identifier, ArtifactType type, Streamable streamable) { @@ -25,7 +35,7 @@ public class StreamableArtifact extends ArtifactBase { private final Streamable streamable; private StreamableArtifact(ArtifactIdentifier identifier, ArtifactType type, Streamable streamable) { - this(identifier, type, ArtifactMetadata.empty(), streamable); + this(identifier, type, new SimpleArtifactMetadata(), streamable); } private StreamableArtifact(ArtifactIdentifier identifier, ArtifactType type, ArtifactMetadata metadata, Streamable streamable) { @@ -53,4 +63,25 @@ public class StreamableArtifact extends ArtifactBase { return streamable.openStream(); } + private static class StreamableFileArtifact extends StreamableArtifact implements Artifact.Cached { + + private final File file; + + private StreamableFileArtifact(ArtifactIdentifier identifier, ArtifactType type, File file) { + super(identifier, type, () -> new FileInputStream(file)); + this.file = file; + } + + @Override + public File asFile() throws MissingArtifactException { + return file; + } + + @Override + public File getFileLocation() throws MissingArtifactException { + return file; + } + + } + } |