HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/default/doc/nio4r-2.5.8/ri/ext/nio4r/org/nio4r/page-ByteBuffer_java.ri
U:RDoc::TopLevel[	iI"(ext/nio4r/org/nio4r/ByteBuffer.java:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;[I"package org.nio4r;;To:RDoc::Markup::BlankLineo;	;[I"!import java.io.IOException; ;TI""import java.io.Serializable; ;TI"'import java.nio.channels.Channel; ;TI"1import java.nio.channels.SelectableChannel; ;TI"3import java.nio.channels.ReadableByteChannel; ;TI"3import java.nio.channels.WritableByteChannel; ;TI".import java.nio.BufferOverflowException; ;TI"/import java.nio.BufferUnderflowException; ;TI"*import java.nio.InvalidMarkException;;T@o;	;[I"import org.jruby.Ruby; ;TI"!import org.jruby.RubyClass; ;TI"import org.jruby.RubyIO; ;TI"#import org.jruby.RubyNumeric; ;TI""import org.jruby.RubyObject; ;TI""import org.jruby.RubyString; ;TI"(import org.jruby.anno.JRubyMethod; ;TI"1import org.jruby.exceptions.RaiseException; ;TI"-import org.jruby.runtime.ThreadContext; ;TI"3import org.jruby.runtime.builtin.IRubyObject; ;TI"$import org.jruby.runtime.Block;;T@o;	;[I"/* ;TI"created by Upekshej;To:RDoc::Markup::Verbatim;[I"*/
;T:@format0o;	;[I"1public class ByteBuffer extends RubyObject {;To;;[
I"Iprivate static final long serialVersionUID = -6903439483039149324L;
;TI"-private java.nio.ByteBuffer byteBuffer;
;TI"
;TI"\public static RaiseException newOverflowError(ThreadContext context, String message) {
;TI"n    RubyClass klass = context.runtime.getModule("NIO").getClass("ByteBuffer").getClass("OverflowError");
;TI"C    return context.runtime.newRaiseException(klass, message);
;TI"}
;TI"
;TI"]public static RaiseException newUnderflowError(ThreadContext context, String message) {
;TI"o    RubyClass klass = context.runtime.getModule("NIO").getClass("ByteBuffer").getClass("UnderflowError");
;TI"C    return context.runtime.newRaiseException(klass, message);
;TI"}
;TI"
;TI"]public static RaiseException newMarkUnsetError(ThreadContext context, String message) {
;TI"o    RubyClass klass = context.runtime.getModule("NIO").getClass("ByteBuffer").getClass("MarkUnsetError");
;TI"C    return context.runtime.newRaiseException(klass, message);
;TI"}
;TI"
;TI"?public ByteBuffer(final Ruby ruby, RubyClass rubyClass) {
;TI"!    super(ruby, rubyClass);
;TI"}
;TI"
;TI"@JRubyMethod
;TI"Rpublic IRubyObject initialize(ThreadContext context, IRubyObject capacity) {
;TI"X    this.byteBuffer = java.nio.ByteBuffer.allocate(RubyNumeric.num2int(capacity));
;TI"    return this;
;TI"}
;TI"
;TI"@JRubyMethod
;TI"7public IRubyObject clear(ThreadContext context) {
;TI""    this.byteBuffer.clear();
;TI"    return this;
;TI"}
;TI"
;TI"%@JRubyMethod(name = "position")
;TI"=public IRubyObject getPosition(ThreadContext context) {
;TI"L    return context.getRuntime().newFixnum(this.byteBuffer.position());
;TI"}
;TI"
;TI"&@JRubyMethod(name = "position=")
;TI"Vpublic IRubyObject setPosition(ThreadContext context, IRubyObject newPosition) {
;TI"5    int pos = RubyNumeric.num2int(newPosition);
;TI"
;TI"    if(pos < 0) {
;TI"P        throw context.runtime.newArgumentError("negative position given");
;TI"    }
;TI"
;TI"-    if(pos > this.byteBuffer.limit()) {
;TI"Y        throw context.runtime.newArgumentError("specified position exceeds limit");
;TI"    }
;TI"
;TI"    try {
;TI",        this.byteBuffer.position(pos);
;TI"!        return newPosition;
;TI"/    } catch(IllegalArgumentException e) {
;TI"N        throw context.runtime.newArgumentError(e.getLocalizedMessage());
;TI"    }
;TI"}
;TI"
;TI""@JRubyMethod(name = "limit")
;TI":public IRubyObject getLimit(ThreadContext context) {
;TI"I    return context.getRuntime().newFixnum(this.byteBuffer.limit());
;TI"}
;TI"
;TI"#@JRubyMethod(name = "limit=")
;TI"Ppublic IRubyObject setLimit(ThreadContext context, IRubyObject newLimit) {
;TI"2    int lim = RubyNumeric.num2int(newLimit);
;TI"
;TI"    if(lim < 0) {
;TI"M        throw context.runtime.newArgumentError("negative limit given");
;TI"    }
;TI"
;TI"0    if(lim > this.byteBuffer.capacity()) {
;TI"Y        throw context.runtime.newArgumentError("specified limit exceeds capacity");
;TI"    }
;TI"
;TI"    try {
;TI")        this.byteBuffer.limit(lim);
;TI"        return newLimit;
;TI"/    } catch(IllegalArgumentException e) {
;TI"N        throw context.runtime.newArgumentError(e.getLocalizedMessage());
;TI"    }
;TI"}
;TI"
;TI"/@JRubyMethod(name = {"capacity", "size"})
;TI":public IRubyObject capacity(ThreadContext context) {
;TI"L    return context.getRuntime().newFixnum(this.byteBuffer.capacity());
;TI"}
;TI"
;TI"@JRubyMethod
;TI";public IRubyObject remaining(ThreadContext context) {
;TI"M    return context.getRuntime().newFixnum(this.byteBuffer.remaining());
;TI"}
;TI"
;TI""@JRubyMethod(name = "full?")
;TI"8public IRubyObject isFull(ThreadContext context) {
;TI"/    if (this.byteBuffer.hasRemaining()) {
;TI"5        return context.getRuntime().getFalse();
;TI"    } else {
;TI"4        return context.getRuntime().getTrue();
;TI"    }
;TI"}
;TI"
;TI"@JRubyMethod
;TI"5public IRubyObject get(ThreadContext context) {
;TI"`    return this.get(context, context.getRuntime().newFixnum(this.byteBuffer.remaining()));
;TI"}
;TI"
;TI"@JRubyMethod
;TI"Ipublic IRubyObject get(ThreadContext context, IRubyObject length) {
;TI"0    int len = RubyNumeric.num2int(length);
;TI"'    byte[] bytes = new byte[len];
;TI"
;TI"    try {
;TI")        this.byteBuffer.get(bytes);
;TI"/    } catch(BufferUnderflowException e) {
;TI"W        throw ByteBuffer.newUnderflowError(context, "not enough data in buffer");
;TI"    }
;TI"
;TI"C    return RubyString.newString(context.getRuntime(), bytes);
;TI"}
;TI"
;TI"@JRubyMethod(name = "[]")
;TI"Jpublic IRubyObject fetch(ThreadContext context, IRubyObject index) {
;TI"-    int i = RubyNumeric.num2int(index);
;TI"
;TI"    if(i < 0) {
;TI"M        throw context.runtime.newArgumentError("negative index given");
;TI"    }
;TI"
;TI",    if(i >= this.byteBuffer.limit()) {
;TI"L        throw context.runtime.newArgumentError("index exceeds limit");
;TI"    }
;TI"
;TI"H    return context.getRuntime().newFixnum(this.byteBuffer.get(i));
;TI"}
;TI"
;TI"@JRubyMethod(name = "<<")
;TI"Fpublic IRubyObject put(ThreadContext context, IRubyObject str) {
;TI"    try {
;TI"O        this.byteBuffer.put(str.convertToString().getByteList().bytes());
;TI".    } catch(BufferOverflowException e) {
;TI"K        throw ByteBuffer.newOverflowError(context, "buffer is full");
;TI"    }
;TI"
;TI"    return this;
;TI"}
;TI"
;TI"&@JRubyMethod(name = "read_from")
;TI"Jpublic IRubyObject readFrom(ThreadContext context, IRubyObject io) {
;TI")    Ruby runtime = context.runtime;
;TI"I    Channel channel = RubyIO.convertToIO(context, io).getChannel();
;TI"
;TI"/    if(!this.byteBuffer.hasRemaining()) {
;TI"K        throw ByteBuffer.newOverflowError(context, "buffer is full");
;TI"    }
;TI"
;TI"d    if(!(channel instanceof ReadableByteChannel) || !(channel instanceof SelectableChannel)) {
;TI"b        throw runtime.newArgumentError("unsupported IO object: " + io.getType().toString());
;TI"    }
;TI"
;TI"    try {
;TI"D        ((SelectableChannel)channel).configureBlocking(false);
;TI"#    } catch(IOException ie) {
;TI"A        throw runtime.newIOError(ie.getLocalizedMessage());
;TI"    }
;TI"
;TI"    try {
;TI"S        int bytesRead = ((ReadableByteChannel)channel).read(this.byteBuffer);
;TI"
;TI""        if(bytesRead >= 0) {
;TI"6            return runtime.newFixnum(bytesRead);
;TI"        } else {
;TI".            throw runtime.newEOFError();
;TI"        }
;TI"#    } catch(IOException ie) {
;TI"A        throw runtime.newIOError(ie.getLocalizedMessage());
;TI"    }
;TI"}
;TI"
;TI"%@JRubyMethod(name = "write_to")
;TI"Ipublic IRubyObject writeTo(ThreadContext context, IRubyObject io) {
;TI")    Ruby runtime = context.runtime;
;TI"I    Channel channel = RubyIO.convertToIO(context, io).getChannel();
;TI"
;TI"/    if(!this.byteBuffer.hasRemaining()) {
;TI"W        throw ByteBuffer.newUnderflowError(context, "not enough data in buffer");
;TI"    }
;TI"
;TI"d    if(!(channel instanceof WritableByteChannel) || !(channel instanceof SelectableChannel)) {
;TI"b        throw runtime.newArgumentError("unsupported IO object: " + io.getType().toString());
;TI"    }
;TI"
;TI"    try {
;TI"D        ((SelectableChannel)channel).configureBlocking(false);
;TI"#    } catch(IOException ie) {
;TI"A        throw runtime.newIOError(ie.getLocalizedMessage());
;TI"    }
;TI"
;TI"    try {
;TI"W        int bytesWritten = ((WritableByteChannel)channel).write(this.byteBuffer);
;TI"
;TI"%        if(bytesWritten >= 0) {
;TI"9            return runtime.newFixnum(bytesWritten);
;TI"        } else {
;TI".            throw runtime.newEOFError();
;TI"        }
;TI"#    } catch(IOException ie) {
;TI"A        throw runtime.newIOError(ie.getLocalizedMessage());
;TI"    }
;TI"}
;TI"
;TI"@JRubyMethod
;TI"6public IRubyObject flip(ThreadContext context) {
;TI"!    this.byteBuffer.flip();
;TI"    return this;
;TI"}
;TI"
;TI"@JRubyMethod
;TI"8public IRubyObject rewind(ThreadContext context) {
;TI"#    this.byteBuffer.rewind();
;TI"    return this;
;TI"}
;TI"
;TI"@JRubyMethod
;TI"6public IRubyObject mark(ThreadContext context) {
;TI"!    this.byteBuffer.mark();
;TI"    return this;
;TI"}
;TI"
;TI"@JRubyMethod
;TI"7public IRubyObject reset(ThreadContext context) {
;TI"    try {
;TI"&        this.byteBuffer.reset();
;TI"        return this;
;TI",    } catch(InvalidMarkException ie) {
;TI"S        throw ByteBuffer.newMarkUnsetError(context, "mark has not been set");
;TI"    }
;TI"}
;TI"
;TI"@JRubyMethod
;TI"9public IRubyObject compact(ThreadContext context) {
;TI"$    this.byteBuffer.compact();
;TI"    return this;
;TI"}
;TI"
;TI"@JRubyMethod
;TI"Cpublic IRubyObject each(ThreadContext context, Block block) {
;TI"<    for(int i = 0; i < this.byteBuffer.limit(); i++) {
;TI"Z        block.call(context, context.getRuntime().newFixnum(this.byteBuffer.get(i)));
;TI"    }
;TI"
;TI"    return this;
;TI"}
;TI"
;TI"@JRubyMethod
;TI"9public IRubyObject inspect(ThreadContext context) {
;TI"9    return context.runtime.newString(String.format(
;TI"?        "#<%s:0x%x @position=%d @limit=%d @capacity=%d>",
;TI"(        this.getType().toString(),
;TI",        System.identityHashCode(this),
;TI")        this.byteBuffer.position(),
;TI"&        this.byteBuffer.limit(),
;TI"(        this.byteBuffer.capacity()
;TI"
    ));
;TI"}
;T;0o;	;[I"};T:
@file@:0@omit_headings_from_table_of_contents_below0