Package io.milton.common
Class BufferingOutputStream
java.lang.Object
java.io.OutputStream
io.milton.common.BufferingOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidIf 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[]Gets the data currently held in memorylonggetSize()booleanreturns true if the data is completely held in memoryvoidvoidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
BufferingOutputStream
public BufferingOutputStream(int maxMemorySize)
-
-
Method Details
-
getInputStream
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
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
-
getSize
public long getSize() -
setOnClose
-
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
-