Package com.saperion.common.io
Class SerializableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.saperion.common.io.SerializableInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Serializable,java.lang.AutoCloseable
public class SerializableInputStream extends java.io.InputStream implements java.io.SerializableAnInputStreamthat is serializable- Author:
- jschwarz
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZEstatic intDEFAULT_IN_MEMORY_BYTESstatic intEND_OF_STREAM
-
Constructor Summary
Constructors Modifier Constructor Description protectedSerializableInputStream()SerializableInputStream(java.io.InputStream inputStream)Creates aSerializableInputStreamfor a given underlyingInputStreamSerializableInputStream(java.io.InputStream in, int bufferSize, int inMemoryBytes, java.io.File tempFileDirectory)Creates aSerializableInputStreamfor a given underlyingInputStream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()java.io.InputStreamgetInputStream()This method returns the wrapped input stream that is serialized by this stream.voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b)intread(byte[] b, int off, int len)static java.lang.Iterable<byte[]>readChunksFromObjectStream(java.io.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(java.io.InputStream inputStream, int chunkSize, java.io.ObjectOutputStream outputStream)This method serializes a givenInputStreamto a givenObjectOutputStream.
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_IN_MEMORY_BYTES
public static final int DEFAULT_IN_MEMORY_BYTES
- See Also:
- Constant Field Values
-
END_OF_STREAM
public static final int END_OF_STREAM
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SerializableInputStream
protected SerializableInputStream()
-
SerializableInputStream
public SerializableInputStream(java.io.InputStream inputStream)
Creates aSerializableInputStreamfor a given underlyingInputStream- Parameters:
inputStream- the underlying input stream. Must not be null.
-
SerializableInputStream
public SerializableInputStream(java.io.InputStream in, int bufferSize, int inMemoryBytes, java.io.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 Detail
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.InputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.InputStream- 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.InputStream- Throws:
java.io.IOException
-
mark
public void mark(int readlimit)
- Overrides:
markin classjava.io.InputStream
-
reset
public void reset() throws java.io.IOException- Overrides:
resetin classjava.io.InputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classjava.io.InputStream
-
getInputStream
public java.io.InputStream 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(java.io.InputStream inputStream, int chunkSize, java.io.ObjectOutputStream outputStream) throws java.io.IOExceptionThis 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:
java.io.IOException
-
readChunksFromObjectStream
public static java.lang.Iterable<byte[]> readChunksFromObjectStream(java.io.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.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
-
-