Top Inners Fields Constructors Methods
org.jruby

public Class RubyEncoding

extends RubyObject
implements Constantizable
Class Inheritance
All Implemented Interfaces
org.jruby.compiler.Constantizable
Annotations
@JRubyClass
name:Encoding
Imports
java.lang.ref.SoftReference, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetDecoder, .CharsetEncoder, .CodingErrorAction, .StandardCharsets, org.jcodings.Encoding, .EncodingDB.Entry, org.jcodings.specific.ASCIIEncoding, .USASCIIEncoding, .UTF16BEEncoding, .UTF8Encoding, org.jcodings.util.CaseInsensitiveBytesHash, .Hash.HashEntryIterator, org.jruby.anno.JRubyClass, .JRubyMethod, org.jruby.compiler.Constantizable, org.jruby.runtime.ClassIndex, .ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.encoding.EncodingCapable, .EncodingService, org.jruby.runtime.opto.OptoFactory, org.jruby.util.ByteList, .CodeRangeable, .StringSupport, org.jruby.util.io.EncodingUtils

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
RubyEncoding.RawCoder

A cached decoder object to decode bytes as raw binary (ISO-8859-1 or ASCII-8BIT) content.

private static class
RubyEncoding.UTF8Coder

A cached decoder for UTF-8 bytes.

Field Summary

Modifier and TypeField and Description
public static final ByteList
private static final int
CHAR_THRESHOLD

The maximum number of characters we can encode/decode in our cached buffers

private final transient Object
private Encoding
public static final ByteList
public static final ByteList
public static final ByteList
private final boolean
public static final Charset
public static final ByteList
private final ByteList
private static final ThreadLocal<SoftReference<RubyEncoding.RawCoder>>
RAW_CODER

Thread-local RawCoder wrapped in a SoftReference to avoid possible ClassLoader leak.

public static final Charset
public static final Charset
private static final ThreadLocal<SoftReference<RubyEncoding.UTF8Coder>>
UTF8_CODER

Thread-local UTF8Coder wrapped in a SoftReference to avoid possible ClassLoader leak.

Inherited from org.jruby.RubyObject:
IVAR_INSPECTING_OBJECT_ALLOCATOROBJECT_ALLOCATORREIFYING_OBJECT_ALLOCATOR

Constructor Summary

AccessConstructor and Description
private
RubyEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy)

private
RubyEncoding(Ruby runtime, byte[] name, Encoding encoding, boolean isDummy)

private
RubyEncoding(Ruby runtime, ByteList name, Encoding encoding, boolean isDummy)

Method Summary

Modifier and TypeMethod and Description
public IRubyObject
public static IRubyObject
private static void
addSpecialAlias(ThreadContext context, RubyHash result, ByteList alias, Encoding encoding)

public static IRubyObject
public static Encoding
public static Encoding
areCompatible(Encoding enc1, int cr1, Encoding enc2, int cr2)

public IRubyObject
public static Encoding

Returns:

a negotiated encoding, if compatible; null otherwise
checkEncoding
(ThreadContext
the current thread context
context
,
Encoding
the first encoding
encoding
,
CodeRangeable
the CodeRangeable from which to get bytes and the second encoding
other
)

Check whether the given encoding and the encoding from the given CodeRangeable are compatible.

public static IRubyObject
public Object
public static RubyClass
public static String
decode(byte[] bytes, int start, int length, Charset charset)

public static String
decode(byte[] bytes, Charset charset)

public static String
decodeISO(byte[] bytes, int start, int length)

public static String
decodeISO(ByteList byteList)
Deprecated use decodeRaw(ByteList)

public static String

Returns:

a decoded String based on raw bytes
decodeRaw
(byte[]
the byte array
bytes
,
int
start of content
start
,
int
length of content
length
)

Decode the range of bytes specified as "raw" binary content, as in ISO-8859-1 or ASCII-8BIT encodings.

public static String

Returns:

a decoded string based on raw bytes
decodeRaw
(ByteList byteList)

Decode the specified bytelist as "raw" binary content.

private static char[]
decodeRawLoop(byte[] s, int start, int length)

public static String

Returns:

a decoded String based on UTF-8 bytes
decodeUTF8
(byte[]
the byte array
bytes
,
int
start of content
start
,
int
length of content
length
)

Decode the range of bytes specified as UTF-8 content.

public static String
decodeUTF8(byte[] bytes)

pack-priv static ByteList
doEncode(String cs, Charset charset, Encoding enc)

pack-priv static ByteList
pack-priv static ByteList
pack-priv static ByteList
pack-priv static ByteList
pack-priv static ByteList
public IRubyObject
public static byte[]
public static byte[]
encode(String str, Charset charset)

