1 28 package org.jruby.util; 29 30 import java.io.OutputStream ; 31 import java.io.IOException ; 32 import org.jruby.RubyString; 33 import org.jruby.runtime.builtin.IRubyObject; 34 35 46 public class IOOutputStream extends OutputStream { 47 private IRubyObject io; 48 49 54 public IOOutputStream(final IRubyObject io) { 55 if(!io.respondsTo("write")) { 56 throw new IllegalArgumentException ("Object: " + io + " is not a legal argument to this wrapper, cause it doesn't respond to \"write\"."); 57 } 58 this.io = io; 59 } 60 61 public void write(final int bite) throws IOException { 62 io.callMethod(io.getRuntime().getCurrentContext(), "write", RubyString.newString(io.getRuntime(), new ByteList(new byte[]{(byte)bite},false))); 63 } 64 65 public void write(final byte[] b) throws IOException { 66 write(b,0,b.length); 67 } 68 69 public void write(final byte[] b,final int off, final int len) throws IOException { 70 io.callMethod(io.getRuntime().getCurrentContext(),"write", RubyString.newString(io.getRuntime(), new ByteList(b, off, len, false))); 71 } 72 } 73 | Popular Tags |