Search in sources :

Example 46 with RubyString

use of org.jruby.RubyString in project jruby-openssl by jruby.

the class StringHelper method newStringFrozen.

static RubyString newStringFrozen(final Ruby runtime, final ByteList bytes) {
    final RubyString str = RubyString.newStringShared(runtime, bytes);
    str.setFrozen(true);
    return str;
}
Also used : RubyString(org.jruby.RubyString)

Example 47 with RubyString

use of org.jruby.RubyString in project jruby-openssl by jruby.

the class X509StoreContext method chain.

@JRubyMethod
public IRubyObject chain(final ThreadContext context) {
    final Ruby runtime = context.runtime;
    final List<X509AuxCertificate> chain = storeContext.getChain();
    if (chain == null)
        return runtime.getNil();
    final RubyArray result = runtime.newArray(chain.size());
    final RubyClass _Certificate = _Certificate(runtime);
    try {
        for (X509AuxCertificate x509 : chain) {
            RubyString encoded = StringHelper.newString(runtime, x509.getEncoded());
            result.append(_Certificate.callMethod(context, "new", encoded));
        }
    } catch (CertificateEncodingException e) {
        throw newStoreError(runtime, e.getMessage());
    }
    return result;
}
Also used : RubyArray(org.jruby.RubyArray) RubyString(org.jruby.RubyString) RubyClass(org.jruby.RubyClass) CertificateEncodingException(java.security.cert.CertificateEncodingException) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 48 with RubyString

use of org.jruby.RubyString in project nokogiri by sparklemotion.

the class XsltStylesheet method getTemplatesFromStreamSource.

private Templates getTemplatesFromStreamSource() throws TransformerConfigurationException {
    if (stylesheet instanceof RubyString) {
        StringReader reader = new StringReader(stylesheet.asJavaString());
        StreamSource xsltStreamSource = new StreamSource(reader);
        return factory.newTemplates(xsltStreamSource);
    }
    return null;
}
Also used : RubyString(org.jruby.RubyString) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader)

Example 49 with RubyString

use of org.jruby.RubyString 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

RubyString (org.jruby.RubyString)49 JRubyMethod (org.jruby.anno.JRubyMethod)32 Ruby (org.jruby.Ruby)28 IRubyObject (org.jruby.runtime.builtin.IRubyObject)18 IOException (java.io.IOException)15 ByteList (org.jruby.util.ByteList)12 StringReader (java.io.StringReader)8 ByteArrayInputStream (java.io.ByteArrayInputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 RaiseException (org.jruby.exceptions.RaiseException)5 BigInteger (java.math.BigInteger)4 PublicKey (java.security.PublicKey)4 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 RubyArray (org.jruby.RubyArray)4 Charset (java.nio.charset.Charset)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 RubyInteger (org.jruby.RubyInteger)3 ThreadContext (org.jruby.runtime.ThreadContext)3 InputSource (org.xml.sax.InputSource)3