public static byte[]
public static byte[]
encodeISO(char[] str)

private static byte[]
encodeISOLoop(char[] s)

private static byte[]
public static byte[]
public static byte[]
public static byte[]
public static byte[]
private static Encoding
public static IRubyObject
private static ByteList
getByteList(final ByteBuffer buffer, final Encoding enc, final boolean shared)

private static byte[]
getBytes(final ByteBuffer buffer)

public static IRubyObject
public static IRubyObject
public static IRubyObject
public final Encoding
private static RubyEncoding.RawCoder
private static RubyEncoding.UTF8Coder
public IRubyObject
inspect(ThreadContext context)

Overrides org.jruby.RubyBasicObject.inspect.

Overrides default org.jruby.runtime.builtin.IRubyObject.inspect.

Returns a string containing a human-readable representation of obj.

private ByteList
public static IRubyObject
public static IRubyObject
public static IRubyObject
public IRubyObject
public static RubyEncoding
newEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy)

public IRubyObject
replicate(ThreadContext context, IRubyObject arg)
Deprecated since 10.0.

public static IRubyObject
public static IRubyObject
public IRubyObject
private static CharBuffer
Inherited from org.jruby.RubyObject:
attachToObjectSpacecallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitconvertToTypedigdig1dig2eqlInternalequalInternalequalsfinishObjectClassgetNativeClassIndexhashCodeinspectop_eqqputsspecificEvaltoRubyStringtoString

Field Detail

BINARY_ASCII_NAMEback to summary
public static final ByteList BINARY_ASCII_NAME
CHAR_THRESHOLDback to summary
private static final int CHAR_THRESHOLD

The maximum number of characters we can encode/decode in our cached buffers

constantback to summary
private final transient Object constant
encodingback to summary
private Encoding encoding
EXTERNALback to summary
public static final ByteList EXTERNAL
FILESYSTEMback to summary
public static final ByteList FILESYSTEM
INTERNALback to summary
public static final ByteList INTERNAL
isDummyback to summary
private final boolean isDummy
ISOback to summary
public static final Charset ISO
LOCALEback to summary
public static final ByteList LOCALE
nameback to summary
private final ByteList name
RAW_CODERback to summary
private static final ThreadLocal<SoftReference<RubyEncoding.RawCoder>> RAW_CODER

Thread-local RawCoder wrapped in a SoftReference to avoid possible ClassLoader leak. See JRUBY-6522

UTF16back to summary
public static final Charset UTF16
UTF8back to summary
public static final Charset UTF8
UTF8_CODERback to summary
private static final ThreadLocal<SoftReference<RubyEncoding.UTF8Coder>> UTF8_CODER

Thread-local UTF8Coder wrapped in a SoftReference to avoid possible ClassLoader leak. See JRUBY-6522

Constructor Detail

RubyEncodingback to summary
private RubyEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy)
RubyEncodingback to summary
private RubyEncoding(Ruby runtime, byte[] name, Encoding encoding, boolean isDummy)
RubyEncodingback to summary
private RubyEncoding(Ruby runtime, ByteList name, Encoding encoding, boolean isDummy)

Method Detail

_dumpback to summary
public IRubyObject _dump(ThreadContext context, IRubyObject arg)
Annotations
@JRubyMethod
name:_dump
_loadback to summary
public static IRubyObject _load(ThreadContext context, IRubyObject recv, IRubyObject str)
Annotations
@JRubyMethod
name:_load
meta:true
addSpecialAliasback to summary
private static void addSpecialAlias(ThreadContext context, RubyHash result, ByteList alias, Encoding encoding)
aliasesback to summary
public static IRubyObject aliases(ThreadContext context, IRubyObject recv)
Annotations
@SuppressWarnings:unchecked
@JRubyMethod
name:aliases
meta:true
areCompatibleback to summary
public static Encoding areCompatible(IRubyObject obj1, IRubyObject obj2)
areCompatibleback to summary
public static Encoding areCompatible(Encoding enc1, int cr1, Encoding enc2, int cr2)
asciiCompatible_pback to summary
public IRubyObject asciiCompatible_p(ThreadContext context)
Annotations
@JRubyMethod
name:ascii_compatible?
checkEncodingback to summary
public static Encoding checkEncoding(ThreadContext context, Encoding encoding, CodeRangeable other)

Check whether the given encoding and the encoding from the given CodeRangeable are compatible. This version differs from RubyString#checkEncoding(CodeRangeable) in that the contents of the first encoding's string are not taken into consideration (e.g. blank first string does not skip compatibility check with second string's encoding). See rb_enc_check in CRuby and use from stringio that passes encoding instead of string for the first argument. See https://github.com/ruby/stringio/pull/116 for some discussion MRI: rb_enc_check with encoding for first parameter

