Class TemporaryDirectoryStorage
- java.lang.Object
-
- com.android.tools.build.apkzlib.bytestorage.TemporaryDirectoryStorage
-
- All Implemented Interfaces:
ByteStorage,java.io.Closeable,java.lang.AutoCloseable
public class TemporaryDirectoryStorage extends java.lang.Object implements ByteStorage
Byte storage that keeps all byte sources as files in a temporary directory. Each data stored is stored as a new file. The file is deleted as soon as the byte source is closed.
-
-
Constructor Summary
Constructors Constructor Description TemporaryDirectoryStorage(TemporaryDirectoryFactory temporaryDirectoryFactory)Creates a new storage using the provided temporary directory.
-
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.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.
-
-
-
Constructor Detail
-
TemporaryDirectoryStorage
public TemporaryDirectoryStorage(TemporaryDirectoryFactory temporaryDirectoryFactory) throws java.io.IOException
Creates a new storage using the provided temporary directory.- Parameters:
temporaryDirectoryFactory- a factory used to create the directory to use for temporary files; this directory will be closed when theTemporaryDirectoryStorageis 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
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-