e.printStackTrace();
}
_data.writeFileDescriptor(fd);
b.transact(XXX, _data, _reply, 0);
_reply.readException();
_reply.readInt();
} catch (RemoteException e) {
e.printStackTrace();
} finally {
_reply.recycle();
_data.recycle();
}
//… …
}
源码路径:./frameworks/base/core/java/android/os/MemoryFile.java
主要功能
-
readBytes()
-
writeBytes()
代码实现
/**
-
Reads bytes from the memory file.
-
Will throw an IOException if the file has been purged.
-
@param buffer byte array to read bytes into.
-
@param srcOffset offset into the memory file to read from.
-
@param destOffset offset into the byte array buffer to read into.
-
@param count number of bytes to read.
-
@return number of bytes read.
-
@throws IOException if the memory file has been purged or deactivated.
*/
public int readBytes(byte[] buffer, int srcOffset, int destOffset, int count)
throws IOException {
beginAccess();
try {
mMapping.position(srcOffset);
mMapping.get(buffer, destOffset, count);
} finally {
endAccess();
}
return c