Package io.milton.common
Class BufferingOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- io.milton.common.BufferingOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public class BufferingOutputStream extends OutputStream
An output stream which will buffer data, initially using memory up to maxMemorySize, and then overflowing to a temporary file. To use this class you will write to it, and then close it, and then call getInputStream to read the data. The temporary file, if it was created, will be deleted when the inputstream is closed.
-
-
Constructor Summary
Constructors Constructor Description BufferingOutputStream(int maxMemorySize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voiddeleteTempFileIfExists()If this is called before the inputstream is used, then the inputstream will fail to open (because it needs the file!!) So should only use in exception handlersvoidflush()byte[]getInMemoryData()Gets the data currently held in memoryInputStreamgetInputStream()longgetSize()booleanisCompleteInMemory()returns true if the data is completely held in memoryvoidsetOnClose(Runnable r)voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Method Detail
-
getInputStream
public InputStream getInputStream()
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(int b) throws IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
getSize
public long getSize()
-
setOnClose
public void setOnClose(Runnable r)
-
isCompleteInMemory
public boolean isCompleteInMemory()
returns true if the data is completely held in memory- Returns:
-
getInMemoryData
public byte[] getInMemoryData()
Gets the data currently held in memory- Returns:
-
deleteTempFileIfExists
public void deleteTempFileIfExists()
If this is called before the inputstream is used, then the inputstream will fail to open (because it needs the file!!) So should only use in exception handlers
-
-