The CBFSVaultStream type is returned by some of the CBVault class's methods. All stream types in CBFS Vault share a common API, documented below.
This type provides a custom streaming API with full read, write, and seek functionality; and implements Closable in order to be compatible with the try-with-resources pattern. To interact with a stream via conventional Java streaming APIs, use the GetInputStream and GetOutputStream methods to obtain an InputStream or OutputStream object.
Gets or sets the length of the stream, in bytes.
Gets or sets the current position within the stream.
Closes the stream, releasing all resources currently allocated for it.
public void close();
Forces all data held by the stream's buffers to be written out to storage.
public void flush();
Creates a standard Java InputStream tied to the current CBFSVaultStream instance.
public InputStream getInputStream();
When an InputStream obtained from this method is closed, the CBFSVaultStream instance that created it is also closed (which, as Close describes, causes all other Java stream objects tied to that CBFSVaultStream instance to be closed as well).
Creates a standard Java OutputStream tied to the current CBFSVaultStream instance.
public OutputStream getOutputStream();
When an OutputStream obtained from this method is closed, the CBFSVaultStream instance that created it is also closed (which, as Close describes, causes all other Java stream objects tied to that CBFSVaultStream instance to be closed as well).
Reads a sequence of bytes from the stream and advances the current position within the stream by the number of bytes read.
Count specifies the number of bytes that should be read from the stream.
Returns a byte array containing the data read from the stream. The length of the returned byte array may be less than Count if that many bytes are not currently available, or may be 0 if the end of the stream has been reached.
Sets the current position within the stream based on a particular point of origin.
public long seek(long offset, CBFSVaultStream.SeekOrigin origin);
Offset specifies the offset in the stream to seek to, relative to Origin. SeekOrigin is an enum declared within the CBFSVaultStream class as shown above.
Returns the new position within the stream.
Writes a sequence of bytes to the stream and advances the current position within the stream by the number of bytes written.
Data specifies the data to write to the stream.
Returns the total number of bytes written to the stream.