Package nl.vpro.domain.image.backend
Class ImageStream
- java.lang.Object
-
- nl.vpro.domain.image.backend.ImageStream
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ReusableImageStream
public class ImageStream extends Object implements AutoCloseable
An image stream represents the actual blob data for an image.This contains an
InputStreamplus some information that may be provided by the backing implementation likegetLength()andgetEtag()The
ReusableImageStreamspecialization will allow for repeated calls ongetStream()resulting a stream that can be used over and over again.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImageStream.Builder
-
Field Summary
Fields Modifier and Type Field Description protected booleanclosedprotected StringcontentTypeprotected Stringetagprotected InstantlastModifiedprotected longlengthprotected org.meeuw.functional.ThrowingRunnable<IOException>onCloseprotected InputStreamstreamprotected URIurl
-
Constructor Summary
Constructors Modifier Constructor Description protectedImageStream(@NonNull InputStream stream, @javax.validation.constraints.Min(0L) long length, @Nullable Instant lastModified, @Nullable String contentType, @Nullable String etag, @Nullable URI url, @Nullable org.meeuw.functional.ThrowingRunnable<IOException> onClose)ImageStream(InputStream stream, long length, Instant lastModified)protectedImageStream(InputStream stream, Instant lastModified)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancanEqual(@Nullable Object other)voidclose()booleanequals(@Nullable Object o)StringgetContentType()StringgetEtag()InstantgetLastModified()longgetLength()org.meeuw.functional.ThrowingRunnable<IOException>getOnClose()InputStreamgetStream()URIgetUrl()inthashCode()static @NonNull ImageStream.BuilderimageStreamBuilder()booleanisClosed()static ReusableImageStreamof(byte[] bytes)static ImageStreamof(File file)static ImageStreamof(InputStream stream)static ImageStreamof(InputStream stream, Instant lastModified)static ImageStreamof(URL url)static ImageStreamof(Path file)voidsetClosed(boolean closed)voidsetContentType(String contentType)voidsetEtag(String etag)voidsetOnClose(org.meeuw.functional.ThrowingRunnable<IOException> onClose)voidsetUrl(URI url)@NonNull StringtoString()ImageStreamwithMetaData(BackendImageMetadata<?> metaData)
-
-
-
Field Detail
-
stream
protected InputStream stream
-
length
protected final long length
-
lastModified
protected final Instant lastModified
-
contentType
protected String contentType
-
etag
protected String etag
-
url
protected URI url
-
onClose
protected org.meeuw.functional.ThrowingRunnable<IOException> onClose
-
closed
protected boolean closed
-
-
Constructor Detail
-
ImageStream
protected ImageStream(InputStream stream, Instant lastModified)
-
ImageStream
public ImageStream(InputStream stream, long length, Instant lastModified)
-
ImageStream
protected ImageStream(@NonNull InputStream stream, @Min(0L) @javax.validation.constraints.Min(0L) long length, @Nullable Instant lastModified, @Nullable String contentType, @Nullable String etag, @Nullable URI url, @Nullable org.meeuw.functional.ThrowingRunnable<IOException> onClose)
-
-
Method Detail
-
of
public static ImageStream of(InputStream stream, Instant lastModified)
-
of
public static ImageStream of(InputStream stream)
-
of
public static ImageStream of(File file) throws IOException
- Throws:
IOException
-
of
public static ImageStream of(Path file) throws IOException
- Throws:
IOException
-
of
public static ImageStream of(URL url) throws IOException
- Throws:
IOException
-
of
public static ReusableImageStream of(byte[] bytes) throws IOException
- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
getStream
public InputStream getStream() throws IOException
- Throws:
IOException- if the stream could not be produces because closed.
-
withMetaData
public ImageStream withMetaData(BackendImageMetadata<?> metaData)
-
imageStreamBuilder
public static @NonNull ImageStream.Builder imageStreamBuilder()
-
getLength
public long getLength()
-
getLastModified
public Instant getLastModified()
-
getContentType
public String getContentType()
-
getEtag
public String getEtag()
-
getUrl
public URI getUrl()
-
getOnClose
public org.meeuw.functional.ThrowingRunnable<IOException> getOnClose()
-
isClosed
public boolean isClosed()
-
setContentType
public void setContentType(String contentType)
-
setEtag
public void setEtag(String etag)
-
setUrl
public void setUrl(URI url)
-
setOnClose
public void setOnClose(org.meeuw.functional.ThrowingRunnable<IOException> onClose)
-
setClosed
public void setClosed(boolean closed)
-
canEqual
protected boolean canEqual(@Nullable Object other)
-
-