public class SerializableInputStream
extends java.io.InputStream
implements java.io.Serializable
InputStream which wraps another InputStream, so that intra-jvm access is done directly on that
stream. However, when it's
serialized, the data is sent on chunks and, when read on the other side, those chunks are written in a temporary
file. So, it's safe to serialize
large amount of data without consuming large memory.| Constructor and Description |
|---|
SerializableInputStream(java.sql.Blob blob)
Wraps the given blob, and calls
forceCopyToFile(), as blobs can only be accessed from within a database
transaction |
SerializableInputStream(byte[] bytes)
Shortcut to
SerializableInputStream(InputStream) using a ByteArrayInputStream |
SerializableInputStream(java.io.File file)
Reads the given file, deleting it when
close() is invoked |
SerializableInputStream(java.io.InputStream inputStream)
Wraps the given stream
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
java.io.File |
file()
Returns a temporary
File with the contents of this stream. |
java.io.File |
forceCopyToFile()
Exhausts the open stream and copy the contents to a temporary file.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
public SerializableInputStream(java.sql.Blob blob)
throws java.io.IOException
forceCopyToFile(), as blobs can only be accessed from within a database
transactionjava.io.IOExceptionpublic SerializableInputStream(byte[] bytes)
SerializableInputStream(InputStream) using a ByteArrayInputStreampublic SerializableInputStream(java.io.File file)
close() is invokedpublic SerializableInputStream(java.io.InputStream inputStream)
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic java.io.File file()
throws java.io.IOException,
java.lang.IllegalStateException
File with the contents of this stream. When the stream has been serialized, the
contents is already on a temporary
file, so it is returned. Otherwise, copy the wrapped stream into a temporary file and return it. It is important
to state that after this
method is invoked, the temporary file will no longer be deleted when this stream is closed, and it's the callers
responsibility to remove the
temporary file.java.io.IOException - When there was an error reading to the temporary filejava.lang.IllegalStateException - When this stream was already closedpublic java.io.File forceCopyToFile()
throws java.io.IOException
file() method), so, subsequent invocation of close() method
will delete the filejava.io.IOException - Error writing to filepublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOException