Java Code Examples for com.google.common.primitives.Bytes#asList()

The following examples show how to use com.google.common.primitives.Bytes#asList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiffBinary.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
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();
	}
}
 
Example 2
Source File: TestDelimitedLengthFieldBasedFrameDecoder.java    From datacollector with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: NetTestUtils.java    From datacollector with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: MessageDeframerTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
private static List<Byte> bytes(InputStream in) {
  try {
    return Bytes.asList(ByteStreams.toByteArray(in));
  } catch (IOException ex) {
    throw new AssertionError(ex);
  }
}
 
Example 5
Source File: ZCashTransaction_taddr.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: ZCashTransaction_taddr.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: ScreenshotTaker.java    From webtester2-core with Apache License 2.0 5 votes vote down vote up
/**
 * 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);

}
 
Example 8
Source File: MessageDeframerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
private static List<Byte> bytes(InputStream in) {
  try {
    return Bytes.asList(ByteStreams.toByteArray(in));
  } catch (IOException ex) {
    throw new AssertionError(ex);
  }
}
 
Example 9
Source File: BitList.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public List<Byte> asByteList() {
    return Bytes.asList(asBytes());
}
 
Example 10
Source File: BlockMatch.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
public BlockMatch(Material type, byte[] dataValues) {
    this.type = type;
    this.dataValues = dataValues != null && dataValues.length > 0 ? new TreeSet<>(Bytes.asList(dataValues)) : Collections.emptySet();
}