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-7.6.0 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-7.5.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-7.4.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-7.1.17 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-6.2.0 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-6.0.11 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.18 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.17 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.15 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.0.22 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.0.7 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.0.3 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-5.5.0 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
tauplatform-1.0.3 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
tauplatform-1.0.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
tauplatform-1.0.1 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.5.1.12 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.3.5 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java
rhodes-3.4.2 platform/shared/xruby/src/com/xruby/runtime/builtin/RubyIOPipeSinkExecutor.java