Parameters
context:ThreadContext

the current thread context

encoding:Encoding

the first encoding

other:CodeRangeable

the CodeRangeable from which to get bytes and the second encoding

Returns:Encoding

a negotiated encoding, if compatible; null otherwise

compatible_pback to summary
public static IRubyObject compatible_p(ThreadContext context, IRubyObject self, IRubyObject first, IRubyObject second)
Annotations
@JRubyMethod
name:compatible?
meta:true
constantback to summary
public Object constant()

Implements org.jruby.compiler.Constantizable.constant.

Annotations
@Override
See Also
org.jruby.compiler.Constantizable
createEncodingClassback to summary
public static RubyClass createEncodingClass(ThreadContext context, RubyClass Object)
decodeback to summary
public static String decode(byte[] bytes, int start, int length, Charset charset)
decodeback to summary
public static String decode(byte[] bytes, Charset charset)
decodeISOback to summary
public static String decodeISO(byte[] bytes, int start, int length)
Annotations
@Deprecated
decodeISOback to summary
public static String decodeISO(ByteList byteList)

Deprecated

use decodeRaw(ByteList)

Annotations
@Deprecated
decodeRawback to summary
public static String decodeRaw(byte[] bytes, int start, int length)

Decode the range of bytes specified as "raw" binary content, as in ISO-8859-1 or ASCII-8BIT encodings. This will attempt to use a zero-allocation decoder if the content length is shorter than CHAR_THRESHOLD bytes, and otherwise will used cached decoders to avoid reallocating Charset-related objects.

Parameters
bytes:byte[]

the byte array

start:int

start of content

length:int

length of content

Returns:String

a decoded String based on raw bytes

decodeRawback to summary
public static String decodeRaw(ByteList byteList)

Decode the specified bytelist as "raw" binary content. This is the same as calling decodeRaw(byte[], int, int) with the contents of byteList.

Returns:String

a decoded string based on raw bytes

decodeRawLoopback to summary
private static char[] decodeRawLoop(byte[] s, int start, int length)
decodeUTF8back to summary
public static String decodeUTF8(byte[] bytes, int start, int length)

Decode the range of bytes specified as UTF-8 content. This will attempt to use a zero-allocation decoder if the content length is shorter than CHAR_THRESHOLD bytes, and otherwise will used cached decoders to avoid reallocating Charset-related objects.

Parameters
bytes:byte[]

the byte array

start:int

start of content

length:int

length of content

Returns:String

a decoded String based on UTF-8 bytes

decodeUTF8back to summary
public static String decodeUTF8(byte[] bytes)
doEncodeback to summary
pack-priv static ByteList doEncode(String cs, Charset charset, Encoding enc)
doEncodeback to summary
pack-priv static ByteList doEncode(CharSequence cs, Charset charset, Encoding enc)
doEncodeUTF16back to summary
pack-priv static ByteList doEncodeUTF16(String str)
doEncodeUTF16back to summary
pack-priv static ByteList doEncodeUTF16(CharSequence str)
doEncodeUTF8back to summary
pack-priv static ByteList doEncodeUTF8(String str)
doEncodeUTF8back to summary
pack-priv static ByteList doEncodeUTF8(CharSequence str)
dummy_pback to summary
public IRubyObject dummy_p(ThreadContext context)
Annotations
@JRubyMethod
name:dummy?
encodeback to summary
public static byte[] encode(CharSequence cs, Charset charset)
encodeback to summary
public static byte[] encode(String str, Charset charset)
encodeISOback to summary
public static byte[] encodeISO(CharSequence str)
encodeISOback to summary
public static byte[] encodeISO(char[] str)
encodeISOLoopback to summary
private static byte[] encodeISOLoop(char[] s)
encodeISOLoopback to summary
private static byte[] encodeISOLoop(CharSequence s)
encodeUTF16back to summary
public static byte[] encodeUTF16(String str)
encodeUTF16back to summary
public static byte[] encodeUTF16(CharSequence str)
encodeUTF8back to summary
public static byte[] encodeUTF8(String str)
encodeUTF8back to summary
public static byte[] encodeUTF8(CharSequence str)
extractEncodingFromObjectback to summary
private static Encoding extractEncodingFromObject(IRubyObject obj)
findback to summary
public static IRubyObject find(ThreadContext context, IRubyObject recv, IRubyObject str)
Annotations
@JRubyMethod
name:find
meta:true
getByteListback to summary
private static ByteList getByteList(final ByteBuffer buffer, final Encoding enc, final boolean shared)
getBytesback to summary
private static byte[] getBytes(final ByteBuffer buffer)
getDefaultExternalback to summary
public static IRubyObject getDefaultExternal(ThreadContext context, IRubyObject recv)
Annotations
@JRubyMethod
name:default_external
meta:true
getDefaultInternalback to summary
public static IRubyObject getDefaultInternal(ThreadContext context, IRubyObject recv)
Annotations
@JRubyMethod
name:default_internal
meta:true
getDefaultInternalback to summary
public static IRubyObject getDefaultInternal(IRubyObject recv)

