Sha256: 3bc0d9a9cf9ab6a3da286296b3028f41a6107130426b41a553346397eed496fa

Contents?: true

Size: 1.8 KB

Versions: 135

Compression:

Stored size: 1.8 KB

Contents

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

package com.xruby.runtime.builtin;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.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 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

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-2.4.0 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.4.0.beta.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.4.0.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.2.beta.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.2.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.1.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.0 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.0.beta.3 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.0.beta.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.3.0.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.6 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.6.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.5 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.5.beta.3 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.5.beta.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.5.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.4.beta.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-2.2.3 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java