下面列出了com.google.common.primitives.Bytes#asList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void diffPerCharacter(DiffSet set, DiffEventListener original_event, DiffEventListener target_event) throws Exception {
try {
List<Byte> listOrig = Bytes.asList(set.getOriginal());
List<Byte> listTarg = Bytes.asList(set.getTarget());
Patch diff = DiffUtils.diff(listOrig, listTarg);
List<Delta> deltas = diff.getDeltas();
for (Delta delta : deltas) {
Chunk chunkOrig = delta.getOriginal();
Chunk chunkTarg = delta.getRevised();
if (delta.getType() == Delta.TYPE.CHANGE) {
original_event.foundChgDelta(chunkPositionPerByte(listOrig, chunkOrig), chunkLengthPerByte(chunkOrig));
target_event.foundChgDelta(chunkPositionPerByte(listTarg, chunkTarg), chunkLengthPerByte(chunkTarg));
} else if (delta.getType() == Delta.TYPE.INSERT) {
target_event.foundInsDelta(chunkPositionPerByte(listTarg, chunkTarg), chunkLengthPerByte(chunkTarg));
} else if (delta.getType() == Delta.TYPE.DELETE) {
original_event.foundDelDelta(chunkPositionPerByte(listOrig, chunkOrig), chunkLengthPerByte(chunkOrig));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static List<List<Byte>> getRandomByteSlices(byte[] bytes) {
List<Byte> byteList = Bytes.asList(bytes);
int numSlices = nextInt(2, 10);
List<Integer> sliceIndexes = new ArrayList<Integer>();
for (int i = 1; i <= numSlices; i++) {
sliceIndexes.add(nextInt(0, bytes.length));
}
Collections.sort(sliceIndexes);
List<List<Byte>> slices = new LinkedList<List<Byte>>();
int byteInd = 0;
for (int sliceIndex : sliceIndexes) {
slices.add(byteList.subList(byteInd, sliceIndex));
byteInd = sliceIndex;
}
slices.add(byteList.subList(byteInd, byteList.size()));
return slices;
}
public static List<List<Byte>> getRandomByteSlices(byte[] bytes) {
List<Byte> byteList = Bytes.asList(bytes);
int numSlices = RandomTestUtils.nextInt(2, 10);
List<Integer> sliceIndexes = new ArrayList<>();
for (int i=1; i<=numSlices; i++) {
sliceIndexes.add(RandomTestUtils.nextInt(0, bytes.length));
}
Collections.sort(sliceIndexes);
List<List<Byte>> slices = new LinkedList<>();
int byteInd = 0;
for (int sliceIndex : sliceIndexes) {
// System.out.println(String.format("Slice from %d through %d", byteInd, sliceIndex));
slices.add(byteList.subList(byteInd, sliceIndex));
byteInd = sliceIndex;
}
// System.out.println(String.format("Slice from %d through %d", byteInd, byteList.size()));
slices.add(byteList.subList(byteInd, byteList.size()));
return slices;
}
private static List<Byte> bytes(InputStream in) {
try {
return Bytes.asList(ByteStreams.toByteArray(in));
} catch (IOException ex) {
throw new AssertionError(ex);
}
}
Tx_in(ZCashTransactionOutput base) {
List<Byte> txbytes = Bytes.asList(Utils.hexToBytes(base.txid));
Collections.reverse(txbytes);
txid = Bytes.toArray(txbytes);
index = base.n;
script = Utils.hexToBytes(base.hex);
this.value = base.value;
}
Tx_in(ZCashTransactionOutput base) {
List<Byte> txbytes = Bytes.asList(Utils.hexToBytes(base.txid));
Collections.reverse(txbytes);
txid = Bytes.toArray(txbytes);
index = base.n;
script = Utils.hexToBytes(base.hex);
this.value = base.value;
}
/**
* Takes a screenshot of the currently displayed page and returns it as a Array of bytes.
* <p>
* This operation is considered "optional" any exceptions occurring during its execution will be logged,
* but not rethrown!
*
* @return the screenshot as bytes
* @see TakesScreenshot#getScreenshotAs(OutputType)
* @see OutputType#BYTES
* @since 2.0
*/
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public Optional<List<Byte>> take() {
List<Byte> bytes = null;
if ((webDriver() instanceof TakesScreenshot)) {
try {
bytes = Bytes.asList((( TakesScreenshot ) webDriver()).getScreenshotAs(OutputType.BYTES));
} catch (RuntimeException e) {
log.warn("Exception while creating screenshot, returning null.", e);
}
}
return Optional.ofNullable(bytes);
}
private static List<Byte> bytes(InputStream in) {
try {
return Bytes.asList(ByteStreams.toByteArray(in));
} catch (IOException ex) {
throw new AssertionError(ex);
}
}
public List<Byte> asByteList() {
return Bytes.asList(asBytes());
}
public BlockMatch(Material type, byte[] dataValues) {
this.type = type;
this.dataValues = dataValues != null && dataValues.length > 0 ? new TreeSet<>(Bytes.asList(dataValues)) : Collections.emptySet();
}