FileDocCategorySizeDatePackage
InputStreamSource.javaAPI DocAndroid 5.1 API2949Thu Mar 12 22:22:30 GMT 2015android.filterpacks.base

InputStreamSource

public class InputStreamSource extends android.filterfw.core.Filter
hide

Fields Summary
private String
mTarget
private InputStream
mInputStream
private android.filterfw.core.MutableFrameFormat
mOutputFormat
Constructors Summary
public InputStreamSource(String name)


       
        super(name);
    
Methods Summary
public voidprocess(android.filterfw.core.FilterContext context)

        int fileSize = 0;
        ByteBuffer byteBuffer = null;

        // Read the file
        try {
            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = mInputStream.read(buffer)) > 0) {
                byteStream.write(buffer, 0, bytesRead);
                fileSize += bytesRead;
            }
            byteBuffer = ByteBuffer.wrap(byteStream.toByteArray());
        } catch (IOException exception) {
            throw new RuntimeException(
                "InputStreamSource: Could not read stream: " + exception.getMessage() + "!");
        }

        // Put it into a frame
        mOutputFormat.setDimensions(fileSize);
        Frame output = context.getFrameManager().newFrame(mOutputFormat);
        output.setData(byteBuffer);

        // Push output
        pushOutput("data", output);

        // Release pushed frame
        output.release();

        // Close output port as we are done here
        closeOutputPort("data");
    
public voidsetupPorts()

        int target = FrameFormat.readTargetString(mTarget);
        if (mOutputFormat == null) {
            mOutputFormat = PrimitiveFormat.createByteFormat(target);
        }
        addOutputPort("data", mOutputFormat);