List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:de.softwareforge.pgpsigner.key.KeyId.java
public KeyId(final Long id) { this.id = id; this.keyId = "0x" + StringUtils.right(Long.toHexString(id), 8); }
From source file:org.opendaylight.latency.util.LatencyPacketUtil.java
public static byte[] buildLldpFrame(final NodeId nodeId, final NodeConnectorId nodeConnectorId, final MacAddress src, final Long outPortNo, final MacAddress destinationAddress) { // Create discovery pkt LLDP discoveryPkt = new LLDP(); // Create LLDP ChassisID TLV BigInteger dataPathId = dataPathIdFromNodeId(nodeId); byte[] cidValue = LLDPTLV.createChassisIDTLVValue(colonize(bigIntegerToPaddedHex(dataPathId))); LLDPTLV chassisIdTlv = new LLDPTLV(); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()).setLength((short) cidValue.length) .setValue(cidValue);/*from www. java 2s.c o m*/ discoveryPkt.setChassisId(chassisIdTlv); // Create LLDP PortID TL String hexString = Long.toHexString(outPortNo); byte[] pidValue = LLDPTLV.createPortIDTLVValue(hexString); LLDPTLV portIdTlv = new LLDPTLV(); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()).setLength((short) pidValue.length).setValue(pidValue); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()); discoveryPkt.setPortId(portIdTlv); // Create LLDP TTL TLV byte[] ttl = new byte[] { (byte) 0x13, (byte) 0x37 }; LLDPTLV ttlTlv = new LLDPTLV(); ttlTlv.setType(LLDPTLV.TLVType.TTL.getValue()).setLength((short) ttl.length).setValue(ttl); discoveryPkt.setTtl(ttlTlv); // Create LLDP SystemName TLV byte[] snValue = LLDPTLV.createSystemNameTLVValue(nodeId.getValue()); LLDPTLV systemNameTlv = new LLDPTLV(); systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()); systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()).setLength((short) snValue.length) .setValue(snValue); discoveryPkt.setSystemNameId(systemNameTlv); // Create LLDP Custom TLV byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnectorId.getValue()); LLDPTLV customTlv = new LLDPTLV(); customTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customValue.length) .setValue(customValue); discoveryPkt.addCustomTLV(customTlv); //Create LLDP CustomSec TLV /*byte[] pureValue = new byte[1]; try { pureValue = getValueForLLDPPacketIntegrityEnsuring(nodeConnectorId); byte[] customSecValue = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, pureValue); LLDPTLV customSecTlv = new LLDPTLV(); customSecTlv.setType(LLDPTLV.TLVType.Custom.getValue()) .setLength((short)customSecValue.length) .setValue(customSecValue); discoveryPkt.addCustomTLV(customSecTlv); } catch (NoSuchAlgorithmException e1) { LOG.info("LLDP extra authenticator creation failed: {}", e1.getMessage()); LOG.debug("Reason why LLDP extra authenticator creation failed: ", e1); }*/ //Create Latency Test Custom TLV String latency = "latency"; byte[] latencybyte = new byte[1]; latencybyte = latency.getBytes(); byte[] latencyValue = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, latencybyte); LLDPTLV latencyTLV = new LLDPTLV(); latencyTLV.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) latencyValue.length) .setValue(latencyValue); discoveryPkt.addCustomTLV(latencyTLV); // Create ethernet pkt byte[] sourceMac = HexEncode.bytesFromHexString(src.getValue()); Ethernet ethPkt = new Ethernet(); ethPkt.setSourceMACAddress(sourceMac).setEtherType(EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt); if (destinationAddress == null) { ethPkt.setDestinationMACAddress(LLDP.LLDPMulticastMac); } else { ethPkt.setDestinationMACAddress(HexEncode.bytesFromHexString(destinationAddress.getValue())); } try { return ethPkt.serialize(); } catch (PacketException e) { LOG.warn("Error creating LLDP packet: {}", e.getMessage()); LOG.debug("Error creating LLDP packet.. ", e); } return null; }
From source file:Uuid32Generator.java
public String generate() { StringBuilder strRetVal = new StringBuilder(); String strTemp;// w w w . jav a2 s. co m try { // IPAddress segment InetAddress addr = InetAddress.getLocalHost(); byte[] ipaddr = addr.getAddress(); for (byte anIpaddr : ipaddr) { Byte b = new Byte(anIpaddr); strTemp = Integer.toHexString(b.intValue() & 0x000000ff); strRetVal.append(ZEROS.substring(0, 2 - strTemp.length())); strRetVal.append(strTemp); } strRetVal.append(':'); // CurrentTimeMillis() segment strTemp = Long.toHexString(System.currentTimeMillis()); strRetVal.append(ZEROS.substring(0, 12 - strTemp.length())); strRetVal.append(strTemp).append(':'); // random segment SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); strTemp = Integer.toHexString(prng.nextInt()); while (strTemp.length() < 8) { strTemp = '0' + strTemp; } strRetVal.append(strTemp.substring(4)).append(':'); // IdentityHash() segment strTemp = Long.toHexString(System.identityHashCode(this)); strRetVal.append(ZEROS.substring(0, 8 - strTemp.length())); strRetVal.append(strTemp); } catch (UnknownHostException uhex) { throw new RuntimeException("Unknown host.", uhex); } catch (NoSuchAlgorithmException nsaex) { throw new RuntimeException("Algorithm 'SHA1PRNG' is unavailiable.", nsaex); } return strRetVal.toString().toUpperCase(); }
From source file:org.trellisldp.rosid.file.FileUtils.java
/** * Partition an identifier into a directory structure * @param identifier the identifier/*from w ww. j a v a 2 s . c om*/ * @return a string usable as a directory path */ public static String partition(final String identifier) { requireNonNull(identifier, "identifier must not be null!"); final StringJoiner joiner = new StringJoiner(separator); final CRC32 hasher = new CRC32(); hasher.update(identifier.getBytes(UTF_8)); final String intermediate = Long.toHexString(hasher.getValue()); range(0, intermediate.length() / LENGTH).limit(MAX) .forEach(i -> joiner.add(intermediate.substring(i * LENGTH, (i + 1) * LENGTH))); joiner.add(md5Hex(identifier)); return joiner.toString(); }
From source file:mondrian.util.UtilCompatibleJdk14.java
public static synchronized String generateUuidStringStatic() { while (true) { String uuid = UUID_BASE + Long.toHexString(System.currentTimeMillis()); if (!uuid.equals(previousUuid)) { previousUuid = uuid;/*from ww w.j a va 2s .c om*/ return uuid; } try { Thread.sleep(1); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
From source file:org.opendaylight.openflowplugin.applications.lldpspeaker.LLDPUtil.java
static byte[] buildLldpFrame(final NodeId nodeId, final NodeConnectorId nodeConnectorId, final MacAddress src, final Long outPortNo, final MacAddress destinationAddress) { // Create discovery pkt LLDP discoveryPkt = new LLDP(); // Create LLDP ChassisID TLV BigInteger dataPathId = dataPathIdFromNodeId(nodeId); byte[] cidValue = LLDPTLV.createChassisIDTLVValue(colonize(bigIntegerToPaddedHex(dataPathId))); LLDPTLV chassisIdTlv = new LLDPTLV(); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()); chassisIdTlv.setType(LLDPTLV.TLVType.ChassisID.getValue()).setLength((short) cidValue.length) .setValue(cidValue);/* w w w. j av a 2 s .c o m*/ discoveryPkt.setChassisId(chassisIdTlv); // Create LLDP PortID TL String hexString = Long.toHexString(outPortNo); byte[] pidValue = LLDPTLV.createPortIDTLVValue(hexString); LLDPTLV portIdTlv = new LLDPTLV(); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()).setLength((short) pidValue.length).setValue(pidValue); portIdTlv.setType(LLDPTLV.TLVType.PortID.getValue()); discoveryPkt.setPortId(portIdTlv); // Create LLDP TTL TLV byte[] ttl = new byte[] { (byte) 0x13, (byte) 0x37 }; LLDPTLV ttlTlv = new LLDPTLV(); ttlTlv.setType(LLDPTLV.TLVType.TTL.getValue()).setLength((short) ttl.length).setValue(ttl); discoveryPkt.setTtl(ttlTlv); // Create LLDP SystemName TLV byte[] snValue = LLDPTLV.createSystemNameTLVValue(nodeId.getValue()); LLDPTLV systemNameTlv = new LLDPTLV(); systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()); systemNameTlv.setType(LLDPTLV.TLVType.SystemName.getValue()).setLength((short) snValue.length) .setValue(snValue); discoveryPkt.setSystemNameId(systemNameTlv); // Create LLDP Custom TLV byte[] customValue = LLDPTLV.createCustomTLVValue(nodeConnectorId.getValue()); LLDPTLV customTlv = new LLDPTLV(); customTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customValue.length) .setValue(customValue); discoveryPkt.addCustomTLV(customTlv); //Create LLDP CustomSec TLV byte[] pureValue = new byte[1]; try { pureValue = getValueForLLDPPacketIntegrityEnsuring(nodeConnectorId); byte[] customSecValue = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_SUB_TYPE_CUSTOM_SEC, pureValue); LLDPTLV customSecTlv = new LLDPTLV(); customSecTlv.setType(LLDPTLV.TLVType.Custom.getValue()).setLength((short) customSecValue.length) .setValue(customSecValue); discoveryPkt.addCustomTLV(customSecTlv); } catch (NoSuchAlgorithmException e1) { LOG.info("LLDP extra authenticator creation failed: {}", e1.getMessage()); LOG.debug("Reason why LLDP extra authenticator creation failed: ", e1); } // Create ethernet pkt byte[] sourceMac = HexEncode.bytesFromHexString(src.getValue()); Ethernet ethPkt = new Ethernet(); ethPkt.setSourceMACAddress(sourceMac).setEtherType(EtherTypes.LLDP.shortValue()).setPayload(discoveryPkt); if (destinationAddress == null) { ethPkt.setDestinationMACAddress(LLDP.LLDPMulticastMac); } else { ethPkt.setDestinationMACAddress(HexEncode.bytesFromHexString(destinationAddress.getValue())); } try { return ethPkt.serialize(); } catch (PacketException e) { LOG.warn("Error creating LLDP packet: {}", e.getMessage()); LOG.debug("Error creating LLDP packet.. ", e); } return null; }
From source file:ch.cyberduck.core.io.CRC32ChecksumCompute.java
@Override public Checksum compute(final InputStream in, final TransferStatus status) throws ChecksumException { final CRC32 crc32 = new CRC32(); try {//from w ww . j a v a 2s . c o m byte[] buffer = new byte[16384]; int bytesRead; while ((bytesRead = in.read(buffer, 0, buffer.length)) != -1) { crc32.update(buffer, 0, bytesRead); } } catch (IOException e) { throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e.getMessage(), e); } finally { IOUtils.closeQuietly(in); } return new Checksum(HashAlgorithm.crc32, Long.toHexString(crc32.getValue())); }
From source file:fr.immotronic.ubikit.pems.enocean.impl.EnoceanDeviceImpl.java
public static String makeEnoceanItemUID(long enoceanUID) { return "ENO" + Long.toHexString(enoceanUID); }
From source file:org.codice.ddf.checksum.impl.CRC32ChecksumProvider.java
@Override public String calculateChecksum(InputStream inputStream) throws IOException { if (inputStream == null) { throw new IllegalArgumentException("InputStream cannot be null"); }/*from ww w .j a v a 2s . co m*/ byte[] bytes = IOUtils.toByteArray(inputStream); Checksum checksum = new CRC32(); checksum.update(bytes, 0, bytes.length); long checkSumValue = checksum.getValue(); return Long.toHexString(checkSumValue); }
From source file:com.example.oauth.Authentication.java
private OAuth2Request request() { final ClientApplicationEntity clientApplication = accessTokenEntity.getClientApplication(); return new OAuth2Request(Collections.emptyMap(), Long.toHexString(clientApplication.getId()), resourceUserAuthentication.getAuthorities(), true, accessToken.getScope(), Collections.singleton(ResourceConfig.RESOURCE_ID), clientApplication.getRedirectUri(), Collections.emptySet(), Collections.emptyMap()); }