/** * Allocate a number of blocks and mark them as used. * * @param length the number of bytes to allocate * @return the start position in bytes */ public long allocate(int length) { return freeSpace.allocate(length); }
/** * Mark the file as empty. */ public void clear() { freeSpace.clear(); }
/** * Mark the space as free. * * @param pos the position in bytes * @param length the number of bytes */ public void free(long pos, int length) { freeSpace.free(pos, length); }
/** * Mark the space as free. * * @param pos the position in bytes * @param length the number of bytes */ public void free(long pos, int length) { int start = getBlock(pos); int blocks = getBlockCount(length); set.clear(start, start + blocks); }
/** * Allocate a number of blocks and mark them as used. * * @param length the number of bytes to allocate * @return the start position in bytes */ public long allocate(int length) { int blocks = getBlockCount(length); for (int i = 0;;) { int start = set.nextClearBit(i); int end = set.nextSetBit(start + 1); if (end < 0 || end - start >= blocks) { set.set(start, start + blocks); return getPos(start); } i = end; } }
/** * Get the position of the first free space. * * @return the position. */ public long getFirstFree() { return getPos(set.nextClearBit(0)); }
/** * Mark the space as in use. * * @param pos the position in bytes * @param length the number of bytes */ public void markUsed(long pos, int length) { freeSpace.markUsed(pos, length); }
long getFirstFree() { return freeSpace.getFirstFree(); }
public int getFillRate() { return freeSpace.getFillRate(); }
long getFileLengthInUse() { return freeSpace.getLastFree(); }
/** * Mark the space as in use. * * @param pos the position in bytes * @param length the number of bytes */ public void markUsed(long pos, int length) { int start = getBlock(pos); int blocks = getBlockCount(length); set.set(start, start + blocks); }
/** * Allocate a number of blocks and mark them as used. * * @param length the number of bytes to allocate * @return the start position in bytes */ public long allocate(int length) { int blocks = getBlockCount(length); for (int i = 0;;) { int start = set.nextClearBit(i); int end = set.nextSetBit(start + 1); if (end < 0 || end - start >= blocks) { set.set(start, start + blocks); return getPos(start); } i = end; } }
/** * Get the position of the last (infinite) free space. * * @return the position. */ public long getLastFree() { return getPos(set.previousSetBit(set.size()-1) + 1); }
/** * Mark the space as in use. * * @param pos the position in bytes * @param length the number of bytes */ public void markUsed(long pos, int length) { freeSpace.markUsed(pos, length); }
long getFirstFree() { return freeSpace.getFirstFree(); }
public int getFillRate() { return freeSpace.getFillRate(); }
long getFileLengthInUse() { return freeSpace.getLastFree(); }
/** * Check whether one of the blocks is in use. * * @param pos the position in bytes * @param length the number of bytes * @return true if a block is in use */ public boolean isUsed(long pos, int length) { int start = getBlock(pos); int blocks = getBlockCount(length); for (int i = start; i < start + blocks; i++) { if (!set.get(i)) { return false; } } return true; }
/** * Allocate a number of blocks and mark them as used. * * @param length the number of bytes to allocate * @return the start position in bytes */ public long allocate(int length) { int blocks = getBlockCount(length); for (int i = 0;;) { int start = set.nextClearBit(i); int end = set.nextSetBit(start + 1); if (end < 0 || end - start >= blocks) { set.set(start, start + blocks); return getPos(start); } i = end; } }
/** * Create a new free space map. * * @param firstFreeBlock the first free block * @param blockSize the block size */ public FreeSpaceBitSet(int firstFreeBlock, int blockSize) { this.firstFreeBlock = firstFreeBlock; this.blockSize = blockSize; clear(); }