Search in sources :

Example 41 with ByteList

use of org.jruby.util.ByteList in project jruby-openssl by jruby.

the class SSLContext method sslVersionString.

private ByteList sslVersionString(long bits) {
    final ByteList str = new ByteList(18);
    boolean first = true;
    if ((bits & CipherStrings.SSL_SSLV3) != 0) {
        if (!first)
            str.append('/');
        first = false;
        str.append(TLSv1);
        str.append('/');
        str.append(SSLv3);
    }
    if ((bits & CipherStrings.SSL_SSLV2) != 0) {
        // first = false;
        if (!first)
            str.append('/');
        str.append(SSLv2);
    }
    return str;
}
Also used : ByteList(org.jruby.util.ByteList)

Example 42 with ByteList

use of org.jruby.util.ByteList in project jruby-openssl by jruby.

the class SSLSocket method syswriteImpl.

private IRubyObject syswriteImpl(final ThreadContext context, final IRubyObject arg, final boolean blocking, final boolean exception) {
    final Ruby runtime = context.runtime;
    try {
        checkClosed();
        final Object ex = waitSelect(SelectionKey.OP_WRITE, blocking, exception);
        // :wait_writable
        if (ex instanceof IRubyObject)
            return (IRubyObject) ex;
        ByteList bytes = arg.asString().getByteList();
        ByteBuffer buff = ByteBuffer.wrap(bytes.getUnsafeBytes(), bytes.getBegin(), bytes.getRealSize());
        final int written;
        if (engine == null) {
            written = writeToChannel(buff, blocking);
        } else {
            written = write(buff, blocking);
        }
        this.io.callMethod(context, "flush");
        return runtime.newFixnum(written);
    } catch (IOException ioe) {
        throw runtime.newIOError(ioe.getMessage());
    }
}
Also used : ByteList(org.jruby.util.ByteList) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) IOException(java.io.IOException) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) ByteBuffer(java.nio.ByteBuffer)

Example 43 with ByteList

use of org.jruby.util.ByteList in project nokogiri by sparklemotion.

the class XmlNode method native_write_to.

/**
 * @param args {IRubyObject io,
 *              IRubyObject encoding,
 *              IRubyObject indentString,
 *              IRubyObject options}
 */
@JRubyMethod(required = 4, visibility = Visibility.PRIVATE)
public IRubyObject native_write_to(ThreadContext context, IRubyObject[] args) {
    IRubyObject io = args[0];
    IRubyObject encoding = args[1];
    IRubyObject indentString = args[2];
    IRubyObject options = args[3];
    String encString = rubyStringToString(encoding);
    SaveContextVisitor visitor = new SaveContextVisitor(RubyFixnum.fix2int(options), rubyStringToString(indentString), encString, isHtmlDoc(context), isFragment(), 0);
    accept(context, visitor);
    final IRubyObject rubyString;
    if (NokogiriHelpers.isUTF8(encString)) {
        rubyString = convertString(context.runtime, visitor.getInternalBuffer());
    } else {
        ByteBuffer bytes = convertEncoding(Charset.forName(encString), visitor.getInternalBuffer());
        ByteList str = new ByteList(bytes.array(), bytes.arrayOffset(), bytes.remaining());
        rubyString = RubyString.newString(context.runtime, str);
    }
    Helpers.invoke(context, io, "write", rubyString);
    return io;
}
Also used : ByteList(org.jruby.util.ByteList) SaveContextVisitor(nokogiri.internals.SaveContextVisitor) RubyString(org.jruby.RubyString) IRubyObject(org.jruby.runtime.builtin.IRubyObject) ByteBuffer(java.nio.ByteBuffer) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

ByteList (org.jruby.util.ByteList)43 Ruby (org.jruby.Ruby)21 JRubyMethod (org.jruby.anno.JRubyMethod)19 RubyString (org.jruby.RubyString)18 IRubyObject (org.jruby.runtime.builtin.IRubyObject)10 GeneralSecurityException (java.security.GeneralSecurityException)8 IOException (java.io.IOException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 ByteBuffer (java.nio.ByteBuffer)5 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 BigInteger (java.math.BigInteger)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)3 ASN1TaggedObject (org.bouncycastle.asn1.ASN1TaggedObject)3 InputSource (org.xml.sax.InputSource)3 StringReader (java.io.StringReader)2