Example usage for android.os ParcelFormatException initCause

List of usage examples for android.os ParcelFormatException initCause

Introduction

In this page you can find the example usage for android.os ParcelFormatException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:edu.umich.flowfence.common.ParceledPayload.java

public static ParceledPayload fromParcel(Parcel p) {
    byte[] data = p.createByteArray();
    if (data == null) {
        // Null data = data's stored in an ashmem region.
        try (ParcelFileDescriptor pfd = p.readFileDescriptor()) {
            FileDescriptor fd = pfd.getFileDescriptor();
            int size = MemoryFile.getSize(fd);
            if (size == -1) {
                throw new ParcelFormatException("ParceledPayload blob is not ashmem");
            }//from w w w  .  j a  v  a  2 s.c  o m
            data = new byte[size];
            FileInputStream fis = new FileInputStream(fd);
            FileChannel chan = fis.getChannel();
            MappedByteBuffer mapping = chan.map(FileChannel.MapMode.READ_ONLY, 0, size);
            mapping.get(data);
        } catch (IOException e) {
            Log.e(TAG, "Couldn't unparcel - not an ashmem region?", e);
            ParcelFormatException pfe = new ParcelFormatException("Exception reading blob for ParceledPayload");
            pfe.initCause(e);
            throw pfe;
        }
    }
    return new ParceledPayload(data);
}