Package org.flag4j.io
Class TensorInputStream
java.lang.Object
java.io.InputStream
org.flag4j.io.TensorInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
A
TensorInputStream
obtains bytes from a system file using a FileInputStream
containing a serialized
tensor, matrix, or vector. Then, deserializes that object using an ObjectInputStream
.-
Field Summary
Modifier and TypeFieldDescriptionprivate final FileInputStream
Stream for loading bytes from a system file.private final ObjectInputStream
Stream for deserializing an object. -
Constructor Summary
ConstructorDescriptionTensorInputStream
(String fileName) CreatesTensorInputStream
which will open a connection with a file through anObjectInputStream
and aFileInputStream
. -
Method Summary
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
fileIn
Stream for loading bytes from a system file. -
objectIn
Stream for deserializing an object.
-
-
Constructor Details
-
TensorInputStream
CreatesTensorInputStream
which will open a connection with a file through anObjectInputStream
and aFileInputStream
. ThisTensorInputStream
can be used to deserialize a tensor, matrix, or vector which is stored in a system file.- Parameters:
fileName
- File name, including extension, of tensor, matrix, or vector to read.- Throws:
IOException
- If an I/O error occurs while reading the stream header.
-
-
Method Details
-
readTensor
Reads a serializedtesnor
from a file.- Returns:
- The deserialized
tensor object
stored in the specified file. - Throws:
IOException
ClassNotFoundException
-
readMatrix
Reads a serializedmatrix
from a file.- Returns:
- The deserialized
matrix object
stored in the specified file. - Throws:
IOException
ClassNotFoundException
-
readVector
Reads a serializedvector
from a file.- Returns:
- The deserialized
vector object
stored in the specified file. - Throws:
IOException
ClassNotFoundException
-
read
Reads a byte of data. This method will block if no input is available. The read operation is forwarded toObjectInputStream.read()
.- Specified by:
read
in classInputStream
- Returns:
- the next byte of data, or
-1
if the end of the stream is reached. - Throws:
IOException
- If an I/O error occurs.
-
close
Closes the stream. This method must be called to release any resources associated with the stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- If an I/O exception has occurred.
-