Package org.jruby.util

Examples of org.jruby.util.ByteList.unsafeBytes()


                 * #    Comment
                 * =    Assignment preceding command name
                 * %    (used in Parameter Expansion)
                 */
                ByteList progByteList = prog.getByteList();
                pBytes = progByteList.unsafeBytes();
                for (p = 0; p < progByteList.length(); p++){
                    if (progByteList.get(p) == ' ' || progByteList.get(p) == '\t'){
                        if (first.unsafeBytes() != DUMMY_ARRAY && first.length() == 0) first.setRealSize(p - first.begin());
                    }
                    else{
View Full Code Here


public class SnappyModule {
  @JRubyMethod(module = true, name = {"deflate", "compress", "dump"})
  public static IRubyObject deflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
    ByteList input = str.convertToString().getByteList();
    byte[] compressed = new byte[Snappy.maxCompressedLength(input.length())];
    int compressedLength = Snappy.compress(input.unsafeBytes(), input.begin(), input.length(), compressed, 0);
    return RubyString.newStringNoCopy(context.runtime, compressed, 0, compressedLength);
  }

  @JRubyMethod(module = true, name = {"inflate", "uncompress", "load"})
  public static IRubyObject inflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
View Full Code Here

  }

  @JRubyMethod(module = true, name = {"inflate", "uncompress", "load"})
  public static IRubyObject inflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
    ByteList input = str.convertToString().getByteList();
    byte[] uncompressed = new byte[Snappy.uncompressedLength(input.unsafeBytes(), input.begin(), input.length())];
    int uncompressedLength = Snappy.uncompress(input.unsafeBytes(), input.begin(), input.length(), uncompressed, 0);
    return RubyString.newStringNoCopy(context.runtime, uncompressed, 0, uncompressedLength);
  }
}
View Full Code Here

  @JRubyMethod(module = true, name = {"inflate", "uncompress", "load"})
  public static IRubyObject inflate(ThreadContext context, IRubyObject self, IRubyObject str) throws IOException {
    ByteList input = str.convertToString().getByteList();
    byte[] uncompressed = new byte[Snappy.uncompressedLength(input.unsafeBytes(), input.begin(), input.length())];
    int uncompressedLength = Snappy.uncompress(input.unsafeBytes(), input.begin(), input.length(), uncompressed, 0);
    return RubyString.newStringNoCopy(context.runtime, uncompressed, 0, uncompressedLength);
  }
}
View Full Code Here

                statement.setBinaryStream(index, ((RubyIO) value).getInStream());
            }
            else { // should be a RubyString
                final ByteList blob = value.asString().getByteList();
                statement.setBinaryStream(index,
                    new ByteArrayInputStream(blob.unsafeBytes(), blob.getBegin(), blob.getRealSize()),
                    blob.getRealSize() // length
                );
            }
        }
    }
View Full Code Here

    @JRubyMethod(name = "quote_string", required = 1, frame = false)
    public static IRubyObject quote_string(final ThreadContext context,
        final IRubyObject recv, final IRubyObject string) {

        final ByteList stringBytes = ((RubyString) string).getByteList();
        final byte[] bytes = stringBytes.unsafeBytes();
        final int begin = stringBytes.getBegin();
        final int realSize = stringBytes.getRealSize();

        ByteList quotedBytes = null; int appendFrom = begin;
        for ( int i = begin; i < begin + realSize; i++ ) {
View Full Code Here

            final RubyString string,
            final char value, final char quote,
            final int newOffset, final int newSizeDiff) {

        final ByteList stringBytes = string.getByteList();
        final byte[] bytes = stringBytes.unsafeBytes();
        final int begin = stringBytes.getBegin();
        final int realSize = stringBytes.getRealSize();

        ByteList quotedBytes = null; int appendFrom = begin;
        for ( int i = begin; i < begin + realSize; i++ ) {
View Full Code Here

                statement.setBinaryStream(index, ((RubyIO) value).getInStream());
            }
            else { // should be a RubyString
                final ByteList blob = value.asString().getByteList();
                statement.setBinaryStream(index,
                    new ByteArrayInputStream(blob.unsafeBytes(), blob.getBegin(), blob.getRealSize()),
                    blob.getRealSize() // length
                );
                // JDBC 4.0 :
                //statement.setBlob(index,
                //    new ByteArrayInputStream(bytes.unsafeBytes(), bytes.getBegin(), bytes.getRealSize())
View Full Code Here

        }
    }

    public static String rubyStringToString(RubyString str) {
        ByteList byteList = str.getByteList();
        byte[] data = byteList.unsafeBytes();
        int offset = byteList.begin();
        int len = byteList.length();
        ByteBuffer buf = ByteBuffer.wrap(data, offset, len);
        return getCharsetUTF8().decode(buf).toString();
    }
View Full Code Here

    if (returnValue.isNil())
      return -1;

    ByteList bytes = returnValue.asString().getByteList();
    int length = bytes.length();
    System.arraycopy(bytes.unsafeBytes(), bytes.getBegin(), b, off + copyLength, length);
    return length + copyLength;
  }

  @Override
  public int read() {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.