Package com.saperion.common.io
Class SerializableInputStream
java.lang.Object
java.io.InputStream
com.saperion.common.io.SerializableInputStream
- All Implemented Interfaces:
Closeable,Serializable,AutoCloseable
An
InputStream that is serializable- Author:
- jschwarz
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSerializableInputStream(InputStream inputStream) Creates aSerializableInputStreamfor a given underlyingInputStreamSerializableInputStream(InputStream in, int bufferSize, int inMemoryBytes, File tempFileDirectory) Creates aSerializableInputStreamfor a given underlyingInputStream -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()This method returns the wrapped input stream that is serialized by this stream.voidmark(int readlimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) static Iterable<byte[]>readChunksFromObjectStream(ObjectInputStream inputStream) This method expects the givenObjectInputStreamto hold the data of anInputStreamserialized bywriteStreamAsChunksToObjectStream(InputStream, int, ObjectOutputStream)and returns anIterablefor the serialized chunks of the stream.voidreset()longskip(long n) static voidwriteStreamAsChunksToObjectStream(InputStream inputStream, int chunkSize, ObjectOutputStream outputStream) This method serializes a givenInputStreamto a givenObjectOutputStream.Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE- See Also:
-
DEFAULT_IN_MEMORY_BYTES
public static final int DEFAULT_IN_MEMORY_BYTES- See Also:
-
END_OF_STREAM
public static final int END_OF_STREAM- See Also:
-
-
Constructor Details
-
SerializableInputStream
protected SerializableInputStream() -
SerializableInputStream
Creates aSerializableInputStreamfor a given underlyingInputStream- Parameters:
inputStream- the underlying input stream. Must not be null.
-
SerializableInputStream
public SerializableInputStream(InputStream in, int bufferSize, int inMemoryBytes, File tempFileDirectory) Creates aSerializableInputStreamfor a given underlyingInputStream- Parameters:
in- the underlying input stream. Must not be null.bufferSize- the size of the chunks used for serializationinMemoryBytes- number of bytes to keep in memory before using a temp file when deserializing the streamtempFileDirectory- directory to store temporary files in when deserializing the stream
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
getInputStream
This method returns the wrapped input stream that is serialized by this stream.- Returns:
- the wrapped input stream that is serialized by this stream
-
writeStreamAsChunksToObjectStream
public static void writeStreamAsChunksToObjectStream(InputStream inputStream, int chunkSize, ObjectOutputStream outputStream) throws IOException This method serializes a givenInputStreamto a givenObjectOutputStream.- Parameters:
inputStream- the stream to serializechunkSize- the size of the chunks the stream is serialized asoutputStream- the output stream to serialize to- Throws:
IOException
-
readChunksFromObjectStream
This method expects the givenObjectInputStreamto hold the data of anInputStreamserialized bywriteStreamAsChunksToObjectStream(InputStream, int, ObjectOutputStream)and returns anIterablefor the serialized chunks of the stream.NOTE: be aware that for performance reasons the
Iteratorreturned by the iterable will return the same byte array for most chunks. So if it is necessary - for whatever reason - to store the chunks one needs to copy them first- Parameters:
inputStream- an object input stream holding the data of anInputStreamserialized bywriteStreamAsChunksToObjectStream(InputStream, int, ObjectOutputStream)- Returns:
- an
Iterablefor the serialized chunks of the stream
-