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 int
static final int
static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
SerializableInputStream
(InputStream inputStream) Creates aSerializableInputStream
for a given underlyingInputStream
SerializableInputStream
(InputStream in, int bufferSize, int inMemoryBytes, File tempFileDirectory) Creates aSerializableInputStream
for a given underlyingInputStream
-
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
This method returns the wrapped input stream that is serialized by this stream.void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) static Iterable<byte[]>
readChunksFromObjectStream
(ObjectInputStream inputStream) This method expects the givenObjectInputStream
to hold the data of anInputStream
serialized bywriteStreamAsChunksToObjectStream(InputStream, int, ObjectOutputStream)
and returns anIterable
for the serialized chunks of the stream.void
reset()
long
skip
(long n) static void
writeStreamAsChunksToObjectStream
(InputStream inputStream, int chunkSize, ObjectOutputStream outputStream) This method serializes a givenInputStream
to 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 aSerializableInputStream
for 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 aSerializableInputStream
for 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:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in 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 givenInputStream
to 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 givenObjectInputStream
to hold the data of anInputStream
serialized bywriteStreamAsChunksToObjectStream(InputStream, int, ObjectOutputStream)
and returns anIterable
for the serialized chunks of the stream.NOTE: be aware that for performance reasons the
Iterator
returned 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 anInputStream
serialized bywriteStreamAsChunksToObjectStream(InputStream, int, ObjectOutputStream)
- Returns:
- an
Iterable
for the serialized chunks of the stream
-