| Method from com.lowagie.text.pdf.MappedRandomAccessFile Detail: |
public static boolean clean(ByteBuffer buffer) {
if (buffer == null || !buffer.isDirect())
return false;
Boolean b = (Boolean) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Boolean success = Boolean.FALSE;
try {
Method getCleanerMethod = buffer.getClass().getMethod("cleaner", (Class[])null);
getCleanerMethod.setAccessible(true);
Object cleaner = getCleanerMethod.invoke(buffer, (Object[])null);
Method clean = cleaner.getClass().getMethod("clean", (Class[])null);
clean.invoke(cleaner, (Object[])null);
success = Boolean.TRUE;
} catch (Exception e) {
// This really is a show stopper on windows
//e.printStackTrace();
}
return success;
}
});
return b.booleanValue();
}
invokes the clean method on the ByteBuffer's cleaner |
public void close() throws IOException {
clean(mappedByteBuffer);
mappedByteBuffer = null;
if (channel != null)
channel.close();
channel = null;
}
|
protected void finalize() throws Throwable {
close();
super.finalize();
}
|
public FileChannel getChannel() {
return channel;
}
|
public long getFilePointer() {
return mappedByteBuffer.position();
}
|
public long length() {
return mappedByteBuffer.limit();
}
|
public int read() {
try {
byte b = mappedByteBuffer.get();
int n = b & 0xff;
return n;
} catch (BufferUnderflowException e) {
return -1; // EOF
}
}
|
public int read(byte[] bytes,
int off,
int len) {
int pos = mappedByteBuffer.position();
int limit = mappedByteBuffer.limit();
if (pos == limit)
return -1; // EOF
int newlimit = pos + len - off;
if (newlimit > limit) {
len = limit - pos; // don't read beyond EOF
}
mappedByteBuffer.get(bytes, off, len);
return len;
}
|
public void seek(long pos) {
mappedByteBuffer.position((int) pos);
}
|