本文整理匯總了Java中com.google.common.primitives.UnsignedBytes.toInt方法的典型用法代碼示例。如果您正苦於以下問題:Java UnsignedBytes.toInt方法的具體用法?Java UnsignedBytes.toInt怎麽用?Java UnsignedBytes.toInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.primitives.UnsignedBytes
的用法示例。
在下文中一共展示了UnsignedBytes.toInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dumpEntry
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
private String dumpEntry(int offset) {
if (DEBUG_SEARCH) {
StringBuilder sb = new StringBuilder(200);
for (int i = offset; i < mData.length; i++) {
if (mData[i] == 0) {
break;
}
char c = (char) UnsignedBytes.toInt(mData[i]);
sb.append(c);
}
return sb.toString();
} else {
return "<disabled>";
}
}
示例2: dumpEntry
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
private String dumpEntry(int offset) {
if (DEBUG_SEARCH) {
StringBuilder sb = new StringBuilder(200);
for (int i = offset; i < mData.length; i++) {
if (mData[i] == 0) {
break;
}
char c = (char) UnsignedBytes.toInt(mData[i]);
sb.append(c);
}
return sb.toString();
} else {
return "<disabled>"; //$NON-NLS-1$
}
}
示例3: consumePacket
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
@Override
public FMLPacket consumePacket(byte[] data)
{
ByteArrayDataInput bdi = ByteStreams.newDataInput(data);
int chunkIdx = UnsignedBytes.toInt(bdi.readByte());
int chunkTotal = UnsignedBytes.toInt(bdi.readByte());
int chunkLength = bdi.readInt();
if (partials == null)
{
partials = new byte[chunkTotal][];
}
partials[chunkIdx] = new byte[chunkLength];
bdi.readFully(partials[chunkIdx]);
for (int i = 0; i < partials.length; i++)
{
if (partials[i] == null)
{
return null;
}
}
return this;
}
示例4: _add_bit
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
private static void _add_bit(@Nonnull byte[] data, @Nonnegative int bitIndex) {
// LOG.info(" +: Add " + bitIndex + " to " + UnsignedBytes.join(" ", data));
// LOG.info(bitIndex + " -> " + (bitIndex / 8) + "[" + (bitIndex % 8) + "] & " + byteValue);
int byteValue = 1 << (7 - (bitIndex % 8));
// This is actually an arbitrary precision arithmetic routine computing
// data + (1 e bitIndex)
for (int byteIndex = bitIndex / 8; byteIndex >= 0; byteIndex--) {
if (byteValue == 0)
break;
byteValue += UnsignedBytes.toInt(data[byteIndex]);
data[byteIndex] = (byte) (byteValue & 0xFF);
byteValue >>= Byte.SIZE;
}
// LOG.info(" +: Result is " + UnsignedBytes.join(" ", data));
}
示例5: add
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
/** Big-endian. */
@Nonnull
public static byte[] add(@Nonnull byte[] in, @Nonnull byte[] value) {
Preconditions.checkArgument(in.length == value.length,
"Illegal addend of length %s for array of length %s", value.length, in.length);
// return new BigInteger(in).add(new BigInteger(Longs.toByteArray(value))).toByteArray();
int carry = 0;
for (int i = in.length - 1; i >= 0; i--) {
int sum = UnsignedBytes.toInt(in[i]) + UnsignedBytes.toInt(value[i]) + carry;
in[i] = (byte) (sum & 0xFF);
carry = sum >> Byte.SIZE;
}
// Preconditions.checkArgument(carry == 0, "Carry overflow after addition.");
return in;
}
示例6: subtract
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
/** Big-endian. */
@Nonnull
public static byte[] subtract(@Nonnull byte[] in, @Nonnull byte[] value) {
Preconditions.checkArgument(in.length == value.length,
"Illegal subtrahend of length %s for array of length %s", value.length, in.length);
int carry = 0;
for (int i = in.length - 1; i >= 0; i--) {
int sum = UnsignedBytes.toInt(in[i]) - UnsignedBytes.toInt(value[i]) + carry;
in[i] = (byte) (sum & 0xFF);
carry = sum >> Byte.SIZE;
}
// Preconditions.checkArgument(carry == 0, "Carry overflow after subtraction.");
return in;
}
示例7: prefixListForBytes
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
/**
* Creates a list of Ipv4 Prefixes from given byte array.
*
* @param bytes to be converted to List of Ipv4Prefixes.
* @return A list of Ipv4Prefixes
*/
public static List<Ipv4Prefix> prefixListForBytes(final byte[] bytes) {
if (bytes.length == 0) {
return Collections.emptyList();
}
final List<Ipv4Prefix> list = new ArrayList<>();
int byteOffset = 0;
while (byteOffset < bytes.length) {
final int bitLength = UnsignedBytes.toInt(bytes[byteOffset]);
byteOffset += 1;
// if length == 0, default route will be added
if (bitLength == 0) {
list.add(EMPTY_PREFIX);
continue;
}
list.add(IetfInetUtil.INSTANCE.ipv4PrefixForShort(bytes, byteOffset, bitLength));
byteOffset += bitLength / Byte.SIZE;
if (bitLength % Byte.SIZE != 0) {
byteOffset++;
}
}
return list;
}
示例8: TypeSpecChunk
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
protected TypeSpecChunk(ByteBuffer buffer, @Nullable Chunk parent) {
super(buffer, parent);
id = UnsignedBytes.toInt(buffer.get());
buffer.position(buffer.position() + 3); // Skip 3 bytes for packing
int resourceCount = buffer.getInt();
resources = new int[resourceCount];
for (int i = 0; i < resourceCount; ++i) {
resources[i] = buffer.getInt();
}
}
示例9: TypeChunk
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
protected TypeChunk(ByteBuffer buffer, @Nullable Chunk parent) {
super(buffer, parent);
id = UnsignedBytes.toInt(buffer.get());
buffer.position(buffer.position() + 3); // Skip 3 bytes for packing
entryCount = buffer.getInt();
entriesStart = buffer.getInt();
configuration = ResourceConfiguration.create(buffer);
}
示例10: decodeLengthUTF8
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
private static int decodeLengthUTF8(ByteBuffer buffer, int offset) {
// UTF-8 strings use a clever variant of the 7-bit integer for packing the string length.
// If the first byte is >= 0x80, then a second byte follows. For these values, the length
// is WORD-length in big-endian & 0x7FFF.
int length = UnsignedBytes.toInt(buffer.get(offset));
if ((length & 0x80) != 0) {
length = ((length & 0x7F) << 8) | UnsignedBytes.toInt(buffer.get(offset + 1));
}
return length;
}
示例11: read
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
@Override
public int read() throws IOException {
byte[] b = new byte[1];
return read(b) == -1
? -1
: UnsignedBytes.toInt(b[0]);
}
示例12: TypeChunk
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
protected TypeChunk(ByteBuffer buffer, @Nullable Chunk parent) {
super(buffer, parent);
id = UnsignedBytes.toInt(buffer.get());
buffer.position(buffer.position() + 3); // Skip 3 bytes for packing
entryCount = buffer.getInt();
entriesStart = buffer.getInt();
configuration = ResourceConfiguration.create(buffer);
}
示例13: formatBytes
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
public static String formatBytes(byte[] bytes) {
if (bytes == null) return "null";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
int unsignedByte = UnsignedBytes.toInt(bytes[i]);
sb.append(unsignedByte);
if (i != bytes.length - 1) {
sb.append(",");
}
}
return sb.toString();
}
示例14: unpackLanguageOrRegion
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
private String unpackLanguageOrRegion(byte[] value, int base) {
Preconditions.checkState(value.length == 2, "Language or region value must be 2 bytes.");
if (value[0] == 0 && value[1] == 0) {
return "";
}
if ((UnsignedBytes.toInt(value[0]) & 0x80) != 0) {
byte[] result = new byte[3];
result[0] = (byte) (base + (value[1] & 0x1F));
result[1] = (byte) (base + ((value[1] & 0xE0) >>> 5) + ((value[0] & 0x03) << 3));
result[2] = (byte) (base + ((value[0] & 0x7C) >>> 2));
return new String(result, US_ASCII);
}
return new String(value, US_ASCII);
}
示例15: decodeLengthUTF8
import com.google.common.primitives.UnsignedBytes; //導入方法依賴的package包/類
private static int decodeLengthUTF8(ByteBuffer buffer, int offset) {
// UTF-8 strings use a clever variant of the 7-bit integer for packing the string length.
// If the first byte is >= 0x80, then a second byte follows. For these values, the length
// is WORD-length in big-endian & 0x7FFF.
int length = UnsignedBytes.toInt(buffer.get(offset));
if ((length & 0x80) != 0) {
length = ((length & 0x7F) << 8) | UnsignedBytes.toInt(buffer.get(offset + 1));
}
return length;
}