List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:com.lightboxtechnologies.nsrl.HashRecordProcessorTest.java
@Test(expected = BadDataException.class) public void processNonnumericProdCode() throws BadDataException { final RecordProcessor<HashData> proc = new HashRecordProcessor(); proc.process(new String[] { Hex.encodeHexString(sha1), Hex.encodeHexString(md5), Hex.encodeHexString(crc32), name, String.valueOf(size), "foo", os_code, special_code }); }
From source file:com.github.breadmoirai.samurai.plugins.groovyval.GroovyvalPlugin.java
public String runScript(String script) throws Exception { final Object result = groovyShell.evaluate(script); if (result != null) { if (result instanceof byte[]) { if (((byte[]) result).length == 0) { return "Empty byte array"; }//from w w w . j av a 2 s.co m return Hex.encodeHexString((byte[]) result); } else if (result instanceof int[]) { return Arrays.toString(((int[]) result)); } else if (result instanceof double[]) { return Arrays.toString(((double[]) result)); } else if (result instanceof Object[]) { return Arrays.toString(((Object[]) result)); } return result.toString(); } else return "null"; }
From source file:libepg.epg.section.Section.java
/** * ??????ID????+3?????????????/*from w ww . j a v a 2 s . c o m*/ * * @param data ? * @throws IllegalArgumentException * 1:???????ID????3???????<br> * 2:?2?0?????<br> * 3:???????preferedTableID???????????<br> */ public Section(byte[] data) throws IllegalArgumentException { byte[] temp = Arrays.copyOf(data, data.length); final int id = ByteConverter.byteToInt(temp[0]); tableId = TABLE_ID.reverseLookUp(id); String hexValue = Hex.encodeHexString(data); //ID??ID????????????ID?????????????(?????ID???????????) if (tableId == null) { MessageFormat msg2 = new MessageFormat( "????? ???={0}"); Object[] parameters2 = { hexValue }; LOG.trace(msg2.format(parameters2)); throw new IllegalArgumentException(msg2.format(parameters2)); } byte[] t = new byte[2]; System.arraycopy(temp, 1, t, 0, t.length); int sectionLength = ByteConverter.bytesToInt(t); if (LOG.isTraceEnabled()) { LOG.trace("b1 = " + Integer.toHexString(sectionLength)); } sectionLength = sectionLength & 0x0FFF; if (LOG.isTraceEnabled()) { LOG.trace("b2 = " + Integer.toHexString(sectionLength)); } //??????? if (sectionLength > tableId.getMaxSectionLength().getMaxSectionBodyLength()) { MessageFormat msg3 = new MessageFormat( "?????????={0} ?={1} ???={2}"); Object[] parameters3 = { tableId.getMaxSectionLength().getMaxSectionBodyLength(), sectionLength, hexValue }; LOG.trace(msg3.format(parameters3)); throw new IllegalArgumentException(msg3.format(parameters3)); } //??????????? int targetLength = sectionLength + 3; byte[] sectionByteArray = new byte[targetLength]; System.arraycopy(temp, 0, sectionByteArray, 0, sectionByteArray.length); if (LOG.isTraceEnabled()) { MessageFormat msg1 = new MessageFormat("\n??={0}\n?={1}"); Object[] parameters1 = { Hex.encodeHexString(temp), Hex.encodeHexString(sectionByteArray) }; LOG.trace(msg1.format(parameters1)); } this.data = new ByteDataBlock(sectionByteArray); }
From source file:com.mycompany.monroelabsm.B58.java
public static String bytesToHex(byte[] b) { return Hex.encodeHexString(b); }
From source file:de.resol.vbus.PacketTest.java
@Test public void testToLiveBuffer() throws Exception { String refValue1 = "aa362335331034430d2a0004080c00671014181c00272024282c00673034383c00274044484c00675054585c00276064686c00677074787c00270004080c0f581014181c0f182024282c0f583034383c0f184044484c0f58"; byte[] testData1 = new byte[13 * 4]; for (int i = 0; i < testData1.length; i++) { testData1[i] = (byte) (i * 4); }/*from ww w. ja va 2s. c om*/ Packet testPacket1 = new Packet(0, 0, 0x2336, 0x3335, 0x4334, 13, testData1); byte[] testBuffer1 = testPacket1.toLiveBuffer(null, 0, 0); assertEquals(refValue1, Hex.encodeHexString(testBuffer1)); byte[] testBuffer2 = new byte[testBuffer1.length + 2]; assertEquals(testBuffer2, testPacket1.toLiveBuffer(testBuffer2, 1, testBuffer2.length - 1)); assertEquals("00" + refValue1 + "00", Hex.encodeHexString(testBuffer2)); assertEquals(null, testPacket1.toLiveBuffer(testBuffer2, 3, testBuffer2.length - 3)); }
From source file:com.consol.citrus.ws.actions.SendSoapMessageAction.java
@Override protected SoapMessage createMessage(TestContext context, String messageType) { Message message = super.createMessage(context, getMessageType()); SoapMessage soapMessage = new SoapMessage(message).mtomEnabled(mtomEnabled); try {/* w w w.j a va2s. c o m*/ for (SoapAttachment attachment : attachments) { attachment.resolveDynamicContent(context); if (mtomEnabled) { String messagePayload = soapMessage.getPayload(String.class); String cid = CID_MARKER + attachment.getContentId(); if (attachment.isMtomInline() && messagePayload.contains(cid)) { byte[] attachmentBinaryData = FileUtils .readToString(attachment.getInputStream(), Charset.forName(attachment.getCharsetName())) .getBytes(Charset.forName(attachment.getCharsetName())); if (attachment.getEncodingType().equals(SoapAttachment.ENCODING_BASE64_BINARY)) { log.info("Adding inline base64Binary data for attachment: %s", cid); messagePayload = messagePayload.replaceAll(cid, Base64.encodeBase64String(attachmentBinaryData)); } else if (attachment.getEncodingType().equals(SoapAttachment.ENCODING_HEX_BINARY)) { log.info("Adding inline hexBinary data for attachment: %s", cid); messagePayload = messagePayload.replaceAll(cid, Hex.encodeHexString(attachmentBinaryData).toUpperCase()); } else { throw new CitrusRuntimeException(String.format( "Unsupported encoding type '%s' for SOAP attachment: %s - choose one of %s or %s", attachment.getEncodingType(), cid, SoapAttachment.ENCODING_BASE64_BINARY, SoapAttachment.ENCODING_HEX_BINARY)); } } else { messagePayload = messagePayload.replaceAll(cid, String.format( "<xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\" href=\"%s\"/>", cid)); soapMessage.addAttachment(attachment); } soapMessage.setPayload(messagePayload); } else { soapMessage.addAttachment(attachment); } } } catch (IOException e) { throw new CitrusRuntimeException(e); } return soapMessage; }
From source file:com.thoughtworks.go.domain.AccessToken.java
private static String generateSecureRandomString(int byteLength) { byte[] randomBytes = new byte[byteLength]; SECURE_RANDOM.nextBytes(randomBytes); return Hex.encodeHexString(randomBytes); }
From source file:libepg.epg.util.datetime.DateTimeFieldConverter.java
private static Map<HMS_KEY, Integer> BcdTimeToMap(byte[] hms) throws ParseException { Map<HMS_KEY, Integer> ret = new HashMap<>(); if (hms.length != 3) { throw new IndexOutOfBoundsException( "?????3????????" + " ?=" + Hex.encodeHexString(hms)); }/* www . j a v a 2 s. c o m*/ //ARIB???????????????? if (Arrays.equals(hms, UNDEFINED_BCD_TIME_BLOCK.getData())) { throw new ParseException("???????????" + " ?=" + Hex.encodeHexString(hms), 0); } Object[] parameters = null; final int hour = new BCD(hms[0]).getDecimal(); final int minute = new BCD(hms[1]).getDecimal(); final int second = new BCD(hms[2]).getDecimal(); CHECK: { final Range<Integer> HOUR_RANGE = Range.between(0, 23); if (!HOUR_RANGE.contains(hour)) { parameters = new Object[] { Hex.encodeHexString(hms), "", hour }; break CHECK; } final Range<Integer> MINUTE_AND_SECOND_RANGE = Range.between(0, 59); if (!MINUTE_AND_SECOND_RANGE.contains(minute)) { parameters = new Object[] { Hex.encodeHexString(hms), "", minute }; break CHECK; } if (!MINUTE_AND_SECOND_RANGE.contains(second)) { parameters = new Object[] { Hex.encodeHexString(hms), "", second }; break CHECK; } } if (parameters != null) { MessageFormat msg = new MessageFormat( "????????????={0} ={1} ={2}"); throw new ParseException(msg.format(parameters), 0); } if (LOG.isTraceEnabled()) { LOG.trace("hour=" + hour + " minute=" + minute + " second=" + second); } ret.put(HMS_KEY.HOUR, hour); ret.put(HMS_KEY.MINUTE, minute); ret.put(HMS_KEY.SECOND, second); return ret; }
From source file:com.bitbreeds.webrtc.signaling.PeerConnection.java
/** * @return A local user with randomly generated username and password. *///from w w w . j ava 2 s .c o m private UserData createLocalUser() { String myUser = Hex.encodeHexString(SignalUtil.randomBytes(4)); String myPass = Hex.encodeHexString(SignalUtil.randomBytes(16)); return new UserData(myUser, myPass); }
From source file:com.jejking.hh.nord.corpus.FetchedDruckSachenProcessor.java
public void preProcessFetchedDocuments(final File inputDirectory, final File outputDirectory, ImmutableMap<URL, Optional<LocalDate>> urlDateMap) { Observable.from(inputDirectory.list()).map(new Func1<String, File>() { @Override//from www . j av a 2s.c o m public File call(String fileName) { return new File(inputDirectory.getPath() + File.separator + fileName); } }).map(new AllrisHtmlToRawDrucksache(urlDateMap)).observeOn(Schedulers.io()) .subscribe(new Action1<Optional<RawDrucksache>>() { @Override public void call(Optional<RawDrucksache> rawDrucksache) { if (rawDrucksache.isPresent()) { File destination = new File(outputDirectory + File.separator + Hex.encodeHexString( rawDrucksache.get().getDrucksachenId().getBytes(Charsets.UTF_8)) + ".dat"); if (!destination.exists()) { try (ObjectOutputStream oos = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream(destination)))) { oos.writeObject(rawDrucksache.get()); counter.addAndGet(1); } catch (Exception e) { e.printStackTrace(); } } else { System.err.println( "Duplicate drucksachen-id: " + rawDrucksache.get().getDrucksachenId()); } } } }); System.out.println("Written " + counter.get() + " data sets"); }