public final class _Private_Utils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
ASCII_CHARSET |
static java.lang.String |
ASCII_CHARSET_NAME |
static byte[] |
EMPTY_BYTE_ARRAY
Just a zero-length byte array, used to avoid allocation.
|
static int[] |
EMPTY_INT_ARRAY
Just a zero-length int array, used to avoid allocation.
|
static java.util.ListIterator<?> |
EMPTY_ITERATOR |
static java.lang.String[] |
EMPTY_STRING_ARRAY
Just a zero-length String array, used to avoid allocation.
|
static int |
MAX_LOOKAHEAD_UTF16
(null.timestamp) requires 11 ASCII chars to distinguish from
(null.timestamps) aka (null '.' 'timestamps')
|
static boolean |
READER_HASNEXT_REMOVED
Marker for code points relevant to removal of IonReader.hasNext().
|
static java.util.TimeZone |
UTC
The UTC
TimeZone . |
static java.nio.charset.Charset |
UTF8_CHARSET |
static java.lang.String |
UTF8_CHARSET_NAME
The string
"UTF-8" . |
Constructor and Description |
---|
_Private_Utils() |
Modifier and Type | Method and Description |
---|---|
static <T> void |
addAll(java.util.Collection<T> dest,
java.util.Iterator<T> src) |
static <T> void |
addAllNonNull(java.util.Collection<T> dest,
java.util.Iterator<T> src) |
static byte[] |
convertUtf16UnitsToUtf8(java.lang.String text)
This differs from
utf8(String) by using our custem encoder. |
static SymbolTable |
copyLocalSymbolTable(SymbolTable symtab)
Creates a mutable copy of this local symbol table.
|
static byte[] |
copyOf(byte[] original,
int newLength)
Replacement for Java6
Arrays.copyOf(byte[], int) . |
static java.lang.String[] |
copyOf(java.lang.String[] original,
int newLength) |
static java.lang.String |
decode(byte[] bytes,
java.nio.charset.Charset charset)
Decodes a byte sequence into a string, given a
Charset . |
static <T> java.util.ListIterator<T> |
emptyIterator() |
static byte[] |
encode(java.lang.String s,
java.nio.charset.Charset charset)
Encodes a String into bytes of a given encoding.
|
static int |
getSidForSymbolTableField(java.lang.String text)
Returns the symbol ID matching a system symbol text of a
local or shared symtab field.
|
static SymbolTable |
initialSymtab(_Private_LocalSymbolTableFactory lstFactory,
SymbolTable defaultSystemSymtab,
SymbolTable... imports)
Returns a minimal symtab that, either system or local depending on the
given values, that supports representation as an IonStruct.
|
static java.util.Iterator<java.lang.Integer> |
intIterator(int... values) |
static java.util.Iterator<java.lang.Integer> |
intIterator(int[] values,
int len) |
static boolean |
isNonSymbolScalar(IonType type)
Determines whether the passed-in data type is a scalar and not a symbol.
|
static boolean |
isTrivialTable(SymbolTable table)
Is the table null, system, or local without imported symbols?
|
static java.util.Iterator<IonValue> |
iterate(ValueFactory valueFactory,
IonReader input)
Create a value iterator from a reader.
|
static byte[] |
loadFileBytes(java.io.File file) |
static java.lang.String |
loadReader(java.io.Reader in) |
static byte[] |
loadStreamBytes(java.io.InputStream in) |
static SymbolToken |
localize(SymbolTable symtab,
SymbolToken sym) |
static void |
localize(SymbolTable symtab,
SymbolToken[] syms) |
static void |
localize(SymbolTable symtab,
SymbolToken[] syms,
int count) |
static _Private_LocalSymbolTableFactory |
newLocalSymbolTableAsStructFactory(ValueFactory imageFactory)
Deprecated.
due to DOM entanglement. Streaming applications should use
.
|
static SymbolTable |
newSharedSymtab(IonReader reader,
boolean alreadyInStruct) |
static SymbolTable |
newSharedSymtab(IonStruct ionRep) |
static SymbolTable |
newSharedSymtab(java.lang.String name,
int version,
SymbolTable priorSymtab,
java.util.Iterator<java.lang.String> symbols)
As per
IonSystem.newSharedSymbolTable(String, int, Iterator, SymbolTable...) ,
any duplicate or null symbol texts are skipped. |
static SymbolTable |
newSubstituteSymtab(SymbolTable original,
int version,
int maxId) |
static com.amazon.ion.impl.SymbolTokenImpl |
newSymbolToken(int sid) |
static com.amazon.ion.impl.SymbolTokenImpl |
newSymbolToken(java.lang.String text,
int sid) |
static SymbolToken |
newSymbolToken(SymbolTable symtab,
int sid) |
static SymbolToken |
newSymbolToken(SymbolTable symtab,
java.lang.String text)
Checks symbol content.
|
static SymbolToken[] |
newSymbolTokens(SymbolTable symtab,
int... syms) |
static SymbolToken[] |
newSymbolTokens(SymbolTable symtab,
java.lang.String... text)
Validates each text element.
|
static int |
readFully(java.io.InputStream in,
byte[] buf)
Calls
InputStream.read(byte[], int, int) until the buffer is
filled or EOF is encountered. |
static int |
readFully(java.io.InputStream in,
byte[] buf,
int offset,
int length)
Calls
InputStream.read(byte[], int, int) until the requested
length is read or EOF is encountered. |
static boolean |
safeEquals(java.lang.Object a,
java.lang.Object b) |
static boolean |
streamIsIonBinary(java.io.PushbackInputStream pushback) |
static java.util.Iterator<java.lang.String> |
stringIterator(java.lang.String... values) |
static java.util.Iterator<java.lang.String> |
stringIterator(java.lang.String[] values,
int len) |
static boolean |
symtabExtends(SymbolTable superset,
SymbolTable subset)
Determines whether the passed-in
superset symtab is an extension
of subset . |
static boolean |
symtabIsLocalAndNonTrivial(SymbolTable symtab) |
static boolean |
symtabIsSharedNotSystem(SymbolTable symtab)
Indicates whether a table is shared but not a system table.
|
static IonStruct |
symtabTree(SymbolTable symtab,
ValueFactory valueFactory) |
static SymbolTable |
systemSymtab(int version) |
static int[] |
toSids(SymbolToken[] symbols,
int count) |
static java.lang.String[] |
toStrings(SymbolToken[] symbols,
int count)
Extracts the non-null text from a list of symbol tokens.
|
static java.lang.String |
utf8(byte[] bytes)
Decodes a UTF-8 byte sequence to a String.
|
static byte[] |
utf8(java.lang.String s)
Encodes a String into UTF-8 bytes.
|
static java.lang.String |
utf8FileToString(java.io.File file) |
static boolean |
valueIsLocalSymbolTable(_Private_IonValue v)
Checks the passed in value and returns whether or not
the value could be a local symbol table.
|
static void |
writeAsBase64(java.io.InputStream byteStream,
java.lang.Appendable out) |
public static final boolean READER_HASNEXT_REMOVED
public static final byte[] EMPTY_BYTE_ARRAY
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static final int[] EMPTY_INT_ARRAY
public static final int MAX_LOOKAHEAD_UTF16
IonCharacterReader.DEFAULT_BUFFER_SIZE
,
IonCharacterReader.BUFFER_PADDING
,
Constant Field Valuespublic static final java.lang.String ASCII_CHARSET_NAME
public static final java.nio.charset.Charset ASCII_CHARSET
public static final java.lang.String UTF8_CHARSET_NAME
"UTF-8"
.public static final java.nio.charset.Charset UTF8_CHARSET
public static final java.util.TimeZone UTC
TimeZone
.
TODO determine if this is well-defined.public static final java.util.ListIterator<?> EMPTY_ITERATOR
public static final <T> java.util.ListIterator<T> emptyIterator()
public static boolean safeEquals(java.lang.Object a, java.lang.Object b)
public static byte[] copyOf(byte[] original, int newLength)
Arrays.copyOf(byte[], int)
.public static java.lang.String[] copyOf(java.lang.String[] original, int newLength)
public static <T> void addAll(java.util.Collection<T> dest, java.util.Iterator<T> src)
public static <T> void addAllNonNull(java.util.Collection<T> dest, java.util.Iterator<T> src)
public static com.amazon.ion.impl.SymbolTokenImpl newSymbolToken(java.lang.String text, int sid)
public static com.amazon.ion.impl.SymbolTokenImpl newSymbolToken(int sid)
public static SymbolToken newSymbolToken(SymbolTable symtab, java.lang.String text)
public static SymbolToken newSymbolToken(SymbolTable symtab, int sid)
public static SymbolToken[] newSymbolTokens(SymbolTable symtab, java.lang.String... text)
text
- may be null or empty.public static SymbolToken[] newSymbolTokens(SymbolTable symtab, int... syms)
syms
- may be null or empty.public static SymbolToken localize(SymbolTable symtab, SymbolToken sym)
public static void localize(SymbolTable symtab, SymbolToken[] syms, int count)
syms
- may be mutated, replacing entries with localized updates!public static void localize(SymbolTable symtab, SymbolToken[] syms)
syms
- may be mutated, replacing entries with localized updates!public static java.lang.String[] toStrings(SymbolToken[] symbols, int count)
UnknownSymbolException
- if any token is missing text.public static int[] toSids(SymbolToken[] symbols, int count)
public static byte[] encode(java.lang.String s, java.nio.charset.Charset charset)
This method is preferred to Charset.encode(String)
and
String.getBytes(String)
(etc.)
since those methods will replace or ignore bad input, and here we throw
an exception.
s
- the string to encode.IonException
- if there's a CharacterCodingException
.public static java.lang.String decode(byte[] bytes, java.nio.charset.Charset charset)
Charset
.
This method is preferred to Charset.decode(ByteBuffer)
and
String(byte[], Charset)
(etc.)
since those methods will replace or ignore bad input, and here we throw
an exception.
bytes
- the data to decode.IonException
- if there's a CharacterCodingException
.public static byte[] utf8(java.lang.String s)
This method is preferred to Charset.encode(String)
and
String.getBytes(String)
(etc.)
since those methods will replace or ignore bad input, and here we throw
an exception.
s
- the string to encode.IonException
- if there's a CharacterCodingException
.public static java.lang.String utf8(byte[] bytes)
This method is preferred to Charset.decode(ByteBuffer)
and
String(byte[], Charset)
(etc.)
since those methods will replace or ignore bad input, and here we throw
an exception.
bytes
- the data to decode.IonException
- if there's a CharacterCodingException
.public static byte[] convertUtf16UnitsToUtf8(java.lang.String text)
utf8(String)
by using our custem encoder.
Not sure which is better.
TODO benchmark the two approachespublic static int readFully(java.io.InputStream in, byte[] buf) throws java.io.IOException
InputStream.read(byte[], int, int)
until the buffer is
filled or EOF is encountered.
This method will block until the request is satisfied.in
- The stream to read from.buf
- The buffer to read to.buf.length
if EOF is encountered before reading that far.java.io.IOException
readFully(InputStream, byte[], int, int)
public static int readFully(java.io.InputStream in, byte[] buf, int offset, int length) throws java.io.IOException
InputStream.read(byte[], int, int)
until the requested
length is read or EOF is encountered.
This method will block until the request is satisfied.in
- The stream to read from.buf
- The buffer to read to.offset
- The offset of the buffer to read from.length
- The length of the data to read.length
if EOF is encountered before reading that far.java.io.IOException
readFully(InputStream, byte[])
public static byte[] loadFileBytes(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String utf8FileToString(java.io.File file) throws IonException, java.io.IOException
IonException
java.io.IOException
public static byte[] loadStreamBytes(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static java.lang.String loadReader(java.io.Reader in) throws java.io.IOException
java.io.IOException
public static boolean streamIsIonBinary(java.io.PushbackInputStream pushback) throws IonException, java.io.IOException
IonException
java.io.IOException
public static java.util.Iterator<IonValue> iterate(ValueFactory valueFactory, IonReader input)
public static boolean valueIsLocalSymbolTable(_Private_IonValue v)
public static final boolean symtabIsSharedNotSystem(SymbolTable symtab)
public static boolean symtabIsLocalAndNonTrivial(SymbolTable symtab)
public static boolean isTrivialTable(SymbolTable table)
public static SymbolTable systemSymtab(int version)
public static SymbolTable newSharedSymtab(IonStruct ionRep)
public static SymbolTable newSharedSymtab(IonReader reader, boolean alreadyInStruct)
public static SymbolTable newSharedSymtab(java.lang.String name, int version, SymbolTable priorSymtab, java.util.Iterator<java.lang.String> symbols)
IonSystem.newSharedSymbolTable(String, int, Iterator, SymbolTable...)
,
any duplicate or null symbol texts are skipped.
Therefore, THIS METHOD IS NOT SUITABLE WHEN READING SERIALIZED
SHARED SYMBOL TABLES since that scenario must preserve all sids.priorSymtab
- may be null.public static SymbolTable copyLocalSymbolTable(SymbolTable symtab) throws SubstituteSymbolTableException
ValueFactory
.
Note that the resulting symbol table holds a distinct, deep copy of the given table, adding symbols on either instances will not modify the other.
symtab
- SymbolTable
instance; not nulljava.lang.IllegalArgumentException
- if the given table is not a local symbol tableSubstituteSymbolTableException
- if any imported table by the given local symbol table is a
substituted table (whereby no exact match was found in its
catalog)@Deprecated public static _Private_LocalSymbolTableFactory newLocalSymbolTableAsStructFactory(ValueFactory imageFactory)
Factory(ValueFactory)
imageFactory
- the ValueFactory from which to construct the IonStruct representation of the LSTLocalSymbolTableAsStruct.Factory
public static SymbolTable initialSymtab(_Private_LocalSymbolTableFactory lstFactory, SymbolTable defaultSystemSymtab, SymbolTable... imports)
lstFactory
- the factory to use to build the local symbol table, never nulldefaultSystemSymtab
- the default system symtab, which will be used if the first
import in imports
isn't a system symtab, never nullimports
- the set of shared symbol tables to import; may be null or empty.
The first (and only the first) may be a system table, in which case the
defaultSystemSymtab
is ignored.public static IonStruct symtabTree(SymbolTable symtab, ValueFactory valueFactory)
public static boolean symtabExtends(SymbolTable superset, SymbolTable subset)
superset
symtab is an extension
of subset
.
If both are LSTs, their imported tables and locally declared symbols are exhaustively checked, which can be expensive. Callers of this method should cache the results of these comparisons.
superset
- either a system or local symbol tablesubset
- either a system or local symbol tablesuperset
extends subset
, false if notpublic static boolean isNonSymbolScalar(IonType type)
public static final int getSidForSymbolTableField(java.lang.String text)
public static final java.util.Iterator<java.lang.String> stringIterator(java.lang.String... values)
public static final java.util.Iterator<java.lang.String> stringIterator(java.lang.String[] values, int len)
public static final java.util.Iterator<java.lang.Integer> intIterator(int... values)
public static final java.util.Iterator<java.lang.Integer> intIterator(int[] values, int len)
public static void writeAsBase64(java.io.InputStream byteStream, java.lang.Appendable out) throws java.io.IOException
java.io.IOException
public static SymbolTable newSubstituteSymtab(SymbolTable original, int version, int maxId)