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


Java Ints.fromBytes方法代码示例

本文整理汇总了Java中com.google.common.primitives.Ints.fromBytes方法的典型用法代码示例。如果您正苦于以下问题:Java Ints.fromBytes方法的具体用法?Java Ints.fromBytes怎么用?Java Ints.fromBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.primitives.Ints的用法示例。


在下文中一共展示了Ints.fromBytes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toAddrString

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * Returns the string representation of an {@link InetAddress}.
 *
 * <p>For IPv4 addresses, this is identical to {@link InetAddress#getHostAddress()}, but for IPv6
 * addresses, the output follows <a href="http://tools.ietf.org/html/rfc5952">RFC 5952</a> section
 * 4. The main difference is that this method uses "::" for zero compression, while Java's version
 * uses the uncompressed form.
 *
 * <p>This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses
 * such as "::c000:201". The output does not include a Scope ID.
 *
 * @param ip {@link InetAddress} to be converted to an address string
 * @return {@code String} containing the text-formatted IP address
 * @since 10.0
 */
public static String toAddrString(InetAddress ip) {
  checkNotNull(ip);
  if (ip instanceof Inet4Address) {
    // For IPv4, Java's formatting is good enough.
    return ip.getHostAddress();
  }
  checkArgument(ip instanceof Inet6Address);
  byte[] bytes = ip.getAddress();
  int[] hextets = new int[IPV6_PART_COUNT];
  for (int i = 0; i < hextets.length; i++) {
    hextets[i] = Ints.fromBytes((byte) 0, (byte) 0, bytes[2 * i], bytes[2 * i + 1]);
  }
  compressLongestRunOfZeroes(hextets);
  return hextetsToIPv6String(hextets);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:31,代码来源:InetAddresses.java

示例2: readUnsignedShort

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * Reads an unsigned {@code short} as specified by {@link DataInputStream#readUnsignedShort()},
 * except using little-endian byte order.
 *
 * @return the next two bytes of the input stream, interpreted as an unsigned 16-bit integer in
 *     little-endian byte order
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // to skip some bytes
@Override
public int readUnsignedShort() throws IOException {
  byte b1 = readAndCheckByte();
  byte b2 = readAndCheckByte();

  return Ints.fromBytes((byte) 0, (byte) 0, b2, b1);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:LittleEndianDataInputStream.java

示例3: readInt

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * Reads an integer as specified by {@link DataInputStream#readInt()}, except using little-endian
 * byte order.
 *
 * @return the next four bytes of the input stream, interpreted as an {@code int} in little-endian
 *     byte order
 * @throws IOException if an I/O error occurs
 */
@CanIgnoreReturnValue // to skip some bytes
@Override
public int readInt() throws IOException {
  byte b1 = readAndCheckByte();
  byte b2 = readAndCheckByte();
  byte b3 = readAndCheckByte();
  byte b4 = readAndCheckByte();

  return Ints.fromBytes(b4, b3, b2, b1);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:LittleEndianDataInputStream.java

示例4: decode

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * @param authData
 * @return Decoded AuthenticatorData object
 * @throws ResponseException
 */
public static AuthenticatorData decode(byte[] authData) throws ResponseException {
  if (authData.length < 37) {
    throw new ResponseException("Invalid input");
  }

  int index = 0;
  byte[] rpIdHash = new byte[32];
  System.arraycopy(authData, 0, rpIdHash, 0, 32);
  index += 32;
  byte flags = authData[index++];
  int signCount =
      Ints.fromBytes(authData[index++], authData[index++], authData[index++], authData[index++]);

  AttestationData attData = null;
  // Bit 6 determines whether attestation data was included
  if ((flags & 1 << 6) != 0) {
    byte[] remainder = new byte[authData.length - index];
    System.arraycopy(authData, index, remainder, 0, authData.length - index);
    try {
      attData = AttestationData.decode(remainder);
    } catch (CborException e) {
      throw new ResponseException("Error decoding");
    }
  }

  return new AuthenticatorData(rpIdHash, flags, signCount, attData);
}
 
开发者ID:google,项目名称:webauthndemo,代码行数:33,代码来源:AuthenticatorData.java

示例5: hashCode

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * Returns the last four bytes of the wrapped hash. This should be unique
 * enough to be a suitable hash code even for blocks, where the goal is to
 * try and get the first bytes to be zeros (i.e. the value as a big integer
 * lower than the target value).
 */
@Override
public int hashCode() {
    // Use the last 4 bytes, not the first 4 which are often zeros in
    // Bitcoin.
    return Ints.fromBytes(bytes[LENGTH - 4], bytes[LENGTH - 3], bytes[LENGTH - 2], bytes[LENGTH - 1]);
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:13,代码来源:Sha256Hash.java

示例6: hashCode

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
@Override
public int hashCode() {
    // Public keys are random already so we can just use a part of them as the hashcode. Read from the start to
    // avoid picking up the type code (compressed vs uncompressed) which is tacked on the end.
    byte[] bits = getPubKey();
    return Ints.fromBytes(bits[0], bits[1], bits[2], bits[3]);
}
 
开发者ID:rsksmart,项目名称:bitcoinj-thin,代码行数:8,代码来源:BtcECKey.java

示例7: hashCode

import com.google.common.primitives.Ints; //导入方法依赖的package包/类
/**
 * Returns the last four bytes of the wrapped hash. This should be unique enough to be a suitable hash code even for
 * blocks, where the goal is to try and get the first bytes to be zeros (i.e. the value as a big integer lower
 * than the target value).
 */
@Override
public int hashCode() {
    // Use the last 4 bytes, not the first 4 which are often zeros in Bitcoin.
    return Ints.fromBytes(bytes[28], bytes[29], bytes[30], bytes[31]);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:11,代码来源:Sha3Hash.java


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