Methods Summary |
---|
public synchronized boolean | allowPurging(boolean allowPurging)Enables or disables purging of the memory file.
boolean oldValue = mAllowPurging;
if (oldValue != allowPurging) {
native_pin(mFD, !allowPurging);
mAllowPurging = allowPurging;
}
return oldValue;
|
public void | close()Closes the memory file. If there are no other open references to the memory
file, it will be deleted.
deactivate();
if (!isClosed()) {
native_close(mFD);
}
|
void | deactivate()Unmaps the memory file from the process's memory space, but does not close it.
After this method has been called, read and write operations through this object
will fail, but {@link #getFileDescriptor()} will still return a valid file descriptor.
if (!isDeactivated()) {
try {
native_munmap(mAddress, mLength);
mAddress = 0;
} catch (IOException ex) {
Log.e(TAG, ex.toString());
}
}
|
protected void | finalize()
if (!isClosed()) {
Log.e(TAG, "MemoryFile.finalize() called while ashmem still open");
close();
}
|
public java.io.FileDescriptor | getFileDescriptor()Gets a FileDescriptor for the memory file.
The returned file descriptor is not duplicated.
return mFD;
|
public java.io.InputStream | getInputStream()Creates a new InputStream for reading from the memory file.
return new MemoryInputStream();
|
public java.io.OutputStream | getOutputStream()Creates a new OutputStream for writing to the memory file.
return new MemoryOutputStream();
|
public static int | getSize(java.io.FileDescriptor fd)Returns the size of the memory file that the file descriptor refers to,
or -1 if the file descriptor does not refer to a memory file.
return native_get_size(fd);
|
private boolean | isClosed()Checks whether the memory file has been closed.
return !mFD.valid();
|
private boolean | isDeactivated()Checks whether the memory file has been deactivated.
return mAddress == 0;
|
public boolean | isPurgingAllowed()Is memory file purging enabled?
return mAllowPurging;
|
public int | length()Returns the length of the memory file.
return mLength;
|
private static native void | native_close(java.io.FileDescriptor fd)
|
private static native int | native_get_size(java.io.FileDescriptor fd)
|
private static native long | native_mmap(java.io.FileDescriptor fd, int length, int mode)
|
private static native void | native_munmap(long addr, int length)
|
private static native java.io.FileDescriptor | native_open(java.lang.String name, int length)
|
private static native void | native_pin(java.io.FileDescriptor fd, boolean pin)
|
private static native int | native_read(java.io.FileDescriptor fd, long address, byte[] buffer, int srcOffset, int destOffset, int count, boolean isUnpinned)
|
private static native void | native_write(java.io.FileDescriptor fd, long address, byte[] buffer, int srcOffset, int destOffset, int count, boolean isUnpinned)
|
public int | readBytes(byte[] buffer, int srcOffset, int destOffset, int count)Reads bytes from the memory file.
Will throw an IOException if the file has been purged.
if (isDeactivated()) {
throw new IOException("Can't read from deactivated memory file.");
}
if (destOffset < 0 || destOffset > buffer.length || count < 0
|| count > buffer.length - destOffset
|| srcOffset < 0 || srcOffset > mLength
|| count > mLength - srcOffset) {
throw new IndexOutOfBoundsException();
}
return native_read(mFD, mAddress, buffer, srcOffset, destOffset, count, mAllowPurging);
|
public void | writeBytes(byte[] buffer, int srcOffset, int destOffset, int count)Write bytes to the memory file.
Will throw an IOException if the file has been purged.
if (isDeactivated()) {
throw new IOException("Can't write to deactivated memory file.");
}
if (srcOffset < 0 || srcOffset > buffer.length || count < 0
|| count > buffer.length - srcOffset
|| destOffset < 0 || destOffset > mLength
|| count > mLength - destOffset) {
throw new IndexOutOfBoundsException();
}
native_write(mFD, mAddress, buffer, srcOffset, destOffset, count, mAllowPurging);
|