/** * Returns the {@code char} value whose big-endian representation is stored in the first 2 bytes * of {@code bytes}; equivalent to {@code ByteBuffer.wrap(bytes).getChar()}. For example, the * input byte array {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that library exposes much more * flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 elements */ @GwtIncompatible // doesn't work public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is stored in the first 2 bytes * of {@code bytes}; equivalent to {@code ByteBuffer.wrap(bytes).getChar()}. For example, the * input byte array {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that library exposes much more * flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 elements */ @GwtIncompatible // doesn't work public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is stored in the first 2 bytes * of {@code bytes}; equivalent to {@code ByteBuffer.wrap(bytes).getChar()}. For example, the * input byte array {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that library exposes much more * flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 elements */ @GwtIncompatible // doesn't work public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
private static char getChar(byte[] data, int offset) { return Chars.fromBytes(data[offset++], data[offset]); }
public static char fromWireCharLE(@Nonnull ByteBuffer buffer) { byte b0 = buffer.get(); byte b1 = buffer.get(); return Chars.fromBytes(b1, b0); }
public static void toArray(byte[] pool, String[] array, int offset) { int poolSize = size(pool); int pos = POOL_SIZE_BYTES; for (int i = 0; i < poolSize; i++) { int elementLength = Chars.fromBytes(pool[pos], pool[pos+1]); pos+=2; array[i + offset] = new String(pool, pos, elementLength, Charsets.UTF_8); pos+=elementLength; } }
/** * Returns the {@code char} value whose big-endian representation is stored in the first 2 bytes * of {@code bytes}; equivalent to {@code ByteBuffer.wrap(bytes).getChar()}. For example, the * input byte array {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that library exposes much more * flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 elements */ @GwtIncompatible // doesn't work public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is stored in the first 2 bytes * of {@code bytes}; equivalent to {@code ByteBuffer.wrap(bytes).getChar()}. For example, the * input byte array {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that library exposes much more * flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 elements */ @GwtIncompatible // doesn't work public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Search for a UTF-8 encoded string in a pool of length-prefixed UTF-8 strings. */ @VisibleForTesting static int find(byte[] pool, byte[] newValue) { int pos = POOL_SIZE_BYTES; int index = 0; while(pos < pool.length) { int stringLength = Chars.fromBytes(pool[pos], pool[pos+1]); pos += ELEMENT_LENGTH_BYTES; if (stringLength == newValue.length && equal(pool, newValue, pos, stringLength)) { return index; } pos += stringLength; index ++; } return -1; }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }
/** * Returns the {@code char} value whose big-endian representation is * stored in the first 2 bytes of {@code bytes}; equivalent to {@code * ByteBuffer.wrap(bytes).getChar()}. For example, the input byte array * {@code {0x54, 0x32}} would yield the {@code char} value {@code '\\u5432'}. * * <p>Arguably, it's preferable to use {@link java.nio.ByteBuffer}; that * library exposes much more flexibility at little cost in readability. * * @throws IllegalArgumentException if {@code bytes} has fewer than 2 * elements */ @GwtIncompatible("doesn't work") public static char fromByteArray(byte[] bytes) { checkArgument(bytes.length >= BYTES, "array too small: %s < %s", bytes.length, BYTES); return fromBytes(bytes[0], bytes[1]); }