Package io.inversion.utils
Class StreamBuffer
- java.lang.Object
-
- java.io.OutputStream
-
- io.inversion.utils.StreamBuffer
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class StreamBuffer extends java.io.OutputStreamUses 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 Constructor Description StreamBuffer()StreamBuffer(java.io.InputStream in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidfinalize()voidflush()longgetBufferSize()java.lang.StringgetContentType()java.io.InputStreamgetInputStream()Returns the data that was written to this stream.intgetLength()java.io.FilegetTempFile()java.lang.StringtoString()StreamBufferwithBufferSize(long bufferSize)StreamBufferwithContentType(java.lang.String contentType)voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Method Detail
-
write
public void write(byte[] b) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOExceptionReturns 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:
java.io.IOException
-
finalize
public void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
getContentType
public java.lang.String getContentType()
-
withContentType
public StreamBuffer withContentType(java.lang.String contentType)
-
getLength
public int getLength()
-
getBufferSize
public long getBufferSize()
-
withBufferSize
public StreamBuffer withBufferSize(long bufferSize)
-
getTempFile
public java.io.File getTempFile()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-