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");