当前位置: 首页>>代码示例>>Java>>正文


Java UnsignedBytes.toInt方法代码示例

本文整理汇总了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>";
    }
}
 
开发者ID:evant,项目名称:silent-support,代码行数:17,代码来源:ApiLookup.java

示例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$
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ApiLookup.java

示例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;
}
 
开发者ID:HATB0T,项目名称:RuneCraftery,代码行数:23,代码来源:ModIdMapPacket.java

示例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));
}
 
开发者ID:shevek,项目名称:dhcp4j,代码行数:17,代码来源:NetworkSet.java

示例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;
}
 
开发者ID:shevek,项目名称:dhcp4j,代码行数:17,代码来源:AddressUtils.java

示例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;
}
 
开发者ID:shevek,项目名称:dhcp4j,代码行数:17,代码来源:AddressUtils.java

示例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;
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:31,代码来源:Ipv4Util.java

示例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();
    }
}
 
开发者ID:CalebFenton,项目名称:apkfile,代码行数:12,代码来源:TypeSpecChunk.java

示例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);
}
 
开发者ID:CalebFenton,项目名称:apkfile,代码行数:9,代码来源:TypeChunk.java

示例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;
}
 
开发者ID:CalebFenton,项目名称:apkfile,代码行数:11,代码来源:ResourceString.java

示例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]);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:8,代码来源:ByteSourceTest.java

示例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);
}
 
开发者ID:madisp,项目名称:android-chunk-utils,代码行数:9,代码来源:TypeChunk.java

示例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();
}
 
开发者ID:pingcap,项目名称:tikv-client-lib-java,代码行数:13,代码来源:KeyUtils.java

示例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);
}
 
开发者ID:madisp,项目名称:android-chunk-utils,代码行数:15,代码来源:ResourceConfiguration.java

示例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;
}
 
开发者ID:xyxyLiu,项目名称:AndResM,代码行数:11,代码来源:ResourceString.java


注:本文中的com.google.common.primitives.UnsignedBytes.toInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。