List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:db.PGKeys.java
private static String randomKey2() { UUID rand = UUID.randomUUID(); return Long.toHexString(rand.getMostSignificantBits() + 37 * rand.getLeastSignificantBits()); }
From source file:com.cloudbees.jenkins.plugins.dockerslaves.DockerfileContainerDefinition.java
@Override public String getImage(DockerDriver driver, Launcher.ProcStarter procStarter, TaskListener listener) throws IOException, InterruptedException { if (image != null) return image; String tag = Long.toHexString(System.nanoTime()); final FilePath workspace = procStarter.pwd(); FilePath contextRoot = workspace.child(contextPath); final FilePath pathToContext = contextRoot.child(contextPath); if (!pathToContext.exists()) { throw new IOException(pathToContext.getRemote() + " does not exists."); }/* w w w . j a v a 2 s. c o m*/ final FilePath pathToDockerfile = contextRoot.child(dockerfile); if (!pathToDockerfile.exists()) { throw new IOException(pathToContext.getRemote() + " does not exists."); } final File context = Util.createTempDir(); pathToContext.copyRecursiveTo(new FilePath(context)); pathToDockerfile.copyTo(new FilePath(new File(context, "Dockerfile"))); final Launcher launcher = new Launcher.LocalLauncher(listener); if (driver.buildDockerfile(launcher, context.getAbsolutePath(), tag) != 0) { throw new IOException("Failed to build image from Dockerfile " + dockerfile); } Util.deleteRecursive(context); this.image = tag; return tag; }
From source file:it.dockins.dockerslaves.spec.DockerfileContainerDefinition.java
@Override public String getImage(DockerDriver driver, Launcher.ProcStarter procStarter, TaskListener listener) throws IOException, InterruptedException { boolean pull = forcePull; if (image != null) return image; String tag = Long.toHexString(System.nanoTime()); final FilePath workspace = procStarter.pwd(); final FilePath pathToContext = workspace.child(contextPath); if (!pathToContext.exists()) { throw new IOException(pathToContext.getRemote() + " does not exists."); }//from w w w. ja v a 2s.c o m final FilePath pathToDockerfile = pathToContext.child(dockerfile); if (!pathToDockerfile.exists()) { throw new IOException(pathToContext.getRemote() + " does not exists."); } final File context = Util.createTempDir(); pathToContext.copyRecursiveTo(new FilePath(context)); pathToDockerfile.copyTo(new FilePath(new File(context, "Dockerfile"))); if (driver.buildDockerfile(listener, context.getAbsolutePath(), tag, pull) != 0) { throw new IOException("Failed to build image from Dockerfile " + dockerfile); } Util.deleteRecursive(context); this.image = tag; return tag; }
From source file:se.sawano.java.security.otp.rfc6238.ExploratoryTests.java
@Test public void should_perform_TOTP() throws Exception { System.out.println("--> " + hexStr2Bytes(seed).length); final ReferenceDataRepository testData = new ReferenceDataRepository().init(); final ReferenceDataRepository.ReferenceData data = testData .getForMode(ReferenceDataRepository.ReferenceData.Mode.SHA512); assertArrayEquals(hexStr2Bytes(seed64), secret().value()); final int numberOfDigitsInCode = 8; final long T0 = ReferenceDataRepository.T0.toEpochMilli(); final long stepSize = ReferenceDataRepository.TIME_STEP.toMillis(); final long T = (data.time.toEpochMilli() - T0) / stepSize; // Number of steps final String hexT = StringUtils.leftPad(Long.toHexString(T), 16, '0'); System.out.println("Thex=" + hexT); assertEquals(data.hexTime, hexT);/* w ww . ja v a 2s. c o m*/ final byte[] hexTBytes = Hex.decodeHex(hexT.toCharArray()); final byte[] hextBytes2 = hexStr2Bytes(hexT); assertArrayEquals(hextBytes2, hexTBytes); final byte[] hashBytes = HmacUtils.hmacSha512(secret().value(), hexTBytes); System.out.println(hashBytes.length); final int binary = truncate(hashBytes); int otp = binary % DIGITS_POWER[numberOfDigitsInCode]; final String totpString = StringUtils.leftPad(Integer.toString(otp), numberOfDigitsInCode, '0'); System.out.println(totpString); assertEquals(data.totp, totpString); }
From source file:edu.cornell.med.icb.util.SimpleChecksum.java
/** * Splits a long value into two long values, representing * the left and right side. This isn't necessarily the * top four bytes and bottom four bytes, it is based on * the number of bytes that are actually used in the value. * @param inval long value to split/* w w w. j a v a 2s. c o m*/ * @return two resultant long values in an array */ private static long[] splitLong(final long inval) { // Take the hex value and use HALF of the // left hex digits to make the first character // and half of right hex digits to make the // second character. final String checksumString = Long.toHexString(inval); final String[] maskStrings = makeHexMaskStrings(checksumString); final long[] maskLongs = new long[2]; maskLongs[0] = Long.parseLong(maskStrings[0], 16); maskLongs[1] = Long.parseLong(maskStrings[1], 16); final long[] result = new long[2]; result[0] = (inval & maskLongs[0]) % CHECKSUM_CHARS.length; result[1] = (inval & maskLongs[1]) % CHECKSUM_CHARS.length; return result; }
From source file:org.openntf.xpt.core.ltpa.Token.java
/** * Generates a new token./* w w w. j a v a 2 s . c o m*/ * * @param canonicalUser * e.g. CN=Christian Guedemann/o=EXAMPLE/C=CH * @param strSecret * the tokens secrete * @param tokenCreation * Date for the token creation * @param expDuration * Expiraiton Time in Minutes * @return New Token Object * @throws NoSuchAlgorithmException * @throws UnsupportedEncodingException */ public static Token generate(String canonicalUser, Date tokenCreation, TokenConfiguration config) throws NoSuchAlgorithmException, UnsupportedEncodingException { Token ltpa = new Token(); Calendar calendar = Calendar.getInstance(); MessageDigest md; md = MessageDigest.getInstance("SHA-1"); ltpa.m_Header = new byte[] { 0, 1, 2, 3 }; ltpa.m_User = LMBCSConverter.INSTANCE.convertString(canonicalUser); byte[] token = null; calendar.setTime(tokenCreation); ltpa.m_Creation = Long.toHexString(calendar.getTime().getTime() / 1000).toUpperCase().getBytes(); calendar.setTime(tokenCreation); calendar.add(Calendar.MINUTE, config.getExpiration()); ltpa.m_Expires = Long.toHexString(calendar.getTime().getTime() / 1000).toUpperCase().getBytes(); token = concatenate(token, ltpa.m_Header); token = concatenate(token, ltpa.m_Creation); token = concatenate(token, ltpa.m_Expires); token = concatenate(token, ltpa.m_User); md.update(token); ltpa.m_Digest = md.digest(org.apache.commons.codec.binary.Base64.decodeBase64(config.getSecret())); token = concatenate(token, ltpa.m_Digest); ltpa.m_RawToken = token; ltpa.m_LtpaToken = org.apache.commons.codec.binary.Base64.encodeBase64String(token); ltpa.m_TokenName = config.getTokenName(); ltpa.m_Domain = config.getDomain(); return ltpa; }
From source file:org.trellisldp.file.FileUtils.java
/** * Get a directory for a given resource identifier. * @param baseDirectory the base directory * @param identifier a resource identifier * @return a directory//from ww w. j av a2 s. co m */ public static File getResourceDirectory(final File baseDirectory, final IRI identifier) { requireNonNull(baseDirectory, "The baseDirectory may not be null!"); requireNonNull(identifier, "The identifier may not be null!"); final String id = identifier.getIRIString(); final StringJoiner joiner = new StringJoiner(separator); final CRC32 hasher = new CRC32(); hasher.update(id.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(id)); return new File(baseDirectory, joiner.toString()); }
From source file:org.sinekartads.util.HexUtils.java
public static String randomHex(int length) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < length; i++) { buf.append(Long.toHexString((long) (Math.random() * 16))); }// w w w.ja v a 2 s. com return buf.toString(); }
From source file:org.okinawaopenlabs.ofpm.utils.OFPMUtils.java
/** * transfer macAddresslong//from w w w. j a v a 2 s. c o m * @param longMac long * @return macAddress transfered * @throws IllegalFormatException If a format string contains an illegal syntax * @throws NullPointerException longMac is null * @throws NumberFormatException if the String does not contain a parsable long */ public static String longToMacAddress(long longMac) throws IllegalFormatException, NullPointerException, NumberFormatException { if (longMac < MIN_MACADDRESS_VALUE || MAX_MACADDRESS_VALUE < longMac) { String errMsg = String.format(PARSE_ERROR, longMac); throw new NumberFormatException(errMsg); } String hex = "000000000000" + Long.toHexString(longMac); StringBuilder hexBuilder = new StringBuilder(hex.substring(hex.length() - 12)); for (int i = 2; i < 16; i = i + 3) { hexBuilder.insert(i, ":"); } return hexBuilder.toString(); }
From source file:com.servioticy.dispatcher.bolts.BenchmarkBolt.java
@Override public void execute(Tuple input) { String suDoc = input.getStringByField("su"); Long stopTS = input.getLongByField("stopts") == null ? System.currentTimeMillis() : input.getLongByField("stopts"); String reason = input.getStringByField("reason") == null ? "timeout" : input.getStringByField("reason"); SensorUpdate su;/*from w ww . j av a 2s .co m*/ try { su = this.mapper.readValue(suDoc, SensorUpdate.class); int chainSize = su.getPathTimestamps() == null ? 0 : su.getPathTimestamps().size(); String csvLine = Long.toHexString(su.getOriginId()) + "," + su.getLastUpdate() + "," + stopTS + "," + reason + "," + chainSize; for (int i = 0; i < chainSize; i++) { csvLine += ","; csvLine += su.getPathTimestamps().get(i) + ","; csvLine += su.getTriggerPath().get(i).get(0) + "," + su.getTriggerPath().get(i).get(1); } File file = new File(dc.benchResultsDir + "/" + context.getThisTaskId() + ".csv"); file.createNewFile(); FileWriter writer = new FileWriter(file, true); writer.append(csvLine + "\n"); writer.flush(); writer.close(); } catch (Exception e) { // TODO Log the error e.printStackTrace(); collector.ack(input); return; } collector.ack(input); }