Class ChunkBasedByteStorage
- java.lang.Object
-
- com.android.tools.build.apkzlib.bytestorage.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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()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.ByteStoragegetDelegate()Obtains the byte storage chunks are allocated from.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
-
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:ByteStorageCreates a new byte source by fully reading an input stream.- Specified by:
fromStreamin interfaceByteStorage- 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:ByteStorageCreates a builder that is an output stream and can create a byte source.- Specified by:
makeBuilderin interfaceByteStorage- 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
public CloseableByteSource fromSource(com.google.common.io.ByteSource source) throws java.io.IOException
Description copied from interface:ByteStorageCreates a new byte source from another byte source.- Specified by:
fromSourcein interfaceByteStorage- 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:ByteStorageObtains the number of bytes currently used.- Specified by:
getBytesUsedin interfaceByteStorage- Returns:
- the number of bytes
-
getMaxBytesUsed
public long getMaxBytesUsed()
Description copied from interface:ByteStorageObtains the maximum number of bytes ever used by this tracker.- Specified by:
getMaxBytesUsedin interfaceByteStorage- Returns:
- the number of bytes
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-