Build 1.0_r1(from source)

android.os
Class MemoryFile

java.lang.Object
  extended by android.os.MemoryFile

public class MemoryFile
extends Object

MemoryFile is a wrapper for the Linux ashmem driver. MemoryFiles are backed by shared memory, which can be optionally set to be purgeable. Purgeable files may have their contents reclaimed by the kernel in low memory conditions (only if allowPurging is set to true). After a file is purged, attempts to read or write the file will cause an IOException to be thrown.


Constructor Summary
MemoryFile(String name, int length)
          MemoryFile constructor.
 
Method Summary
 boolean allowPurging(boolean allowPurging)
          Enables or disables purging of the memory file.
 void close()
          Closes and releases all resources for the memory file.
protected  void finalize()
          Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
 InputStream getInputStream()
          Creates a new InputStream for reading from the memory file.
 OutputStream getOutputStream()
          Creates a new OutputStream for writing to the memory file.
 boolean isPurgingAllowed()
          Is memory file purging enabled?
 int length()
          Returns the length of the memory file.
 int readBytes(byte[] buffer, int srcOffset, int destOffset, int count)
          Reads bytes from the memory file.
 void writeBytes(byte[] buffer, int srcOffset, int destOffset, int count)
          Write bytes to the memory file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryFile

public MemoryFile(String name,
                  int length)
MemoryFile constructor.

Parameters:
name - optional name for the file (can be null).
length - of the memory file in bytes.
Method Detail

close

public void close()
Closes and releases all resources for the memory file.


finalize

protected void finalize()
Description copied from class: Object
Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Overrides:
finalize in class Object

length

public int length()
Returns the length of the memory file.

Returns:
file length.

isPurgingAllowed

public boolean isPurgingAllowed()
Is memory file purging enabled?

Returns:
true if the file may be purged.

allowPurging

public boolean allowPurging(boolean allowPurging)
                     throws IOException
Enables or disables purging of the memory file.

Parameters:
allowPurging - true if the operating system can purge the contents of the file in low memory situations
Returns:
previous value of allowPurging
Throws:
IOException

getInputStream

public InputStream getInputStream()
Creates a new InputStream for reading from the memory file.

Returns:
InputStream

getOutputStream

public OutputStream getOutputStream()
Creates a new OutputStream for writing to the memory file.

Returns:
OutputStream

readBytes

public int readBytes(byte[] buffer,
                     int srcOffset,
                     int destOffset,
                     int count)
              throws IOException
Reads bytes from the memory file. Will throw an IOException if the file has been purged.

Parameters:
buffer - byte array to read bytes into.
srcOffset - offset into the memory file to read from.
destOffset - offset into the byte array buffer to read into.
count - number of bytes to read.
Returns:
number of bytes read.
Throws:
IOException

writeBytes

public void writeBytes(byte[] buffer,
                       int srcOffset,
                       int destOffset,
                       int count)
                throws IOException
Write bytes to the memory file. Will throw an IOException if the file has been purged.

Parameters:
buffer - byte array to write bytes from.
srcOffset - offset into the byte array buffer to write from.
destOffset - offset into the memory file to write to.
count - number of bytes to write.
Throws:
IOException

Build 1.0_r1(from source)

Please submit a feedback, bug or feature