本文整理汇总了Java中com.google.common.primitives.Bytes类的典型用法代码示例。如果您正苦于以下问题:Java Bytes类的具体用法?Java Bytes怎么用?Java Bytes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bytes类属于com.google.common.primitives包,在下文中一共展示了Bytes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetCustomString
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Test method for
* {@link org.opendaylight.controller.liblldp.LLDPTLV#getCustomString(byte[], int)}
* .
* @throws Exception
*/
@Test
public void testGetCustomString() throws Exception {
byte[] inputCustomTlv = Bytes.concat(new byte[] {
// custom type (7b) + length (9b) = 16b = 2B (skipped)
// 0x7f, 24,
// openflow OUI
0x00, 0x26, (byte) 0xe1,
// subtype
0x00},
// custom value
CUSTOM_TLV_ULTIMATE_BIN);
String actual = LLDPTLV.getCustomString(inputCustomTlv, inputCustomTlv.length);
LOG.debug("actual custom TLV value as string: {}", actual);
Assert.assertEquals(CUSTOM_TLV_ULTIMATE, actual);
}
示例2: getFirstMatch
import com.google.common.primitives.Bytes; //导入依赖的package包/类
public int getFirstMatch(byte[] content) {
byte[] beginning = content;
if (content.length > maxOffset) {
beginning = Arrays.copyOfRange(content, 0, maxOffset);
}
OR:
for (int i = 0; i < clues.length; i++) {
byte[][] group = clues[i];
for (byte[] clue : group) {
if (Bytes.indexOf(beginning, clue) == -1)
continue OR;
}
// success, all members of one group matched
return i;
}
return -1;
}
示例3: extractTagValuePairs
import com.google.common.primitives.Bytes; //导入依赖的package包/类
@Test
public void extractTagValuePairs() throws Exception {
byte[] paddedBytes = Bytes.concat(new byte[] {9,9},
tag1.getUidBytes(),
value1.getUidBytes(),
tag2.getUidBytes(),
value2.getUidBytes());
int offset = 2;
RowKeyTagValue tagValue1 = new RowKeyTagValue(tag1, value1);
RowKeyTagValue tagValue2 = new RowKeyTagValue(tag2, value2);
List<RowKeyTagValue> tagValues = RowKeyTagValue.extractTagValuePairs(paddedBytes, offset, offset + UID.UID_ARRAY_LENGTH * 4);
assertThat(tagValues).hasSize(2);
assertThat(tagValues.get(0)).isEqualTo(tagValue1);
assertThat(tagValues.get(1)).isEqualTo(tagValue2);
assertThat(tagValues.get(0).hashCode()).isEqualTo(tagValue1.hashCode());
assertThat(tagValues.get(1).hashCode()).isEqualTo(tagValue2.hashCode());
}
示例4: testReadBytes
import com.google.common.primitives.Bytes; //导入依赖的package包/类
public void testReadBytes() throws IOException {
ByteProcessor<byte[]> processor = new ByteProcessor<byte[]>() {
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
@Override
public boolean processBytes(byte[] buffer, int offset, int length) throws IOException {
if (length >= 0) {
out.write(buffer, offset, length);
}
return true;
}
@Override
public byte[] getResult() {
return out.toByteArray();
}
};
File asciiFile = getTestFile("ascii.txt");
byte[] result = Files.readBytes(asciiFile, processor);
assertEquals(Bytes.asList(Files.toByteArray(asciiFile)), Bytes.asList(result));
}
示例5: signRawTransaction
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Signs the raw bytes using a travel document.
* Follows the steps in this answer: https://bitcoin.stackexchange.com/a/5241
* @return signedRawTransaction
*/
public byte[] signRawTransaction(PublicKey pubkey, byte[][] parts, PassportConnection pcon) throws Exception {
byte[] rawTransaction = Bytes.concat(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5],
parts[6], parts[7], parts[8], parts[9], parts[10], parts[11], parts[12]);
// Double hash transaction
byte[] step14 = Sha256Hash.hash(Sha256Hash.hash(rawTransaction));
// Generate signature and get publickey
byte[] multiSignature = new byte[320];
byte[] hashPart;
for (int i = 0; i < 4; i++) {
hashPart = Arrays.copyOfRange(step14, i * 8, i * 8 + 8);
System.arraycopy(pcon.signData(hashPart), 0, multiSignature, i * 80, 80);
}
byte[] signatureLength = Util.hexStringToByteArray("fd97014d4101");
byte[] hashCodeType = Util.hexStringToByteArray("01");
byte[] publicKeyASN = pubkey.getEncoded();
byte[] publicKey = new byte[81];
System.arraycopy(publicKeyASN, publicKeyASN.length-81, publicKey, 0, 81);
byte[] publickeyLength = Util.hexStringToByteArray("4c51");
// Set signature and pubkey in format
byte[] step16 = Bytes.concat(signatureLength, multiSignature, hashCodeType, publickeyLength, publicKey);
// Update transaction with signature and remove hash code type
byte[] step19 = Bytes.concat(parts[0], parts[1], parts[2], parts[3], step16, parts[6],
parts[7], parts[8], parts[9], parts[10], parts[11], parts[12]);
return step19;
}
示例6: getPaddingTlvs
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Parse padding for PDU based on current length.
*
* @param currentLength current length
* @return byteArray padding array
*/
public static byte[] getPaddingTlvs(int currentLength) {
List<Byte> bytes = new ArrayList<>();
while (IsisConstants.PDU_LENGTH > currentLength) {
int length = IsisConstants.PDU_LENGTH - currentLength;
TlvHeader tlvHeader = new TlvHeader();
tlvHeader.setTlvType(TlvType.PADDING.value());
if (length >= PADDING_FIXED_LENGTH) {
tlvHeader.setTlvLength(PADDING_FIXED_LENGTH);
} else {
tlvHeader.setTlvLength(IsisConstants.PDU_LENGTH - (currentLength + TLVHEADERLENGTH));
}
PaddingTlv tlv = new PaddingTlv(tlvHeader);
bytes.addAll(Bytes.asList(tlv.asBytes()));
currentLength = currentLength + tlv.tlvLength() + TLVHEADERLENGTH;
}
byte[] byteArray = new byte[bytes.size()];
int i = 0;
for (byte byt : bytes) {
byteArray[i++] = byt;
}
return byteArray;
}
示例7: testDecodeWithoutAttestation
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Test method for {@link com.google.webauthn.gaedemo.objects.AuthenticatorData#decode(byte[])}.
*/
@Test
public void testDecodeWithoutAttestation() {
byte[] randomRpIdHash = new byte[32];
random.nextBytes(randomRpIdHash);
byte[] flags = {0};
int countInt = random.nextInt(Integer.MAX_VALUE);
byte[] count = ByteBuffer.allocate(4).putInt(countInt).array();
byte[] data = Bytes.concat(randomRpIdHash, flags, count);
try {
AuthenticatorData result = AuthenticatorData.decode(data);
assertArrayEquals(randomRpIdHash, result.getRpIdHash());
assertEquals(countInt, result.getSignCount());
} catch (ResponseException e) {
fail("Exception occurred");
}
}
示例8: toArray
import com.google.common.primitives.Bytes; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
if (componentType == boolean.class) {
return Booleans.toArray((Collection) values);
} else if (componentType == byte.class) {
return Bytes.toArray((Collection) values);
} else if (componentType == short.class) {
return Shorts.toArray((Collection) values);
} else if (componentType == int.class) {
return Ints.toArray((Collection) values);
} else if (componentType == long.class) {
return Longs.toArray((Collection) values);
} else if (componentType == float.class) {
return Floats.toArray((Collection) values);
} else if (componentType == double.class) {
return Doubles.toArray((Collection) values);
} else if (componentType == char.class) {
return Chars.toArray((Collection) values);
}
return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
示例9: asBytes
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Returns metric of reachability values as bytes of metric of reachability.
*
* @return byteArray metric of reachability values as bytes of metric of reachability
*/
public byte[] asBytes() {
List<Byte> bytes = new ArrayList<>();
bytes.add((byte) this.defaultMetric());
if (this.isDelayIsInternal()) {
bytes.add((byte) Integer.parseInt(value1));
} else {
bytes.add((byte) Integer.parseInt(value2));
}
if (this.isExpenseIsInternal()) {
bytes.add((byte) Integer.parseInt(value1));
} else {
bytes.add((byte) Integer.parseInt(value2));
}
if (this.isErrorIsInternal()) {
bytes.add((byte) Integer.parseInt(value1));
} else {
bytes.add((byte) Integer.parseInt(value2));
}
bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.neighborId()));
return Bytes.toArray(bytes);
}
示例10: hmacDrbgUpdate
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* HMAC_DRBG Update Process
*
* See: http://csrc.nist.gov/publications/nistpubs/800-90A/SP800-90A.pdf 10.1.2.2
*/
private void hmacDrbgUpdate(byte[] providedData) {
// 1. K = HMAC(K, V || 0x00 || provided_data)
setKey(hash(Bytes.concat(value, BYTE_ARRAY_0, emptyIfNull(providedData))));
// 2. V = HMAC(K, V);
value = hash(value);
// 3. If (provided_data = Null), then return K and V.
if (providedData == null) {
return;
}
// 4. K = HMAC (K, V || 0x01 || provided_data).
setKey(hash(Bytes.concat(value, BYTE_ARRAY_1, providedData)));
// 5. V = HMAC (K, V).
value = hash(value);
}
示例11: getDdHeaderAsByteArray
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Gets DD Header as byte array.
*
* @return dd header as byte array.
*/
public byte[] getDdHeaderAsByteArray() {
List<Byte> headerLst = new ArrayList<>();
try {
headerLst.add((byte) this.ospfVersion());
headerLst.add((byte) this.ospfType());
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.ospfPacLength())));
headerLst.addAll(Bytes.asList(this.routerId().toOctets()));
headerLst.addAll(Bytes.asList(this.areaId().toOctets()));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.checksum())));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.authType())));
//Authentication is 0 always. Total 8 bytes consist of zero
byte[] auth = new byte[OspfUtil.EIGHT_BYTES];
headerLst.addAll(Bytes.asList(auth));
} catch (Exception e) {
log.debug("Error");
}
return Bytes.toArray(headerLst);
}
示例12: getHelloHeaderAsByteArray
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Gets hello header as byte array.
*
* @return hello header
*/
public byte[] getHelloHeaderAsByteArray() {
List<Byte> headerLst = new ArrayList<>();
try {
headerLst.add((byte) this.ospfVersion());
headerLst.add((byte) this.ospfType());
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.ospfPacLength())));
headerLst.addAll(Bytes.asList(this.routerId().toOctets()));
headerLst.addAll(Bytes.asList(this.areaId().toOctets()));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.checksum())));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.authType())));
//Authentication is 0 always. Total 8 bytes consist of zero
byte[] auth = new byte[OspfUtil.EIGHT_BYTES];
headerLst.addAll(Bytes.asList(auth));
} catch (Exception e) {
log.debug("Error::getHelloHeaderAsByteArray {}", e.getMessage());
return Bytes.toArray(headerLst);
}
return Bytes.toArray(headerLst);
}
示例13: getHelloBodyAsByteArray
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Gets hello body as byte array.
*
* @return hello body as byte array
*/
public byte[] getHelloBodyAsByteArray() {
List<Byte> bodyLst = new ArrayList<>();
try {
bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
bodyLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.helloInterval())));
bodyLst.add((byte) this.options());
bodyLst.add((byte) this.routerPriority());
bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(this.routerDeadInterval())));
bodyLst.addAll(Bytes.asList(this.dr().toOctets()));
bodyLst.addAll(Bytes.asList(this.bdr().toOctets()));
for (Ip4Address neighbour : neighborAddress) {
bodyLst.addAll(Bytes.asList(neighbour.toOctets()));
}
} catch (Exception e) {
log.debug("Error::getHelloBodyAsByteArray {}", e.getMessage());
return Bytes.toArray(bodyLst);
}
return Bytes.toArray(bodyLst);
}
示例14: getLsuHeaderAsByteArray
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Gets lsu header.
*
* @return lsu header as byte array
*/
public byte[] getLsuHeaderAsByteArray() {
List<Byte> headerLst = new ArrayList<>();
try {
headerLst.add((byte) this.ospfVersion());
headerLst.add((byte) this.ospfType());
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.ospfPacLength())));
headerLst.addAll(Bytes.asList(this.routerId().toOctets()));
headerLst.addAll(Bytes.asList(this.areaId().toOctets()));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.checksum())));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.authType())));
//Authentication is 0 always. Total 8 bytes consist of zero
byte[] auth = new byte[OspfUtil.EIGHT_BYTES];
headerLst.addAll(Bytes.asList(auth));
} catch (Exception e) {
log.debug("Error::LSUpdate::getLsuHeaderAsByteArray:: {}", e.getMessage());
return Bytes.toArray(headerLst);
}
return Bytes.toArray(headerLst);
}
示例15: getOpaqueLsaHeaderAsByteArray
import com.google.common.primitives.Bytes; //导入依赖的package包/类
/**
* Gets header as byte array.
*
* @return header as byte array
*/
public byte[] getOpaqueLsaHeaderAsByteArray() {
List<Byte> headerLst = new ArrayList<>();
try {
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.age())));
headerLst.add((byte) this.options());
headerLst.add((byte) this.lsType());
headerLst.add((byte) this.opaqueType());
headerLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(this.opaqueId())));
headerLst.addAll(Bytes.asList(this.advertisingRouter().toOctets()));
headerLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(this.lsSequenceNo())));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.lsCheckSum())));
headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.lsPacketLen())));
} catch (Exception e) {
log.debug("Error::getLsaHeaderAsByteArray {}", e.getMessage());
return Bytes.toArray(headerLst);
}
return Bytes.toArray(headerLst);
}