Class ChunkBasedByteStorage

  • All Implemented Interfaces:
    ByteStorage, java.io.Closeable, java.lang.AutoCloseable

    public class ChunkBasedByteStorage
    extends java.lang.Object
    implements ByteStorage
    Byte storage that breaks byte sources into smaller byte sources. This storage uses another storage as a delegate and, when a source is requested, it will allocate one or more sources from the delegate to build the requested source.
    • Method Detail

      • getDelegate

        public ByteStorage getDelegate()
        Obtains the byte storage chunks are allocated from.
      • fromStream

        public CloseableByteSource fromStream​(java.io.InputStream stream)
                                       throws java.io.IOException
        Description copied from interface: ByteStorage
        Creates a new byte source by fully reading an input stream.
        Specified by:
        fromStream in interface ByteStorage
        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

        public CloseableByteSourceFromOutputStreamBuilder makeBuilder()
                                                               throws java.io.IOException
        Description copied from interface: ByteStorage
        Creates a builder that is an output stream and can create a byte source.
        Specified by:
        makeBuilder in interface ByteStorage
        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

        public CloseableByteSource fromSource​(com.google.common.io.ByteSource source)
                                       throws java.io.IOException
        Description copied from interface: ByteStorage
        Creates a new byte source from another byte source.
        Specified by:
        fromSource in interface ByteStorage
        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

        public long getBytesUsed()
        Description copied from interface: ByteStorage
        Obtains the number of bytes currently used.
        Specified by:
        getBytesUsed in interface ByteStorage
        Returns:
        the number of bytes
      • getMaxBytesUsed

        public long getMaxBytesUsed()
        Description copied from interface: ByteStorage
        Obtains the maximum number of bytes ever used by this tracker.
        Specified by:
        getMaxBytesUsed in interface ByteStorage
        Returns:
        the number of bytes
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException