public void setDictionary(byte[] buf, int off, int nbytes) { if (impl == null) { throw new IllegalStateException(); } // avoid int overflow, check null buf if (off <= buf.length && nbytes >= 0 && off >= 0 && buf.length - off >= nbytes) { impl.setDictionary(Arrays.copyOfRange(buf, off, buf.length), nbytes); } else { throw new ArrayIndexOutOfBoundsException(); } }
@JRubyMethod(name = "set_dictionary", required = 1) public IRubyObject set_dictionary(ThreadContext context, IRubyObject arg) { try { byte[] tmp = arg.convertToString().getBytes(); int err = flater.setDictionary(tmp, tmp.length); if (err == com.jcraft.jzlib.JZlib.Z_STREAM_ERROR) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: "); } run(); return arg; } catch (IllegalArgumentException iae) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: " + iae.getMessage()); } }
@JRubyMethod(name = "set_dictionary", required = 1) public IRubyObject set_dictionary(ThreadContext context, IRubyObject arg) { try { byte[] tmp = arg.convertToString().getBytes(); int err = flater.setDictionary(tmp, tmp.length); if (err == com.jcraft.jzlib.JZlib.Z_STREAM_ERROR) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: "); } run(); return arg; } catch (IllegalArgumentException iae) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: " + iae.getMessage()); } }
@JRubyMethod(name = "set_dictionary", required = 1) public IRubyObject set_dictionary(ThreadContext context, IRubyObject arg) { try { byte[] tmp = arg.convertToString().getBytes(); int err = flater.setDictionary(tmp, tmp.length); if (err == com.jcraft.jzlib.JZlib.Z_STREAM_ERROR) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: "); } run(); return arg; } catch (IllegalArgumentException iae) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: " + iae.getMessage()); } }
@JRubyMethod(name = "set_dictionary", required = 1) public IRubyObject set_dictionary(ThreadContext context, IRubyObject arg) { try { byte[] tmp = arg.convertToString().getBytes(); int err = flater.setDictionary(tmp, tmp.length); if (err == com.jcraft.jzlib.JZlib.Z_STREAM_ERROR) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: "); } run(); return arg; } catch (IllegalArgumentException iae) { throw RubyZlib.newStreamError(context.getRuntime(), "stream error: " + iae.getMessage()); } }