Package org.jruby.util

Examples of org.jruby.util.ByteList


    private IRubyObject inspectStruct(final ThreadContext context) {   
        RubyArray member = (RubyArray) getInternalVariable(classOf(), "__member__");

        assert !member.isNil() : "uninitialized struct";

        ByteList buffer = new ByteList("#<struct ".getBytes());
        buffer.append(getMetaClass().getRealClass().getRealClass().getName().getBytes());
        buffer.append(' ');

        for (int i = 0,k=member.getLength(); i < k; i++) {
            if (i > 0) buffer.append(',').append(' ');
            // FIXME: MRI has special case for constants here
            buffer.append(RubyString.objAsString(context, member.eltInternal(i)).getByteList());
            buffer.append('=');
            buffer.append(inspect(context, values[i]).getByteList());
        }

        buffer.append('>');
        return getRuntime().newString(buffer); // OBJ_INFECT       
    }
View Full Code Here


                return new Character(s.charAt(0));
            }
            return new Character('\0');
        } else if (javaClass == String.class) {
            RubyString rubyString = (RubyString) rubyObject.callMethod(context, "to_s");
            ByteList bytes = rubyString.getByteList();
            try {
                return new String(bytes.unsafeBytes(), bytes.begin(), bytes.length(), "UTF8");
            } catch (UnsupportedEncodingException uee) {
                return new String(bytes.unsafeBytes(), bytes.begin(), bytes.length());
            }
        } else if (javaClass == ByteList.class) {
            return rubyObject.convertToString().getByteList();
        } else if (javaClass == BigInteger.class) {
           if (rubyObject instanceof RubyBignum) {
View Full Code Here

        throw numeric.getRuntime().newTypeError("could not coerce " + numeric.getMetaClass() + " to " + target);
    }
   
    public static Object coerceStringToType(RubyString string, Class target) {
        try {
            ByteList bytes = string.getByteList();
            return new String(bytes.unsafeBytes(), bytes.begin(), bytes.length(), "UTF8");
        } catch (UnsupportedEncodingException uee) {
            return string.toString();
        }
    }
View Full Code Here

        case ClassIndex.FLOAT:
            javaObject = new Double(((RubyFloat) object).getValue());
            break;
        case ClassIndex.STRING:
            try {
                ByteList bytes = ((RubyString) object).getByteList();
                javaObject = new String(bytes.unsafeBytes(), bytes.begin(), bytes.length(), "UTF8");
            } catch (UnsupportedEncodingException uee) {
                javaObject = object.toString();
            }
            break;
        case ClassIndex.TRUE:
View Full Code Here

                context.getRuntime().newString("AF_INET"),
                context.getRuntime().newFixnum(sender.getPort()),
                context.getRuntime().newString(sender.getHostName()),
                context.getRuntime().newString(sender.getAddress().getHostAddress())
            });
            IRubyObject result = context.getRuntime().newString(new ByteList(buf.array(), 0, buf.position()));
            return context.getRuntime().newArray(new IRubyObject[]{result, addressArray});
        } catch (UnknownHostException e) {
            throw sockerr(context.getRuntime(), "recvfrom: name or service not known");
        } catch (IOException e) {
            throw sockerr(context.getRuntime(), "recvfrom: name or service not known");
View Full Code Here

    public IRubyObject recv(ThreadContext context, IRubyObject[] args) {
        try {
            int length = RubyNumeric.fix2int(args[0]);
            ByteBuffer buf = ByteBuffer.allocate(length);
            ((DatagramChannel) this.getChannel()).receive(buf);
            return context.getRuntime().newString(new ByteList(buf.array(), 0, buf.position()));
        } catch (IOException e) {
            throw sockerr(context.getRuntime(), "recv: name or service not known");
        }
    }
View Full Code Here

   
    private static List<ByteList> dirGlobs(String cwd, IRubyObject[] args, int flags) {
        List<ByteList> dirs = new ArrayList<ByteList>();
       
        for (int i = 0; i < args.length; i++) {
            ByteList globPattern = args[i].convertToString().getByteList();
            dirs.addAll(Dir.push_glob(cwd, globPattern, flags));
        }
       
        return dirs;
    }
View Full Code Here

    @JRubyMethod(name = "[]", required = 1, rest=true, meta = true)
    public static IRubyObject aref(IRubyObject recv, IRubyObject[] args) {
        List<ByteList> dirs;
        if (args.length == 1) {
            ByteList globPattern = args[0].convertToString().getByteList();
            dirs = Dir.push_glob(getCWD(recv.getRuntime()), globPattern, 0);
        } else {
            dirs = dirGlobs(getCWD(recv.getRuntime()), args, 0);
        }
View Full Code Here

        int flags = args.length == 2 ?  RubyNumeric.num2int(args[1]) : 0;

        List<ByteList> dirs;
        IRubyObject tmp = args[0].checkArrayType();
        if (tmp.isNil()) {
            ByteList globPattern = args[0].convertToString().getByteList();
            dirs = Dir.push_glob(recv.getRuntime().getCurrentDirectory(), globPattern, flags);
        } else {
            dirs = dirGlobs(getCWD(runtime), ((RubyArray) tmp).toJavaArray(), flags);
        }
       
View Full Code Here

        return out;
    }

    public static final ByteList crypt(ByteList salt, ByteList original) {
        ByteList buffer = new ByteList(new byte[]{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, false);

        byte charZero = salt.bytes[salt.begin];
        byte charOne = salt.bytes[salt.begin + 1];

        buffer.set(0, charZero);
        buffer.set(1, charOne);

        int Eswap0 = con_salt[(int) (charZero & 127)];
        int Eswap1 = con_salt[(int) (charOne & 127)] << 4;

        byte[] key = new byte[8];

        for (int i = 0; i < key.length; i++) {
            key[i] = (byte) 0;
        }

        for (int i = 0; i < key.length && i < original.length(); i++) {
            int iChar = (int) (original.bytes[original.begin + i] & 255);

            key[i] = (byte) (iChar << 1);
        }

        int[] schedule = des_set_key(key);
        int[] out = body(schedule, Eswap0, Eswap1);

        byte[] b = new byte[9];

        intToFourBytes(out[0], b, 0);
        intToFourBytes(out[1], b, 4);
        b[8] = 0;

        for (int i = 2, y = 0, u = 128; i < 13; i++) {
            for (int j = 0, c = 0; j < 6; j++) {
                c <<= 1;

                if (((int) b[y] & u) != 0) {
                    c |= 1;
                }

                u >>>= 1;

                if (u == 0) {
                    y++;
                    u = 128;
                }
                buffer.set(i, cov_2char[c]);
            }
        }
        return buffer;
    }
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.