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.Serializable
AnInputStream
that is serializable- Author:
- jschwarz
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BUFFER_SIZE
static int
DEFAULT_IN_MEMORY_BYTES
static int
END_OF_STREAM
-
Constructor Summary
Constructors Modifier Constructor Description protected
SerializableInputStream()
SerializableInputStream(java.io.InputStream inputStream)
Creates aSerializableInputStream
for a given underlyingInputStream
SerializableInputStream(java.io.InputStream in, int bufferSize, int inMemoryBytes, java.io.File tempFileDirectory)
Creates aSerializableInputStream
for a given underlyingInputStream
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
java.io.InputStream
getInputStream()
This method returns the wrapped input stream that is serialized by this stream.void
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
static java.lang.Iterable<byte[]>
readChunksFromObjectStream(java.io.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(java.io.InputStream inputStream, int chunkSize, java.io.ObjectOutputStream outputStream)
This method serializes a givenInputStream
to 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 aSerializableInputStream
for 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 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 Detail
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classjava.io.InputStream
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in 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.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:
java.io.IOException
-
readChunksFromObjectStream
public static java.lang.Iterable<byte[]> readChunksFromObjectStream(java.io.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.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
-
-