Interface ByteStorage

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Implementing Classes:
    ChunkBasedByteStorage, InMemoryByteStorage, OverflowToDiskByteStorage, TemporaryDirectoryStorage

    public interface ByteStorage
    extends java.io.Closeable
    Interface 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 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 CloseableByteSource can 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