Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.ext.jruby;
 
 import org.jruby.Ruby;
public class JRubyObjectInputStream extends RubyObject {
    private static final ObjectAllocator JROIS_ALLOCATOR = new ObjectAllocator() {
	    public IRubyObject allocate(Ruby runtimeRubyClass klass) {
		return new JRubyObjectInputStream(runtimeklass);
        }
    };
    public static RubyClass createJRubyObjectInputStream(Ruby runtime) {
	RubyClass result = runtime.defineClass("JRubyObjectInputStream",runtime.getObject(),);
	return result;
    }
    @JRubyMethod(name = "new", rest = true, meta = true)
    public static IRubyObject newInstance(IRubyObject recvIRubyObject[] argsBlock block) {
        IRubyObject obj = ((RubyClass)recv).allocate();
        obj.callMethod(recv.getRuntime().getCurrentContext(), "initialize"argsblock);
        return obj;
    }
    public JRubyObjectInputStream(Ruby runtimeRubyClass rubyClass) {
	super(runtime,rubyClass);
    }
    
    @JRubyMethod(name="initialize",required=1, visibility = .)
    public IRubyObject initialize(IRubyObject wrappedStream) {
        InputStream stream = (InputStream)wrappedStream.toJava(InputStream.class);
        try {
             = new JRubyObjectInputStreamImpl(getRuntime(),stream);
        } catch (IOException ioe) {
            throw getRuntime().newIOErrorFromException(ioe);
        }
        return this;
    }
    @JRubyMethod(name="read_object", alias="readObject")
	public IRubyObject readObject() {
        try {
        	return Java.getInstance(getRuntime(),.readObject());
        } catch (IOException ioe) {
            throw getRuntime().newIOErrorFromException(ioe);
        } catch (ClassNotFoundException cnfe) {
            throw getRuntime().newNameError(cnfe.getLocalizedMessage(), cnfe.getMessage(), cnfe);
        }
    }
    @JRubyMethod(name="close")
    public IRubyObject close() {
        try {
            .close();
        } catch (IOException ioe) {
            throw getRuntime().newIOErrorFromException(ioe);
        }
        return this;
    }
    static class JRubyObjectInputStreamImpl extends ObjectInputStream {
        protected Ruby runtime;
        public JRubyObjectInputStreamImpl(Ruby rt,InputStream inthrows IOException {
            super(in);
             = rt;
        }
        @Override
        protected Class resolveClass(ObjectStreamClass descthrows IOExceptionClassNotFoundException {
            return Class.forName(desc.getName(),true,.getJRubyClassLoader());
        }
    }
New to GrepCode? Check out our FAQ X