Package nl.vpro.domain.image.backend
Class ReusableImageStream
- java.lang.Object
-
- nl.vpro.domain.image.backend.ImageStream
-
- nl.vpro.domain.image.backend.ReusableImageStream
-
- All Implemented Interfaces:
AutoCloseable
public class ReusableImageStream extends ImageStream
A version ofImageStreamthat on first use ofgetStream()will copy the stream to a file, so you call it multiple times.- Since:
- 1.11
- Author:
- Roelof Jan Koekoek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReusableImageStream.Builderstatic classReusableImageStream.FileDeleter
-
Field Summary
-
Fields inherited from class nl.vpro.domain.image.backend.ImageStream
closed, contentType, etag, lastModified, length, onClose, stream, url
-
-
Constructor Summary
Constructors Constructor Description ReusableImageStream(InputStream stream)ReusableImageStream(InputStream stream, long length, Instant lastModified)ReusableImageStream(InputStream stream, Instant lastModified)ReusableImageStream(ImageStream stream)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static @NonNull ReusableImageStream.Builderbuilder()voidclose()voidcopy()voidcopyImageInfoTo(BackendImageMetadata<?> image)protected voidcreateShutDownHook()protected voidfinalize()@NonNull PathgetFile()byte[]getHash()longgetLength()InputStreamgetStream()static @PolyNull ReusableImageStreamof(@PolyNull ImageStream imageStream)protected voidremoveShutDownHook()ReusableImageStreamwithMetaData(BackendImageMetadata<?> metaData)-
Methods inherited from class nl.vpro.domain.image.backend.ImageStream
canEqual, equals, getContentType, getEtag, getLastModified, getOnClose, getUrl, hashCode, imageStreamBuilder, isClosed, of, of, of, of, of, of, setClosed, setContentType, setEtag, setOnClose, setUrl, toString
-
-
-
-
Constructor Detail
-
ReusableImageStream
public ReusableImageStream(InputStream stream)
-
ReusableImageStream
public ReusableImageStream(InputStream stream, Instant lastModified)
-
ReusableImageStream
public ReusableImageStream(InputStream stream, long length, Instant lastModified)
-
ReusableImageStream
public ReusableImageStream(ImageStream stream) throws IOException
- Throws:
IOException
-
-
Method Detail
-
of
public static @PolyNull ReusableImageStream of(@PolyNull ImageStream imageStream) throws IOException
- Throws:
IOException
-
getStream
public InputStream getStream() throws IOException
- Overrides:
getStreamin classImageStream- Throws:
IOException- if the stream could not be produces because closed.
-
getLength
public long getLength()
- Overrides:
getLengthin classImageStream
-
finalize
protected void finalize() throws Throwable
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classImageStream- Throws:
IOException
-
withMetaData
public ReusableImageStream withMetaData(BackendImageMetadata<?> metaData)
- Overrides:
withMetaDatain classImageStream
-
copyImageInfoTo
public void copyImageInfoTo(BackendImageMetadata<?> image) throws IOException
- Throws:
IOException
-
getHash
public byte[] getHash() throws IOException- Throws:
IOException
-
copy
public void copy() throws IOException- Throws:
IOException
-
createShutDownHook
protected void createShutDownHook()
-
removeShutDownHook
protected void removeShutDownHook()
-
getFile
public @NonNull Path getFile() throws IOException
- Throws:
IOException
-
builder
public static @NonNull ReusableImageStream.Builder builder()
-
-