1 28 31 package org.jruby.util; 32 33 import java.io.IOException ; 34 import java.io.Writer ; 35 36 import org.jruby.runtime.builtin.IRubyObject; 37 38 42 public class IOWriter extends Writer { 43 private IRubyObject io; 44 45 public IOWriter(IRubyObject io) { 46 super(); 47 if(!io.respondsTo("write")) { 48 throw new IllegalArgumentException ("Object: " + io + " is not a legal argument to this wrapper, cause it doesn't respond to \"write\"."); 49 } 50 this.io = io; 51 } 52 53 public void close() throws IOException { 54 io.callMethod(io.getRuntime().getCurrentContext(), "close"); 55 } 56 57 public void flush() throws IOException { 58 io.callMethod(io.getRuntime().getCurrentContext(), "flush"); 59 } 60 61 public void write(char[] cbuf, int off, int len) { 62 io.callMethod(io.getRuntime().getCurrentContext(),"write", io.getRuntime().newString(String.valueOf(cbuf,off,len))); 63 } 64 } | Popular Tags |