Methods Summary |
---|
public int | appendData(java.io.InputStream is, int count)
if (count <= 0) {
return 0;
}
long startPos = length;
long lastPos = length + count - 1;
grow(lastPos); // Changes length
int blockIdx = (int)(startPos >> BLOCK_SHIFT);
int offset = (int) (startPos & BLOCK_MASK);
int bytesAppended = 0;
while (count > 0) {
byte[] block = blocks.get(blockIdx);
int toCopy = Math.min(BLOCK_SIZE - offset, count);
count -= toCopy;
while (toCopy > 0) {
int bytesRead = is.read(block, offset, toCopy);
if (bytesRead < 0) {
length -= (count - bytesAppended);
return bytesAppended;
}
toCopy -= bytesRead;
offset += bytesRead;
}
blockIdx++;
offset = 0;
}
return count;
|
public void | close()
blocks.clear();
length = 0;
|
public void | freeBefore(long pos)
int blockIdx = (int)(pos >> BLOCK_SHIFT);
if (blockIdx <= firstUndisposed) { // Nothing to do
return;
}
for (int i = firstUndisposed; i < blockIdx; i++) {
blocks.set(i, null);
}
firstUndisposed = blockIdx;
|
public void | getData(java.io.OutputStream os, int count, long pos)
if (pos + count > length) {
throw new IndexOutOfBoundsException("Argument out of cache");
}
int blockIdx = (int)(pos >> BLOCK_SHIFT);
int offset = (int) (pos & BLOCK_MASK);
if (blockIdx < firstUndisposed) {
throw new IndexOutOfBoundsException("The requested data are already disposed");
}
while (count > 0) {
byte[] block = blocks.get(blockIdx);
int toWrite = Math.min(BLOCK_SIZE - offset, count);
os.write(block, offset, toWrite);
blockIdx++;
offset = 0;
count -= toWrite;
}
|
public int | getData(long pos)
if (pos >= length) {
return -1;
}
byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
return block[(int)(pos & BLOCK_MASK)] & 0xFF;
|
public int | getData(byte[] buffer, int offset, int count, long pos)
if (count > buffer.length - offset || count < 0 || offset < 0) {
throw new IndexOutOfBoundsException();
}
if (count == 0) {
return 0;
}
if (pos >= length) {
return -1;
}
if (count + pos > length) {
count = (int) (length - pos);
}
byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
int nbytes = Math.min(count, BLOCK_SIZE - (int)(pos & BLOCK_MASK));
System.arraycopy(block, (int)(pos & BLOCK_MASK), buffer, offset, nbytes);
return nbytes;
|
private void | grow(long pos)
int blocksNeeded = (int)(pos >> BLOCK_SHIFT) - blocks.size() + 1;
for (int i=0; i < blocksNeeded; i++) {
blocks.add(new byte[BLOCK_SIZE]);
}
length = pos + 1;
|
public long | length()
return length;
|
public void | putData(int oneByte, long pos)
if (pos >= length) {
grow(pos);
}
byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
block[(int)(pos & BLOCK_MASK)] = (byte) oneByte;
|
public void | putData(byte[] buffer, int offset, int count, long pos)
if (count > buffer.length - offset || count < 0 || offset < 0) {
throw new IndexOutOfBoundsException();
}
if (count == 0){
return;
}
long lastPos = pos + count - 1;
if (lastPos >= length) {
grow(lastPos);
}
while (count > 0) {
byte[] block = blocks.get((int)(pos >> BLOCK_SHIFT));
int blockOffset = (int)(pos & BLOCK_MASK);
int toCopy = Math.min(BLOCK_SIZE - blockOffset, count);
System.arraycopy(buffer, offset, block, blockOffset, toCopy);
pos += toCopy;
count -= toCopy;
offset += toCopy;
}
|