Package org.jruby.util

Examples of org.jruby.util.ByteList


            super(offset);
        }
        public void put(Ruby runtime, IRubyObject ptr, IRubyObject value) {
            MemoryIO io = getMemoryIO(ptr).getMemoryIO(offset);
            if (!io.isNull()) {
                ByteList bl = value.convertToString().getByteList();
                io.put(0, bl.unsafeBytes(), bl.begin(), bl.length());
                io.putByte(bl.length(), (byte) 0);
            }
        }
View Full Code Here


            MemoryIO io = getMemoryIO(ptr).getMemoryIO(offset);
            if (io.isNull()) {
                return runtime.getNil();
            }
            int len = (int) io.indexOf(0, (byte) 0, Integer.MAX_VALUE);
            ByteList bl = new ByteList(len);
            bl.length(len);
            io.get(0, bl.unsafeBytes(), bl.begin(), len);
       
            return runtime.newString(bl);
        }
View Full Code Here

            super(offset);
            this.size = size;
        }
        public void put(Ruby runtime, IRubyObject ptr, IRubyObject value) {
            MemoryIO io = getMemoryIO(ptr);
            ByteList bl = value.convertToString().getByteList();
            // Clamp to no longer than
            int len = Math.min(bl.length(), size - 1);
            io.put(offset, bl.unsafeBytes(), bl.begin(), len);
            io.putByte(offset + len, (byte) 0);
        }
View Full Code Here

            MemoryIO io = getMemoryIO(ptr);
            int len = (int) io.indexOf(offset, (byte) 0, size);
            if (len < 0) {
                len = size;
            }
            ByteList bl = new ByteList(len);
            bl.length(len);
            io.get(0, bl.unsafeBytes(), bl.begin(), len);
       
            return runtime.newString(bl);
        }
View Full Code Here

    }

    public RubyString(Ruby runtime, RubyClass rubyClass, CharSequence value) {
        super(runtime, rubyClass);
        assert value != null;
        this.value = new ByteList(ByteList.plain(value), false);
    }
View Full Code Here

    }

    public RubyString(Ruby runtime, RubyClass rubyClass, byte[] value) {
        super(runtime, rubyClass);
        assert value != null;
        this.value = new ByteList(value);
    }
View Full Code Here

        return empty;
    }

    public static RubyString newUnicodeString(Ruby runtime, String str) {
        try {
            return new RubyString(runtime, runtime.getString(), new ByteList(str.getBytes("UTF8"), false));
        } catch (UnsupportedEncodingException uee) {
            return new RubyString(runtime, runtime.getString(), str);
        }
    }
View Full Code Here

    }

    public static RubyString newString(Ruby runtime, byte[] bytes, int start, int length) {
        byte[] copy = new byte[length];
        System.arraycopy(bytes, start, copy, 0, length);
        return new RubyString(runtime, runtime.getString(), new ByteList(copy, false));
    }
View Full Code Here

        str.shareLevel = SHARE_LEVEL_BYTELIST;
        return str;
    }   

    public static RubyString newStringShared(Ruby runtime, byte[] bytes, int start, int length) {
        RubyString str = new RubyString(runtime, runtime.getString(), new ByteList(bytes, start, length, false));
        str.shareLevel = SHARE_LEVEL_BUFFER;
        return str;
    }
View Full Code Here

    @JRubyMethod(name = "+", required = 1)
    public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
        RubyString str = other.convertToString();
       
        ByteList result = new ByteList(value.realSize + str.value.realSize);
        result.realSize = value.realSize + str.value.realSize;
        System.arraycopy(value.bytes, value.begin, result.bytes, 0, value.realSize);
        System.arraycopy(str.value.bytes, str.value.begin, result.bytes, value.realSize, str.value.realSize);
     
        RubyString resultStr = newString(context.getRuntime(), result);
View Full Code Here

TOP

Related Classes of org.jruby.util.ByteList

Copyright © 2018 www.massapicom. 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.