Methods Summary |
---|
public void | close()
flushBefore(raf.length());
super.close();
raf.close();
file.delete();
|
public void | flushBefore(long pos)
long readFromPos = flushedPos;
super.flushBefore(pos);
long bytesToRead = pos - readFromPos;
raf.seek(readFromPos);
if (bytesToRead < MAX_BUFFER_LEN) {
byte buffer[] = new byte[(int)bytesToRead];
raf.readFully(buffer);
os.write(buffer);
} else {
byte buffer[] = new byte[MAX_BUFFER_LEN];
while (bytesToRead > 0) {
int count = (int)Math.min(MAX_BUFFER_LEN, bytesToRead);
raf.readFully(buffer, 0, count);
os.write(buffer, 0, count);
bytesToRead -= count;
}
}
os.flush();
if (pos != streamPos) {
raf.seek(streamPos); // Reset the position
}
|
public boolean | isCached()
return true;
|
public boolean | isCachedFile()
return true;
|
public boolean | isCachedMemory()
return false;
|
public long | length()
try {
return raf.length();
} catch (IOException e) {
return -1L;
}
|
public int | read()
bitOffset = 0; // Should reset
int res = raf.read();
if (res >= 0) {
streamPos++;
}
return res;
|
public int | read(byte[] b, int off, int len)
bitOffset = 0;
int numRead = raf.read(b, off, len);
if (numRead > 0) {
streamPos += numRead;
}
return numRead;
|
public void | seek(long pos)
if (pos < flushedPos) {
throw new IndexOutOfBoundsException();
}
raf.seek(pos);
streamPos = raf.getFilePointer();
bitOffset = 0;
|
public void | write(int b)
flushBits(); // See the flushBits method description
raf.write(b);
streamPos++;
|
public void | write(byte[] b, int off, int len)
flushBits(); // See the flushBits method description
raf.write(b, off, len);
streamPos += len;
|