Package org.flag4j.io
Class TensorOutputStream
java.lang.Object
java.io.OutputStream
org.flag4j.io.TensorOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
A class for writing tensors to a file in various formats.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final FileOutputStream
Stream for writing data to a file.private final ObjectOutputStream
Stream for serializing object. -
Constructor Summary
ConstructorDescriptionTensorOutputStream
(String fileName) CreatesTensorOutputStream
which will use anObjectOutputStream
to write serialized data to aFileOutputStream
which will in-turn write the serialized data to a file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the stream.void
write
(int b) Writes a bite to the output stream.void
write
(TensorBase<?, ?, ?, ?, ?, ?, ?> A) Writes aTensorBase
object to a file by serializing the object.Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write, write
-
Field Details
-
fileOut
Stream for writing data to a file. -
objectOut
Stream for serializing object.
-
-
Constructor Details
-
TensorOutputStream
CreatesTensorOutputStream
which will use anObjectOutputStream
to write serialized data to aFileOutputStream
which will in-turn write the serialized data to a file.- Parameters:
fileName
- File name, including extension, of file to write data to.- Throws:
IOException
- If an I/O error occurs while reading the stream header.
-
-
Method Details
-
write
Writes aTensorBase
object to a file by serializing the object.- Parameters:
A
- Object to write to file. This may be a real/complex dense or sparse tensor, matrix, or vector.- Throws:
IOException
-
write
Writes a bite to the output stream. This method will forward the write toObjectOutputStream.write(int)
.- Specified by:
write
in classOutputStream
- Parameters:
b
- thebyte
.- Throws:
IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the output stream has been closed.
-
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 classOutputStream
- Throws:
IOException
- If an I/O exception has occurred.
-