本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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]);
}
示例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]);
}
示例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]);
}