List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:de.ks.flatadocdb.defaults.DefaultIdGenerator.java
public String getSha1Hash(Path repository, Path targetPath) {//for debugging and readability the string is used instead of the byte array. Also avoids possible programming errors using the byte array in equals/hashcode. String relative = getRelativePath(repository, targetPath); MessageDigest digest = sha1.get(); byte[] checksum = digest.digest(relative.getBytes(Charsets.UTF_16)); String hexString = Hex.encodeHexString(checksum); log.trace("Generated {} \"{}\" for {}", digest.getAlgorithm(), hexString, relative); return hexString; }
From source file:com.bitbreeds.webrtc.sctp.model.SCTPAttribute.java
@Override public String toString() { return "SCTPAttribute{" + "type=" + type + ", data=" + Hex.encodeHexString(data) + '}'; }
From source file:libepg.util.bytearray.ByteDataBlock.java
/** * @return ??????????16 */ @Override public String toString() { return Hex.encodeHexString(this.data); }
From source file:com.whizzosoftware.hobson.dsc.api.codec.DSCFrameEncoder.java
@Override protected void encode(ChannelHandlerContext ctx, DSCCommand cmd, ByteBuf out) throws Exception { String cmdStr = cmd.getCommandString(); if (cmdStr != null) { logger.trace("encode: {}", cmdStr); // calculate checksum char checksum = 0; for (int i = 0; i < cmdStr.length(); i++) { checksum += cmdStr.charAt(i); }//from w w w .j av a 2s . c o m checksum = (char) (checksum & 0xFF); // write data frame byte[] bytes = (cmdStr + Integer.toHexString((int) checksum).toUpperCase() + "\r\n").getBytes(); out.writeBytes(bytes); if (logger.isTraceEnabled()) { logger.trace("Wrote {} bytes: {}", bytes.length, Hex.encodeHexString(bytes)); } } else { logger.error("Attempt to send unknown command class: {}", cmd); } }
From source file:com.ait.tooling.server.core.security.SimpleKeyStringSigningProvider.java
private final String hmac(final String text) { try {//from w w w.j av a 2 s. c om final Mac hmac = Mac.getInstance(HMAC_ALGORITHM); hmac.init(m_secret); return Hex.encodeHexString(hmac.doFinal(text.getBytes(IHTTPConstants.CHARSET_UTF_8))); } catch (Exception e) { logger.error("hmac error", e); throw new IllegalArgumentException(e); } }
From source file:de.drop_converter.plugins.binary_convert.Data2Hex.java
@Override public boolean importData(TransferSupport support) throws ConverterException { try {//from ww w. j a v a2 s . co m if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> files = (List<File>) support.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); for (File file : files) { FileInputStream fis = null; OutputStream out = null; try { out = getOutputStream(file, ".hex"); fis = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int count = 0; while (-1 != (count = fis.read(buffer))) { if (count == bufferSize) { out.write(Hex.encodeHexString(buffer).getBytes("UTF-8")); } else { byte[] tmp = Arrays.copyOf(Hex.encodeHexString(buffer).getBytes("UTF-8"), count); out.write(tmp); } } } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(fis); } } return true; } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) { String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); OutputStream out = null; try { byte[] encode = Hex.encodeHexString(data.getBytes()).getBytes(); out = getOutputStream(null, ".hex"); out.write(encode); } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); } } } catch (Exception e) { throw new ConverterException(e); } return false; }
From source file:de.undercouch.gradle.tasks.download.VerifyTest.java
/** * Tests if the Verify task can verify a file using its MD5 checksum * @throws Exception if anything goes wrong *//*from w w w. ja v a 2 s . co m*/ @Test public void verifyMD5() throws Exception { Download t = makeProjectAndTask(); t.src(makeSrc(TEST_FILE_NAME)); File dst = folder.newFile(); t.dest(dst); Verify v = makeVerifyTask(t); v.algorithm("MD5"); MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(contents); String calculatedChecksum = Hex.encodeHexString(md5.digest()); v.checksum(calculatedChecksum); v.src(t.getDest()); t.execute(); v.execute(); // will throw if the checksum is not OK }
From source file:com.lightboxtechnologies.ingest.Uploader.java
public int run(String[] args) throws IOException { if (args.length != 1) { System.err.println("Usage: Uploader <dest path>"); System.err.println("Writes data to HDFS path from stdin"); return 2; }//from www .j ava 2 s. co m final String dst = args[0]; final Configuration conf = getConf(); final MessageDigest hasher = FsEntryUtils.getHashInstance("MD5"); final DigestInputStream hashedIn = new DigestInputStream(System.in, hasher); final FileSystem fs = FileSystem.get(conf); final Path path = new Path(dst); final FSDataOutputStream outFile = fs.create(path, true); IOUtils.copyLarge(hashedIn, outFile, new byte[1024 * 1024]); System.out.println(Hex.encodeHexString(hasher.digest())); return 0; }
From source file:com.basho.riak.presto.SplitTask.java
public String toString() { byte[] binary = term2binary(task); byte[] b = Base64.encodeBase64(binary); return Hex.encodeHexString(b); }
From source file:com.playonlinux.core.utils.ChecksumCalculator.java
public String calculate(File fileToCheck, String algorithm) throws IOException { final long fileSize = FileUtils.sizeOf(fileToCheck); try (final FileInputStream inputStream = new FileInputStream(fileToCheck)) { MessageDigest messageDigest; try {// w ww. ja v a 2 s .co m messageDigest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } byte[] digest = getDigest(inputStream, messageDigest, fileSize); return Hex.encodeHexString(digest); } }