List of usage examples for com.google.common.primitives Bytes asList
public static List<Byte> asList(byte... backingArray)
From source file:com.streamsets.pipeline.lib.parser.net.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)); }//w w w . j a va2s. c om 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; }
From source file:org.jclouds.googlecloudstorage.domain.DomainUtils.java
public static byte[] reverse(byte[] b) { List<Byte> hashByte = Bytes.asList(b); List<Byte> reversedList = Lists.reverse(hashByte); return Bytes.toArray(reversedList); }
From source file:io.v.impl.google.lib.discovery.UUIDUtil.java
/** * Converts from {@link UUID} to {@link Uuid}. *//*from www . j a v a 2 s . co m*/ public static Uuid UUIDToUuid(UUID id) { ByteBuffer b = ByteBuffer.allocate(16); b.putLong(id.getMostSignificantBits()); b.putLong(id.getLeastSignificantBits()); return new Uuid(Bytes.asList(b.array())); }
From source file:org.onosproject.isis.io.isispacket.tlv.TlvsToBytes.java
/** * Sets the ISIS TLV and returns in the form of bytes. * * @param isisTlv isisTlv./*from w w w . j a v a 2 s. com*/ * @return tlvBytes */ public static List<Byte> tlvToBytes(IsisTlv isisTlv) { List<Byte> tlvBytes = new ArrayList<>(); if (isisTlv instanceof AreaAddressTlv) { AreaAddressTlv areaAddressTlv = (AreaAddressTlv) isisTlv; tlvBytes.addAll(Bytes.asList(areaAddressTlv.asBytes())); } else if (isisTlv instanceof IpInterfaceAddressTlv) { IpInterfaceAddressTlv ipInterfaceAddressTlv = (IpInterfaceAddressTlv) isisTlv; tlvBytes.addAll(Bytes.asList(ipInterfaceAddressTlv.asBytes())); } else if (isisTlv instanceof ProtocolSupportedTlv) { ProtocolSupportedTlv protocolSupportedTlv = (ProtocolSupportedTlv) isisTlv; tlvBytes.addAll(Bytes.asList(protocolSupportedTlv.asBytes())); } else if (isisTlv instanceof PaddingTlv) { PaddingTlv paddingTlv = (PaddingTlv) isisTlv; tlvBytes.addAll(Bytes.asList(paddingTlv.asBytes())); } else if (isisTlv instanceof IsisNeighborTlv) { IsisNeighborTlv isisNeighborTlv = (IsisNeighborTlv) isisTlv; tlvBytes.addAll(Bytes.asList(isisNeighborTlv.asBytes())); } else if (isisTlv instanceof AdjacencyStateTlv) { AdjacencyStateTlv isisAdjacencyState = (AdjacencyStateTlv) isisTlv; tlvBytes.addAll(Bytes.asList(isisAdjacencyState.asBytes())); } else if (isisTlv instanceof HostNameTlv) { HostNameTlv hostNameTlv = (HostNameTlv) isisTlv; tlvBytes.addAll(Bytes.asList(hostNameTlv.asBytes())); } else if (isisTlv instanceof IpExtendedReachabilityTlv) { IpExtendedReachabilityTlv ipExtendedReachabilityTlv = (IpExtendedReachabilityTlv) isisTlv; tlvBytes.addAll(Bytes.asList(ipExtendedReachabilityTlv.asBytes())); } else if (isisTlv instanceof IpInternalReachabilityTlv) { IpInternalReachabilityTlv ipInternalReachabilityTlv = (IpInternalReachabilityTlv) isisTlv; tlvBytes.addAll(Bytes.asList(ipInternalReachabilityTlv.asBytes())); } else if (isisTlv instanceof IsReachabilityTlv) { IsReachabilityTlv isReachabilityTlv = (IsReachabilityTlv) isisTlv; tlvBytes.addAll(Bytes.asList(isReachabilityTlv.asBytes())); } else if (isisTlv instanceof LspEntriesTlv) { LspEntriesTlv lspEntriesTlv = (LspEntriesTlv) isisTlv; tlvBytes.addAll(Bytes.asList(lspEntriesTlv.asBytes())); } else if (isisTlv instanceof IsExtendedReachability) { IsExtendedReachability isExtendedReachability = (IsExtendedReachability) isisTlv; tlvBytes.addAll(Bytes.asList(isExtendedReachability.asBytes())); } else { log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes "); } return tlvBytes; }
From source file:com.sprogcoder.memory.MemoryUtils.java
public static int bytesToSignedInt(byte[] bytes) { byte[] byteCopy = Arrays.copyOf(bytes, bytes.length); Collections.reverse(Bytes.asList(byteCopy)); return Ints.fromByteArray(byteCopy); }
From source file:org.onosproject.isis.io.isispacket.tlv.subtlv.SubTlvToBytes.java
/** * Sets the ISIS sub TLV and returns in the form of bytes. * * @param subTlv isisTlv./*from w w w. java2 s . com*/ * @return subTlvBytes */ public static List<Byte> tlvToBytes(TrafficEngineeringSubTlv subTlv) { List<Byte> subTlvBytes = new ArrayList<>(); if (subTlv instanceof AdministrativeGroup) { AdministrativeGroup administrativeGroup = (AdministrativeGroup) subTlv; subTlvBytes.addAll(Bytes.asList(administrativeGroup.asBytes())); } else if (subTlv instanceof MaximumBandwidth) { MaximumBandwidth maximumBandwidth = (MaximumBandwidth) subTlv; subTlvBytes.addAll(Bytes.asList(maximumBandwidth.asBytes())); } else if (subTlv instanceof MaximumReservableBandwidth) { MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) subTlv; subTlvBytes.addAll(Bytes.asList(maximumReservableBandwidth.asBytes())); } else if (subTlv instanceof TrafficEngineeringMetric) { TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) subTlv; subTlvBytes.addAll(Bytes.asList(trafficEngineeringMetric.asBytes())); } else if (subTlv instanceof UnreservedBandwidth) { UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) subTlv; subTlvBytes.addAll(Bytes.asList(unreservedBandwidth.asBytes())); } else if (subTlv instanceof NeighborIpAddress) { NeighborIpAddress interfaceIpAddress = (NeighborIpAddress) subTlv; subTlvBytes.addAll(Bytes.asList(interfaceIpAddress.asBytes())); } else { log.debug("TlvsToBytes::UNKNOWN TLV TYPE ::TlvsToBytes "); } return subTlvBytes; }
From source file:org.immutables.check.Checkers.java
public static IterableChecker<List<Byte>, Byte> check(byte[] actualByteArray) { return check(Bytes.asList(actualByteArray)); }
From source file:com.yandex.yoctodb.util.UnsignedByteArray.java
@Override public Iterator<Byte> iterator() { return Bytes.asList(data).iterator(); }
From source file:com.jeffreybosboom.strata.Solution.java
private Solution(byte[] order, byte[] colors) { checkArgument(Bytes.asList(order).stream().distinct().count() == order.length, "contains duplicates: %s", Arrays.toString(order)); this.order = order; this.colors = colors; }
From source file:org.onosproject.ospf.protocol.lsa.TlvHeader.java
/** * Gets TLV header as bytes./*ww w . j a v a 2 s .co m*/ * * @return TLV header as bytes */ public byte[] getTlvHeaderAsByteArray() { List<Byte> headerLst = new ArrayList(); headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvType))); headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.tlvLength))); return Bytes.toArray(headerLst); }