FileDocCategorySizeDatePackage
SerializedFrame.javaAPI DocAndroid 5.1 API8311Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

SerializedFrame

public class SerializedFrame extends android.filterfw.core.Frame
A frame that serializes any assigned values. Such a frame is used when passing data objects between threads.
hide

Fields Summary
private static final int
INITIAL_CAPACITY
The initial capacity of the serialized data stream.
private DirectByteOutputStream
mByteOutputStream
The internal data streams.
private ObjectOutputStream
mObjectOut
Constructors Summary
SerializedFrame(android.filterfw.core.FrameFormat format, android.filterfw.core.FrameManager frameManager)

        super(format, frameManager);
        setReusable(false);

        // Setup streams
        try {
            mByteOutputStream = new DirectByteOutputStream(INITIAL_CAPACITY);
            mObjectOut = new ObjectOutputStream(mByteOutputStream);
            mByteOutputStream.markHeaderEnd();
        } catch (IOException e) {
            throw new RuntimeException("Could not create serialization streams for "
                + "SerializedFrame!", e);
        }
    
Methods Summary
private final java.lang.ObjectdeserializeObjectValue()

        try {
            InputStream inputStream = mByteOutputStream.getInputStream();
            ObjectInputStream objectStream = new ObjectInputStream(inputStream);
            return objectStream.readObject();
        } catch (IOException e) {
            throw new RuntimeException("Could not deserialize object in " + this + "!", e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Unable to deserialize object of unknown class in "
                + this + "!", e);
        }
    
public android.graphics.BitmapgetBitmap()

        Object result = deserializeObjectValue();
        return (result instanceof Bitmap) ? (Bitmap)result : null;
    
public java.nio.ByteBuffergetData()

        Object result = deserializeObjectValue();
        return (result instanceof ByteBuffer) ? (ByteBuffer)result : null;
    
public float[]getFloats()

        Object result = deserializeObjectValue();
        return (result instanceof float[]) ? (float[])result : null;
    
public int[]getInts()

        Object result = deserializeObjectValue();
        return (result instanceof int[]) ? (int[])result : null;
    
public java.lang.ObjectgetObjectValue()

        return deserializeObjectValue();
    
protected booleanhasNativeAllocation()

        return false;
    
protected voidreleaseNativeAllocation()

    
private final voidserializeObjectValue(java.lang.Object object)

        try {
            mByteOutputStream.reset();
            mObjectOut.writeObject(object);
            mObjectOut.flush();
            mObjectOut.close();
        } catch (IOException e) {
            throw new RuntimeException("Could not serialize object " + object + " in "
                + this + "!", e);
        }
    
public voidsetBitmap(android.graphics.Bitmap bitmap)

        assertFrameMutable();
        setGenericObjectValue(bitmap);
    
public voidsetData(java.nio.ByteBuffer buffer, int offset, int length)

        assertFrameMutable();
        setGenericObjectValue(ByteBuffer.wrap(buffer.array(), offset, length));
    
public voidsetFloats(float[] floats)

        assertFrameMutable();
        setGenericObjectValue(floats);
    
protected voidsetGenericObjectValue(java.lang.Object object)

        serializeObjectValue(object);
    
public voidsetInts(int[] ints)

        assertFrameMutable();
        setGenericObjectValue(ints);
    
public java.lang.StringtoString()

        return "SerializedFrame (" + getFormat() + ")";
    
static android.filterfw.core.SerializedFramewrapObject(java.lang.Object object, android.filterfw.core.FrameManager frameManager)

        FrameFormat format = ObjectFormat.fromObject(object, FrameFormat.TARGET_SIMPLE);
        SerializedFrame result = new SerializedFrame(format, frameManager);
        result.setObjectValue(object);
        return result;