Deprecated

Annotations
@Deprecated
getEncodingback to summary
public final Encoding getEncoding()
getRawCoderback to summary
private static RubyEncoding.RawCoder getRawCoder()
getUTF8Coderback to summary
private static RubyEncoding.UTF8Coder getUTF8Coder()
inspectback to summary
public IRubyObject inspect(ThreadContext context)

Overrides org.jruby.RubyBasicObject.inspect.

Overrides default org.jruby.runtime.builtin.IRubyObject.inspect.

Doc from org.jruby.RubyBasicObject.inspect.

Returns a string containing a human-readable representation of obj. If not overridden, uses the to_s method to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"

Annotations
@JRubyMethod
name:inspect
inspectNameback to summary
private ByteList inspectName()
listback to summary
public static IRubyObject list(ThreadContext context, IRubyObject recv)
Annotations
@JRubyMethod
name:list
meta:true
locale_charmapback to summary
public static IRubyObject locale_charmap(ThreadContext context, IRubyObject recv)
Annotations
@JRubyMethod
name:locale_charmap
meta:true
name_listback to summary
public static IRubyObject name_list(ThreadContext context, IRubyObject recv)
Annotations
@SuppressWarnings:unchecked
@JRubyMethod
name:name_list
meta:true
namesback to summary
public IRubyObject names(ThreadContext context)
Annotations
@SuppressWarnings:unchecked
@JRubyMethod
name:names
newEncodingback to summary
public static RubyEncoding newEncoding(Ruby runtime, byte[] name, int p, int end, boolean isDummy)
replicateback to summary
public IRubyObject replicate(ThreadContext context, IRubyObject arg)

Deprecated

since 10.0.

Annotations
@Deprecated
since:10.0
setDefaultExternalback to summary
public static IRubyObject setDefaultExternal(ThreadContext context, IRubyObject recv, IRubyObject encoding)
Annotations
@JRubyMethod
name:default_external=
meta:true
setDefaultInternalback to summary
public static IRubyObject setDefaultInternal(ThreadContext context, IRubyObject recv, IRubyObject encoding)
Annotations
@JRubyMethod
name:default_internal=
meta:true
to_sback to summary
public IRubyObject to_s(ThreadContext context)

Overrides org.jruby.RubyBasicObject.to_s.

Annotations
@JRubyMethod
name:to_s, name
toCharBufferback to summary
private static CharBuffer toCharBuffer(CharSequence str)
org.jruby back to summary

private Class RubyEncoding.RawCoder

extends Object
Class Inheritance

A cached decoder object to decode bytes as raw binary (ISO-8859-1 or ASCII-8BIT) content.

Field Summary

Modifier and TypeField and Description
private final char[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public final String
decode(byte[] bytes, int start, int length)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

charBufferback to summary
private final char[] charBuffer

Constructor Detail

RawCoderback to summary
private RawCoder()

Method Detail

decodeback to summary
public final String decode(byte[] bytes, int start, int length)
org.jruby back to summary

private Class RubyEncoding.UTF8Coder

extends Object
Class Inheritance

A cached decoder for UTF-8 bytes.

Field Summary

Modifier and TypeField and Description
private static final int
BUF_SIZE

The resulting encode/decode buffer sized by the max number of characters (using 4 bytes per char possible for utf-8)

private final ByteBuffer
private final CharBuffer
private final CharsetDecoder
private final CharsetEncoder

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final CharBuffer
decode(byte[] bytes, int start, int length)

public final ByteBuffer
public final ByteBuffer
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUF_SIZEback to summary
private static final int BUF_SIZE

The resulting encode/decode buffer sized by the max number of characters (using 4 bytes per char possible for utf-8)

byteBufferback to summary
private final ByteBuffer byteBuffer
charBufferback to summary
private final CharBuffer charBuffer
decoderback to summary
private final CharsetDecoder decoder
encoderback to summary
private final CharsetEncoder encoder

Constructor Detail

UTF8Coderback to summary
pack-priv UTF8Coder()

Method Detail

decodeback to summary
public final CharBuffer decode(byte[] bytes, int start, int length)
encodeback to summary
public final ByteBuffer encode(String str)
encodeback to summary
public final ByteBuffer encode(CharSequence str)