Package org.jruby.util

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


        }

        @JRubyMethod(name = "write", required = 1)
        public IRubyObject write(IRubyObject p1) throws IOException {
            ByteList bytes = p1.convertToString().getByteList();
            io.write(bytes.unsafeBytes(), bytes.begin(), bytes.length());
            return getRuntime().newFixnum(bytes.length());
        }
    }
}
View Full Code Here


            if (len == 0) {
                return RubyString.newEmptyString(runtime);
            }
            ByteList bl = new ByteList(len);
            bl.length(len);
            address.read(0, bl.unsafeBytes(), bl.begin(), len);
           
            return RubyString.newString(runtime, bl);
        }
        public static final FunctionInvoker INSTANCE = new StringInvoker();
    }
View Full Code Here

            } else if (parameter instanceof RubyString) {
                // Handle a string being used as a inout buffer
                final ByteList bl = ((RubyString) parameter).getByteList();
                final int len = bl.length();
                final Memory memory = new Memory(len);
                memory.write(0, bl.unsafeBytes(), bl.begin(), len);

                //
                // Arrange for the bytes to be copied back after the function is called
                //
                invocation.addPostInvoke(new Runnable() {
View Full Code Here

                //
                // Arrange for the bytes to be copied back after the function is called
                //
                invocation.addPostInvoke(new Runnable() {
                    public void run() {
                        memory.read(0, bl.unsafeBytes(), bl.begin(), len);
                    }
                });
                return memory;
            }
            return Util.convertParameter(parameter, Pointer.class);
View Full Code Here

        public final Object marshal(Invocation invocation, IRubyObject parameter) {
            // Ruby strings are UTF-8, so should be able to just copy directly
            RubyString s = parameter.asString();
            ByteList bl = s.getByteList();
            final Memory memory = new Memory(bl.length() + 1);
            memory.write(0, bl.unsafeBytes(), bl.begin(), bl.length());
            memory.setByte(bl.length(), (byte) 0);
            return memory;
        }
        public static final Marshaller INSTANCE = new StringMarshaller();
    }
View Full Code Here

        public final Object marshal(Invocation invocation, IRubyObject parameter) {
            // Ruby strings are UTF-8, so should be able to just copy directly
            final ByteList bl = parameter.asString().getByteList();
            final int strlen = bl.length();
            final Memory memory = new Memory(strlen + 1);
            memory.write(0, bl.unsafeBytes(), bl.begin(), strlen);
            memory.setByte(bl.length(), (byte) 0);
           
            //
            // Arrange for the bytes to be copied back after the function is called
            //
View Full Code Here

            //
            // Arrange for the bytes to be copied back after the function is called
            //
            invocation.addPostInvoke(new Runnable() {
                public void run() {
                    memory.read(0, bl.unsafeBytes(), bl.begin(), strlen);
                }
            });
            return memory;
        }
        public static final Marshaller INSTANCE = new RbxStringMarshaller();
View Full Code Here

                return (((JNAMemory) parameter).getNativeMemory());
            } else if (parameter.isNil()) {
                return Pointer.NULL;
            } else if (parameter instanceof RubyString) {
                ByteList bl = ((RubyString) parameter).getByteList();
                return ByteBuffer.wrap(bl.unsafeBytes(), bl.begin(), bl.realSize);
            } else {
                return Util.convertParameter(parameter, Object.class);
            }
        }
        public static final Marshaller INSTANCE = new BufferMarshaller();
View Full Code Here

        if (arg instanceof RubyString) {
            final RubyString s = (RubyString) arg;
            final int size = Util.int32Value(s.length());
            final ByteList bl = s.getByteList();
            final JNAMemoryIO io = JNAMemoryIO.allocateDirect(size);
            io.put(0, bl.unsafeBytes(), bl.begin(), bl.length());
            io.putByte(bl.length(), (byte) 0);
            return new JNABuffer(context.getRuntime(), io, 0, size);
        } else {
            return allocate(context, arg, CLEAR_DEFAULT);
        }
View Full Code Here

            result.op_aset(context, createId, self.getMetaClass().to_s());

            ByteList bl = self.getByteList();
            byte[] uBytes = bl.unsafeBytes();
            RubyArray array = runtime.newArray(bl.length());
            for (int i = bl.begin(), t = bl.begin() + bl.length(); i < t; i++) {
                array.store(i, runtime.newFixnum(uBytes[i] & 0xff));
            }

            result.op_aset(context, runtime.newString("raw"), array);
            return result;
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.