Sha256: 336e3c6ec812974a6404cb04e10363f2d5d1fca14d00ce57c810522dbd9b148f

Contents?: true

Size: 1.9 KB

Versions: 115

Compression:

Stored size: 1.9 KB

Contents

/**
 * Copyright 2007 Michael Chen
 * Distributed under the BSD License
 */

package com.xruby.runtime.builtin;

import java.io.IOException;
import java.io.InputStream;

import j2me.nio.ByteBuffer;
import j2me.nio.channels.Pipe.SinkChannel;

import com.xruby.runtime.lang.RubyException;
import com.xruby.runtime.lang.RubyRuntime;
import com.xruby.runtime.lang.RubyValue;

public class RubyIOPipeSinkExecutor implements RubyIOExecutor {

    private final SinkChannel sink;

    public RubyIOPipeSinkExecutor(SinkChannel sink) {
        this.sink = sink;
    }

    public void close() {
        try {
            this.sink.close();
        } catch (IOException e) {
            throw new RubyException(RubyRuntime.IOErrorClass, e.toString());
        }
    }

    public InputStream getInputStream()
    {
    	return null;
    }
    
    public boolean eof() {
        throw notAllowed();
    }

    private RubyException notAllowed() {
        return new RubyException(RubyRuntime.IOErrorClass, "not opened for reading");
    }

    public void flush() {
        // FIXME: may be not used for the java NIO pipe implementation..
    }

    public String gets(RubyValue seperator) {
        throw notAllowed();
    }

    public void print(String s) {
        ByteBuffer bytebuffer = ByteBuffer.wrap(s.getBytes());
        try {
            this.sink.write(bytebuffer);
        } catch (IOException e) {
            throw new RubyException(RubyRuntime.IOErrorClass, e.toString());
        }
    }

    public String read() {
        throw notAllowed();
    }

    public String read(long length) {
        throw notAllowed();
    }

    public String read(int length, int offset) {
        throw notAllowed();
    }

    public int write(String s) {
        print(s);
        return s.length();
    }

    public void truncate(int length) {
        throw notAllowed();
    }

    public void seek(long length) {
        throw notAllowed();
    }
}

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
rhodes-3.5.1.12 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.5 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.4.2 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.4 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.3 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.3.beta.4 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.3.beta.3 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.3.beta.2 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.3.beta.1 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.7 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.6 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.5 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.4 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.3 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.2 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.2.beta.1 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.1 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.0 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.0.beta.3 platform/bb/RubyVM/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java