Package org.jruby.util

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


        public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) {
           
            if (isCharArray() && value instanceof RubyString) {
                ByteList bl = value.convertToString().getByteList();
                ptr.getMemoryIO().putZeroTerminatedByteArray(m.offset, bl.getUnsafeBytes(), bl.begin(),
                    Math.min(bl.length(), arrayType.length() - 1));

            } else if (false) {
                RubyArray ary = value.convertToArray();
                int count = ary.size();
View Full Code Here


        }

        ByteList bl = s.getByteList();
        StringSupport.checkStringSafety(s.getRuntime(), s);
        DirectMemoryIO memory = TransientNativeMemoryIO.allocateAligned(s.getRuntime(), bl.length() + 1, 1, false);
        memory.putZeroTerminatedByteArray(0, bl.getUnsafeBytes(), bl.begin(), bl.length());
        s.setByteListShared();
        s.setFFIHandle(new NativeStringHandle(memory, s.getByteList()));

        return memory.getAddress();
    }
View Full Code Here

           
            if (!v.isNil()) {
                tainted = in.isTaint();
                untrusted = in.isUntrusted();
                ByteList bytes = ((RubyString) v).getByteList();
                rawInput = new ByteArrayInputStream(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
            } else if (in.respondsTo("getc") && in.respondsTo("read")) {
                tainted = true;
                untrusted = true;
                rawInput = inputStream(context, in);
            } else {
View Full Code Here

        ByteList srcBL = srcString.getByteList();

        if (srcBL.getRealSize() == 0) return context.runtime.newSymbol("source_buffer_empty");

        ByteBuffer srcBB = ByteBuffer.wrap(srcBL.getUnsafeBytes(), srcBL.begin(), srcBL.getRealSize());
        try {
            CharBuffer srcCB = CharBuffer.allocate((int) (srcDecoder.maxCharsPerByte() * srcBL.getRealSize()) + 1);
            CoderResult decodeResult = srcDecoder.decode(srcBB, srcCB, true);
            srcCB.flip();

View Full Code Here

            }
            return Character.valueOf('\0');
        } else if (javaClass == String.class) {
            RubyString rubyString = (RubyString) rubyObject.callMethod(context, "to_s");
            ByteList bytes = rubyString.getByteList();
            return RubyEncoding.decodeUTF8(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
        } else if (javaClass == ByteList.class) {
            return rubyObject.convertToString().getByteList();
        } else if (javaClass == BigInteger.class) {
           if (rubyObject instanceof RubyBignum) {
             return ((RubyBignum)rubyObject).getValue();
View Full Code Here

        case ClassIndex.FLOAT:
            javaObject = new Double(((RubyFloat) object).getValue());
            break;
        case ClassIndex.STRING:
            ByteList bytes = ((RubyString) object).getByteList();
            javaObject = RubyEncoding.decodeUTF8(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
            break;
        case ClassIndex.TRUE:
            javaObject = Boolean.TRUE;
            break;
        case ClassIndex.FALSE:
View Full Code Here

            ByteList bytes = string.getByteList();

            // 1.9 support for encodings
            // TODO: Fix charset use for JRUBY-4553
            if (string.getRuntime().is1_9()) {
                return new String(bytes.getUnsafeBytes(), bytes.begin(), bytes.length(), string.getEncoding().toString());
            }

            return RubyEncoding.decodeUTF8(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
        } catch (UnsupportedEncodingException uee) {
            return string.toString();
View Full Code Here

            // TODO: Fix charset use for JRUBY-4553
            if (string.getRuntime().is1_9()) {
                return new String(bytes.getUnsafeBytes(), bytes.begin(), bytes.length(), string.getEncoding().toString());
            }

            return RubyEncoding.decodeUTF8(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
        } catch (UnsupportedEncodingException uee) {
            return string.toString();
        }
    }
View Full Code Here

            }
        }
        try {
            // TODO: jzlib-1.1.0.jar throws IndexOutOfBoundException for zero length buffer.
            if (bytes.length() > 0) {
                io.write(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
            }
            return getRuntime().newFixnum(bytes.length());
        } catch (IOException ioe) {
            throw getRuntime().newIOErrorFromException(ioe);
        }
View Full Code Here

                }
            }

            ByteList result = new ByteList((int) left);
            ByteBuffer buf = ByteBuffer.wrap(result.getUnsafeBytes(),
                    result.begin(), (int) left);

            //
            // Copy any buffered data (including ungetc byte)
            //
            copyBufferedBytes(buf);
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.