Interface ByteStorage
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Implementing Classes:
ChunkBasedByteStorage,InMemoryByteStorage,OverflowToDiskByteStorage,TemporaryDirectoryStorage
public interface ByteStorage extends java.io.CloseableInterface for a storage that will temporarily save bytes. There are several factory methods to create byte sources from several inputs, all of which may be discarded after the byte source has been created. The data is saved in the storage and will be kept until the byte source is closed.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description CloseableByteSourcefromSource(com.google.common.io.ByteSource source)Creates a new byte source from another byte source.CloseableByteSourcefromStream(java.io.InputStream stream)Creates a new byte source by fully reading an input stream.longgetBytesUsed()Obtains the number of bytes currently used.longgetMaxBytesUsed()Obtains the maximum number of bytes ever used by this tracker.CloseableByteSourceFromOutputStreamBuildermakeBuilder()Creates a builder that is an output stream and can create a byte source.
-
-
-
Method Detail
-
fromStream
CloseableByteSource fromStream(java.io.InputStream stream) throws java.io.IOException
Creates a new byte source by fully reading an input stream.- Parameters:
stream- the input stream- Returns:
- a byte source containing the cached data from the given stream
- Throws:
java.io.IOException- failed to read the stream
-
makeBuilder
CloseableByteSourceFromOutputStreamBuilder makeBuilder() throws java.io.IOException
Creates a builder that is an output stream and can create a byte source.- Returns:
- a builder where data can be written to and a
CloseableByteSourcecan eventually be obtained from - Throws:
java.io.IOException- failed to create the builder; this may happen if the builder require some preparation such as temporary storage allocation that may fail
-
fromSource
CloseableByteSource fromSource(com.google.common.io.ByteSource source) throws java.io.IOException
Creates a new byte source from another byte source.- Parameters:
source- the byte source to copy data from- Returns:
- the tracked byte source
- Throws:
java.io.IOException- failed to read data from the byte source
-
getBytesUsed
long getBytesUsed()
Obtains the number of bytes currently used.- Returns:
- the number of bytes
-
getMaxBytesUsed
long getMaxBytesUsed()
Obtains the maximum number of bytes ever used by this tracker.- Returns:
- the number of bytes
-
-