Class OverflowToDiskByteStorage
- java.lang.Object
-
- com.android.tools.build.apkzlib.bytestorage.OverflowToDiskByteStorage
-
- All Implemented Interfaces:
ByteStorage,java.io.Closeable,java.lang.AutoCloseable
public class OverflowToDiskByteStorage extends java.lang.Object implements ByteStorage
Byte storage that keeps data in memory up to a certain size. After that, older sources are moved to disk and the newer ones served from memory.Once unloaded to disk, sources are not reloaded into memory as that would be in direct conflict with the filesystem's caching and the costs would probably outweight the benefits.
The maximum memory used by storage is actually larger than the maximum provided. It may exceed the limit by the size of one source. That is because sources are always loaded into memory before the storage decides to flush them to disk.
-
-
Constructor Summary
Constructors Constructor Description OverflowToDiskByteStorage(long memoryCacheSize, TemporaryDirectoryFactory temporaryDirectoryFactory)Creates a new byte storage with the given memory cache size using the provided temporary directory to write data that overflows the memory size.OverflowToDiskByteStorage(TemporaryDirectoryFactory temporaryDirectoryFactory)Creates a new byte storage with the default memory cache using the provided temporary directory to write data that overflows the memory size.
-
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.longgetDiskBytesUsed()Obtains the number of bytes stored in disk.longgetMaxBytesUsed()Obtains the maximum number of bytes ever used by this tracker.longgetMaxDiskBytesUsed()Obtains the maximum number of bytes ever stored in disk.longgetMaxMemoryBytesUsed()Obtains the maximum number of bytes ever stored in memory.longgetMemoryBytesUsed()Obtains the number of bytes stored in memory.CloseableByteSourceFromOutputStreamBuildermakeBuilder()Creates a builder that is an output stream and can create a byte source.
-
-
-
Constructor Detail
-
OverflowToDiskByteStorage
public OverflowToDiskByteStorage(TemporaryDirectoryFactory temporaryDirectoryFactory) throws java.io.IOException
Creates a new byte storage with the default memory cache using the provided temporary directory to write data that overflows the memory size.- Parameters:
temporaryDirectoryFactory- the factory used to create a temporary directory where to overflow to; the created directory will be closed when theOverflowToDiskByteStorageobject is closed- Throws:
java.io.IOException- failed to create the temporary directory
-
OverflowToDiskByteStorage
public OverflowToDiskByteStorage(long memoryCacheSize, TemporaryDirectoryFactory temporaryDirectoryFactory) throws java.io.IOExceptionCreates a new byte storage with the given memory cache size using the provided temporary directory to write data that overflows the memory size.- Parameters:
memoryCacheSize- the in-memory cache; a value of {@link 0} will effectively disable in-memory cachingtemporaryDirectoryFactory- the factory used to create a temporary directory where to overflow to; the created directory will be closed when theOverflowToDiskByteStorageobject is closed- Throws:
java.io.IOException- failed to create the temporary directory
-
-
Method Detail
-
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
-
getMemoryBytesUsed
public long getMemoryBytesUsed()
Obtains the number of bytes stored in memory.
-
getMaxMemoryBytesUsed
public long getMaxMemoryBytesUsed()
Obtains the maximum number of bytes ever stored in memory.
-
getDiskBytesUsed
public long getDiskBytesUsed()
Obtains the number of bytes stored in disk.
-
getMaxDiskBytesUsed
public long getMaxDiskBytesUsed()
Obtains the maximum number of bytes ever stored in disk.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-