@JRubyMethod(required = 1, optional = 1) @Override public IRubyObject seek(IRubyObject[] args) { checkOpen(); checkFinalized(); long amount = RubyNumeric.num2long(args[0]); int whence = Stream.SEEK_SET; long newPosition = data.pos; if (args.length > 1 && !args[0].isNil()) whence = RubyNumeric.fix2int(args[1]); if (whence == Stream.SEEK_CUR) { newPosition += amount; } else if (whence == Stream.SEEK_END) { newPosition = data.internal.getByteList().length() + amount; } else if (whence == Stream.SEEK_SET) { newPosition = amount; } else { throw getRuntime().newErrnoEINVALError("invalid whence"); } if (newPosition < 0) throw getRuntime().newErrnoEINVALError("invalid seek value"); data.pos = newPosition; data.eof = false; return RubyFixnum.zero(getRuntime()); }
@JRubyMethod(name = {"length", "size"}) @Override public IRubyObject length() { checkFinalized(); return getRuntime().newFixnum(data.internal.getByteList().length()); }