Package io.inversion.utils
Class StreamBuffer
java.lang.Object
java.io.OutputStream
io.inversion.utils.StreamBuffer
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Uses an in memory buffer to hold output until bufferSize data is written then will switch over
to writing everything to a temp file. You get the data back by calling getInputStream() which
can be called multiple times, each time returning a new InputStream with all the data. Calling
getInputStream() will close the OutputStream and prevent additional writing.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidfinalize()voidflush()longReturns the data that was written to this stream.inttoString()withBufferSize(long bufferSize) withContentType(String contentType) voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
StreamBuffer
public StreamBuffer() -
StreamBuffer
-
-
Method Details
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
getInputStream
Returns the data that was written to this stream. If the stream is backed by a temp file, the file will be deleted when the inputStream is closed or finalized.- Returns:
- a stream containing the data written to this stream
- Throws:
IOException
-
finalize
-
getContentType
-
withContentType
-
getLength
public int getLength() -
getBufferSize
public long getBufferSize() -
withBufferSize
-
getTempFile
-
toString
-