Skip to content

Instantly share code, notes, and snippets.

@tschaub
Created June 28, 2010 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tschaub/456300 to your computer and use it in GitHub Desktop.
Save tschaub/456300 to your computer and use it in GitHub Desktop.
var stream = new Stream(new java.io.PipedInputStream());
var _out = new java.io.PipedOutputStream(stream);
var _runnable = new java.lang.Runnable({
run: function() {
javax.imageio.ImageIO.write(_image, options.imageType, _out);
}
});
var _thread = new java.lang.Thread(_runnable);
_thread.start();
stream.forEach = function(callback, thisObj) {
var length = 8192;
var buffer = new ByteArray(length);
while (true) {
var read = stream.readInto(buffer, 0, length);
if (read < 0) {
break;
}
buffer.length = read;
callback.call(thisObj, buffer);
buffer.length = length;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment