com.google.common.primitives.Bytes#asList ( )源码实例Demo

下面列出了com.google.common.primitives.Bytes#asList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PacketProxy   文件: DiffBinary.java
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;
}
 
源代码3 项目: datacollector   文件: NetTestUtils.java
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;
}
 
源代码4 项目: grpc-nebula-java   文件: MessageDeframerTest.java
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;
}
 
源代码7 项目: webtester2-core   文件: ScreenshotTaker.java
/**
 * 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);

}
 
源代码8 项目: grpc-java   文件: MessageDeframerTest.java
private static List<Byte> bytes(InputStream in) {
  try {
    return Bytes.asList(ByteStreams.toByteArray(in));
  } catch (IOException ex) {
    throw new AssertionError(ex);
  }
}
 
源代码9 项目: brooklyn-server   文件: BitList.java
public List<Byte> asByteList() {
    return Bytes.asList(asBytes());
}
 
源代码10 项目: uSkyBlock   文件: BlockMatch.java
public BlockMatch(Material type, byte[] dataValues) {
    this.type = type;
    this.dataValues = dataValues != null && dataValues.length > 0 ? new TreeSet<>(Bytes.asList(dataValues)) : Collections.emptySet();
}