public class OverflowToDiskByteStorage extends java.lang.Object implements ByteStorage
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 and 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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
CloseableByteSource |
fromSource(com.google.common.io.ByteSource source)
Creates a new byte source from another byte source.
|
CloseableByteSource |
fromStream(java.io.InputStream stream)
Creates a new byte source by fully reading an input stream.
|
long |
getBytesUsed()
Obtains the number of bytes currently used.
|
long |
getDiskBytesUsed()
Obtains the number of bytes stored in disk.
|
long |
getMaxBytesUsed()
Obtains the maximum number of bytes ever used by this tracker.
|
long |
getMaxDiskBytesUsed()
Obtains the maximum number of bytes ever stored in disk.
|
long |
getMaxMemoryBytesUsed()
Obtains the maximum number of bytes ever stored in memory.
|
long |
getMemoryBytesUsed()
Obtains the number of bytes stored in memory.
|
CloseableByteSourceFromOutputStreamBuilder |
makeBuilder()
Creates a builder that is an output stream and can create a byte source.
|
public OverflowToDiskByteStorage(TemporaryDirectoryFactory temporaryDirectoryFactory) throws java.io.IOException
temporaryDirectoryFactory - the factory used to create a temporary directory where to
overflow to; the created directory will be closed when the OverflowToDiskByteStorage object is closedjava.io.IOException - failed to create the temporary directorypublic OverflowToDiskByteStorage(long memoryCacheSize,
TemporaryDirectoryFactory temporaryDirectoryFactory)
throws java.io.IOException
memoryCacheSize - the in-memory cache; a value of 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 the OverflowToDiskByteStorage object is closedjava.io.IOException - failed to create the temporary directorypublic CloseableByteSource fromStream(java.io.InputStream stream) throws java.io.IOException
ByteStoragefromStream in interface ByteStoragestream - the input streamjava.io.IOException - failed to read the streampublic CloseableByteSourceFromOutputStreamBuilder makeBuilder() throws java.io.IOException
ByteStoragemakeBuilder in interface ByteStorageCloseableByteSource can eventually
be obtained fromjava.io.IOException - failed to create the builder; this may happen if the builder require some
preparation such as temporary storage allocation that may failpublic CloseableByteSource fromSource(com.google.common.io.ByteSource source) throws java.io.IOException
ByteStoragefromSource in interface ByteStoragesource - the byte source to copy data fromjava.io.IOException - failed to read data from the byte sourcepublic long getBytesUsed()
ByteStoragegetBytesUsed in interface ByteStoragepublic long getMaxBytesUsed()
ByteStoragegetMaxBytesUsed in interface ByteStoragepublic long getMemoryBytesUsed()
public long getMaxMemoryBytesUsed()
public long getDiskBytesUsed()
public long getMaxDiskBytesUsed()
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOException