List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:de.resol.vbus.HeaderTest.java
@Test public void testCalcAndSetChecksumV0() throws Exception { byte[] testBuffer1 = Hex.decodeHex("aa000021772000050000000000000000".toCharArray()); assertEquals(0x42, Header.calcAndSetChecksumV0(testBuffer1, 1, 14)); assertEquals(0x42, testBuffer1[15]); }
From source file:com.microsoft.sqlserver.jdbc.datatypes.SQLServerSpatialDatatypeTest.java
@Test public void testMultiPointWkb() throws DecoderException { String geoWKT = "MULTIPOINT((2 3), (7 8 9.5))"; byte[] geomWKB = Hex.decodeHex( "00000000010502000000000000000000004000000000000008400000000000001C400000000000002040000000000000F8FF0000000000002340020000000100000000010100000003000000FFFFFFFF0000000004000000000000000001000000000100000001" .toCharArray());//w w w . j a va 2 s . com byte[] geogWKB = Hex.decodeHex( "E61000000105020000000000000000000840000000000000004000000000000020400000000000001C40000000000000F8FF0000000000002340020000000100000000010100000003000000FFFFFFFF0000000004000000000000000001000000000100000001" .toCharArray()); Geometry geomWKT = Geometry.deserialize(geomWKB); Geography geogWKT = Geography.deserialize(geogWKB); assertEquals(geomWKT.asTextZM(), geoWKT); assertEquals(geogWKT.asTextZM(), geoWKT); }
From source file:de.resol.vbus.PacketTest.java
@Test public void testFromLiveBuffer() throws Exception { byte[] refBuffer1 = Hex.decodeHex( "00aa362335331034430d2a0004080c00671014181c00272024282c00673034383c00274044484c00675054585c00276064686c00677074787c00270004080c0f581014181c0f182024282c0f583034383c0f184044484c0f58" .toCharArray());// w w w . j av a2 s . c om int refStart1 = 1; long refTimestamp1 = System.currentTimeMillis(); int refChannel1 = 0x13; int refDestinationAddress1 = 0x2336; int refSourceAddress1 = 0x3335; int refCommand1 = 0x4334; int refFrameCount1 = 13; byte[] refData1 = Hex.decodeHex( "0004080c1014181c2024282c3034383c4044484c5054585c6064686c7074787c8084888c9094989ca0a4a8acb0b4b8bcc0c4c8cc" .toCharArray()); Packet testPacket1 = Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, refTimestamp1, refChannel1); assertEquals(refTimestamp1, testPacket1.timestamp); assertEquals(refChannel1, testPacket1.channel); assertEquals(refDestinationAddress1, testPacket1.destinationAddress); assertEquals(refSourceAddress1, testPacket1.sourceAddress); assertEquals(refCommand1, testPacket1.command); assertEquals(refFrameCount1, testPacket1.frameCount); assertArrayEquals(refData1, testPacket1.frameData); // fail on missing bytes in header assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, 9, 0, 0)); // fail on missing bytes in frames assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1 - 1, 0, 0)); // fail on missing sync byte in header refBuffer1[refStart1] = (byte) 0xBB; assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, 0, 0)); refBuffer1[refStart1] = (byte) 0xAA; // fail on MSB in frames refBuffer1[refBuffer1.length - 1] = (byte) 0x80; assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, 0, 0)); // fail on checksum error in frames refBuffer1[refBuffer1.length - 1] = (byte) 0x00; assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, 0, 0)); // fail on checksum error in header refBuffer1[refStart1 + 9]--; assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, 0, 0)); // fail on wrong protocol version in header refBuffer1[refStart1 + 5]++; assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, 0, 0)); // fail on MSB in header refBuffer1[refStart1 + 9] = (byte) 0x80; assertEquals(null, Packet.fromLiveBuffer(refBuffer1, refStart1, refBuffer1.length - refStart1, 0, 0)); }
From source file:com.vmware.o11n.plugin.crypto.service.CryptoEncodingService.java
/** * * @param hexData//from www . j a va 2 s.c o m * @return * @throws DecoderException */ public String hexToBase32(String hexData) throws DecoderException { //decode hex byte[] data = Hex.decodeHex(hexData.toCharArray()); //encode base32 Base32 b32 = new Base32(); return b32.encodeAsString(data); }
From source file:com.jkoolcloud.tnt4j.streams.utils.Utils.java
/** * Converts a string representing hexadecimal values into an array of bytes. * * @param str//from www. j a v a2s . c o m * String to convert * @return decoded byte sequence */ public static byte[] decodeHex(String str) { byte[] ba = null; try { if (str != null && str.startsWith(HEX_PREFIX)) { str = str.substring(HEX_PREFIX.length()); } ba = Hex.decodeHex((str == null ? "" : str).toCharArray()); } catch (DecoderException e) { } return ba; }
From source file:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java
public static byte[] AddandUpdateMDAC(byte[] vCData, short vcEntry, String appName) { String TAG = "VCDescriptionFile:AddandUpdateMDAC"; Log.i(TAG, "Enter"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] VC_EntryBytes = Utils.shortToByteArr(vcEntry); try {/*w w w. j ava 2 s .co m*/ out.write(createTlv(0x4F, Hex.decodeHex(appName.toCharArray()))); out.write(createTlv(0x40, VC_EntryBytes)); return (createTlv(0x72, Utils.append(out.toByteArray(), vCData))); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.knewton.mapreduce.SSTableColumnMapperTest.java
/** * Test the end time range filters in the mapper. * /*w ww . j av a 2s .co m*/ * @throws IOException * @throws InterruptedException * @throws DecoderException */ @Test public void testEndRangeStudentEvents() throws IOException, InterruptedException, DecoderException { // Mar.28.2013.19:53:38.0.0 DateTime dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC); long eventId1 = dt.getMillis(); // Mar.29.2013.03:07:21.0.0 dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC); long eventId5 = dt.getMillis(); ByteBuffer columnName = ByteBuffer.wrap(new byte[8]); columnName.putLong(eventId5); columnName.rewind(); IColumn column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray()))); Configuration conf = new Configuration(); conf.set(StudentEventAbstractMapper.END_DATE_PARAMETER_NAME, "2013-03-28T23:03:02.394-04:00"); DoNothingStudentEventMapper dnsem = new DoNothingStudentEventMapper(); Mapper<ByteBuffer, IColumn, LongWritable, StudentEventWritable>.Context context = dnsem.new Context(conf, new TaskAttemptID(), null, null, null, new DoNothingStatusReporter(), null); dnsem.setup(context); dnsem.map(RandomStudentEventGenerator.getRandomIdBuffer(), column, context); assertNull(dnsem.getRowKey()); ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer(); columnName = ByteBuffer.wrap(new byte[8]); columnName.putLong(eventId1); columnName.rewind(); column = new Column(columnName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray()))); dnsem.map(randomKey, column, context); assertEquals(dnsem.getRowKey(), randomKey); }
From source file:com.facebook.presto.accumulo.iterators.SingleColumnValueFilter.java
@Override public boolean validateOptions(Map<String, String> options) { checkNotNull(CF, options);/*from w ww. j av a2 s . c o m*/ checkNotNull(CQ, options); checkNotNull(COMPARE_OP, options); try { CompareOp.valueOf(options.get(COMPARE_OP)); } catch (RuntimeException e) { throw new IllegalArgumentException("Unknown value of " + COMPARE_OP + ":" + options.get(COMPARE_OP)); } checkNotNull(VALUE, options); try { new Value(Hex.decodeHex(options.get(VALUE).toCharArray())); } catch (DecoderException e) { throw new IllegalArgumentException( "Option " + VALUE + " is not a hex-encoded value: " + options.get(VALUE), e); } return true; }
From source file:io.warp10.quasar.trl.QuasarTokenRevocationListLoader.java
public void loadTrl() { try {/*from ww w. j a v a 2 s .co m*/ QuasarTRL quasarTRL = null; // // Sensision metrics thread heart beat // Sensision.event(QuasarTokenFilterSensisionConstants.SENSISION_CLASS_QUASAR_FILTER_TRL_COUNT, labels, 1); // // get all files in the directory // String[] files = getFolderFiles(path); // // extract the most recent files per warp.type // Map<String, JavaTRLLoaded> latest = latestFilesToRead(files); boolean update = updateTRL(read, latest); if (update) { long now = System.currentTimeMillis(); // sum files size int size = getSipHashesSize(latest.values()); // load the selected files for (Map.Entry<String, JavaTRLLoaded> entry : latest.entrySet()) { if (null == quasarTRL) { quasarTRL = new QuasarTRL(size); } // // Read the token revocation list // BufferedReader br = null; try { br = new BufferedReader(new FileReader(new File(path, entry.getValue().fileName))); while (true) { String line = br.readLine(); if (null == line) { break; } line = line.trim(); // application if (line.startsWith(QuasarConfiguration.WARP_APPLICATION_PREFIX)) { // compute the sip hash with the app name long appSipHash = getApplicationHash(line.substring(1)); quasarTRL.revokeApplication(appSipHash); } else { // token sip hash hex encoded convert it into long byte[] bytes = Hex.decodeHex(line.toCharArray()); long tokenRevoked = ByteBuffer.wrap(bytes, 0, 8).order(ByteOrder.BIG_ENDIAN) .getLong(); // add it to the future trl list quasarTRL.revokeToken(tokenRevoked); } } // mark as readed read.put(entry.getKey(), entry.getValue()); } catch (Exception exp) { exp.printStackTrace(); } finally { if (null != br) { try { br.close(); } catch (IOException e) { } } } } // end for all files if (0 != quasarTRLLoadedHandler.size() && null != quasarTRL) { // // sort and switch the new trl // quasarTRL.sortTokens(); // // call all the handlers // for (QuasarTRLLoadedHandler handler : quasarTRLLoadedHandler) { handler.onQuasarTRL(quasarTRL); } currentTrl = quasarTRL; // // Sensision trl loaded // long timeElapsed = System.currentTimeMillis() - now; Sensision.event(QuasarTokenFilterSensisionConstants.SENSISION_CLASS_QUASAR_FILTER_TRL_LOAD_TIME, labels, timeElapsed); Sensision.event( QuasarTokenFilterSensisionConstants.SENSISION_CLASS_QUASAR_FILTER_TRL_TOKENS_COUNT, labels, quasarTRL.getTrlSize()); } } // end if update } catch (Exception exp) { // thread error Sensision.update(QuasarTokenFilterSensisionConstants.SENSISION_CLASS_QUASAR_FILTER_TRL_ERROR_COUNT, labels, 1); } }
From source file:libepg.epg.section.sdt.ServiceDescriptionTableRepeatingPartTest.java
/** * Test of getDescriptors_loop method, of class * ServiceDescriptionTableRepeatingPart. *///from w ww . j a v a 2 s .c o m @Test public void testGetDescriptors_loop() throws DecoderException, Throwable { LOG.debug("getDescriptors_loop"); ServiceDescriptionTableRepeatingPart instance = ClassGetter.init(this.x); DescriptorsLoop expResult = new DescriptorsLoop( Hex.decodeHex("481201000f0e4e484b451d461d6c310f456c357ec10184cf0701fe08f0010408".toCharArray())); DescriptorsLoop result = instance.getDescriptors_loop(); assertEquals(expResult, result); }