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;
}
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());
}
}
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;
}
Aggregations