Class HeapDisk
java.lang.Object
com.google.common.jimfs.HeapDisk
A resizable pseudo-disk acting as a shared space for storing file data. A disk allocates fixed
size blocks of bytes to files as needed and may cache blocks that have been freed for reuse. A
memory disk has a fixed maximum number of blocks it will allocate at a time (which sets the total
"size" of the disk) and a maximum number of unused blocks it will cache for reuse at a time
(which sets the minimum amount of space the disk will use once
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intThe current total number of blocks that are currently allocated to files.(package private) final RegularFileCache of free blocks to be allocated to files.private final intFixed size of each block for this disk.private final intMaximum total number of blocks that the disk may contain at any time.private final intMaximum total number of unused blocks that may be cached for reuse at any time. -
Constructor Summary
ConstructorsConstructorDescriptionHeapDisk(int blockSize, int maxBlockCount, int maxCachedBlockCount) Creates a new disk with the givenblockSize,maxBlockCountandmaxCachedBlockCount.HeapDisk(Configuration config) Creates a new disk using settings from the given configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidallocate(RegularFile file, int count) Allocates the given number of blocks and adds them to the given file.intReturns the size of blocks created by this disk.private RegularFilecreateBlockCache(int maxCachedBlockCount) voidfree(RegularFile file) Frees all blocks in the given file.voidfree(RegularFile file, int count) Frees the lastcountblocks from the given file.longReturns the total size of this disk.longReturns the current number of unallocated bytes on this disk.private static inttoBlockCount(long size, int blockSize) Returns the nearest multiple ofblockSizethat is invalid input: '<'=size.
-
Field Details
-
blockSize
private final int blockSizeFixed size of each block for this disk. -
maxBlockCount
private final int maxBlockCountMaximum total number of blocks that the disk may contain at any time. -
maxCachedBlockCount
private final int maxCachedBlockCountMaximum total number of unused blocks that may be cached for reuse at any time. -
blockCache
Cache of free blocks to be allocated to files. While this is stored as a file, it isn't used like a normal file: only the methods for accessing its blocks are used. -
allocatedBlockCount
private int allocatedBlockCountThe current total number of blocks that are currently allocated to files.
-
-
Constructor Details
-
HeapDisk
Creates a new disk using settings from the given configuration. -
HeapDisk
public HeapDisk(int blockSize, int maxBlockCount, int maxCachedBlockCount) Creates a new disk with the givenblockSize,maxBlockCountandmaxCachedBlockCount.
-
-
Method Details
-
toBlockCount
private static int toBlockCount(long size, int blockSize) Returns the nearest multiple ofblockSizethat is invalid input: '<'=size. -
createBlockCache
-
blockSize
public int blockSize()Returns the size of blocks created by this disk. -
getTotalSpace
public long getTotalSpace()Returns the total size of this disk. This is the maximum size of the disk and does not reflect the amount of data currently allocated or cached. -
getUnallocatedSpace
public long getUnallocatedSpace()Returns the current number of unallocated bytes on this disk. This is the maximum number of additional bytes that could be allocated and does not reflect the number of bytes currently actually cached in the disk. -
allocate
Allocates the given number of blocks and adds them to the given file.- Throws:
IOException
-
free
Frees all blocks in the given file. -
free
Frees the lastcountblocks from the given file.
-