List of usage examples for org.apache.commons.codec.binary Hex decodeHex
public static byte[] decodeHex(char[] data) throws IllegalArgumentException
From source file:libepg.common.packet.TestPacket_SDT.java
public TestPacket_SDT() throws DecoderException { target100 = new TsPacket(Hex.decodeHex(p100)); target101 = new TsPacket(Hex.decodeHex(p101)); target102 = new TsPacket(Hex.decodeHex(p102)); target103 = new TsPacket(Hex.decodeHex(p103)); target104 = new TsPacket(Hex.decodeHex(p104)); target105 = new TsPacket(Hex.decodeHex(p105)); target106 = new TsPacket(Hex.decodeHex(p106)); target107 = new TsPacket(Hex.decodeHex(p107)); target108 = new TsPacket(Hex.decodeHex(p108)); target109 = new TsPacket(Hex.decodeHex(p109)); target110 = new TsPacket(Hex.decodeHex(p110)); target111 = new TsPacket(Hex.decodeHex(p111)); target112 = new TsPacket(Hex.decodeHex(p112)); target113 = new TsPacket(Hex.decodeHex(p113)); target114 = new TsPacket(Hex.decodeHex(p114)); target115 = new TsPacket(Hex.decodeHex(p115)); target200 = new TsPacket(Hex.decodeHex(p200)); target201 = new TsPacket(Hex.decodeHex(p201)); target202 = new TsPacket(Hex.decodeHex(p202)); target203 = new TsPacket(Hex.decodeHex(p203)); target204 = new TsPacket(Hex.decodeHex(p204)); target205 = new TsPacket(Hex.decodeHex(p205)); target206 = new TsPacket(Hex.decodeHex(p206)); target207 = new TsPacket(Hex.decodeHex(p207)); target208 = new TsPacket(Hex.decodeHex(p208)); target209 = new TsPacket(Hex.decodeHex(p209)); target210 = new TsPacket(Hex.decodeHex(p210)); target211 = new TsPacket(Hex.decodeHex(p211)); target212 = new TsPacket(Hex.decodeHex(p212)); target213 = new TsPacket(Hex.decodeHex(p213)); target214 = new TsPacket(Hex.decodeHex(p214)); target215 = new TsPacket(Hex.decodeHex(p215)); }
From source file:com.ning.arecibo.util.timeline.times.TestTimelineCoder.java
@Test(groups = "fast") public void testTimeCursorThatShowedError() throws Exception { // 39 bytes are: ff4f90f67afd03ce1e1ffe1a1e1d01fe771e1d01fd01df1e1d1ffe761e1d01fe771e1d01fe571e // 1944 samples; error at 1934 final int sampleCount = 1944; //final byte[] times = Hex.decodeHex("ff4f90f67afd03ce1e1ffe1a1e1d01fe771e1d01fd01df1e1d1ffe761e1d01fe771e1d01fe571e".toCharArray()); final byte[] times = Hex .decodeHex("00000018FF4F8FE521FD023D1E1FFEF01E1D01FE771E1D01FD03E21EFE07980F".toCharArray()); Assert.assertEquals(times.length, 32); final TimelineCursorImpl cursor = new TimelineCursorImpl(times, sampleCount); for (int i = 0; i < sampleCount; i++) { final DateTime nextTime = cursor.getNextTime(); Assert.assertNotNull(nextTime);/*from ww w.jav a2 s . c o m*/ cursor.skipToSampleNumber(i + 1); } try { final DateTime lastTime = cursor.getNextTime(); Assert.assertTrue(false); } catch (Exception e) { } }
From source file:libepg.common.packet.TestPacket_pid0x11_count_d_0_0.java
public TestPacket_pid0x11_count_d_0_0() throws DecoderException { target_p0d = new TsPacket(Hex.decodeHex(p0d)); target_p0e = new TsPacket(Hex.decodeHex(p0e)); target_p0f = new TsPacket(Hex.decodeHex(p0f)); target_p10 = new TsPacket(Hex.decodeHex(p10)); target_p11 = new TsPacket(Hex.decodeHex(p11)); target_p12 = new TsPacket(Hex.decodeHex(p12)); target_p13 = new TsPacket(Hex.decodeHex(p13)); target_p14 = new TsPacket(Hex.decodeHex(p14)); target_p15 = new TsPacket(Hex.decodeHex(p15)); target_p16 = new TsPacket(Hex.decodeHex(p16)); target_p17 = new TsPacket(Hex.decodeHex(p17)); target_p18 = new TsPacket(Hex.decodeHex(p18)); target_p19 = new TsPacket(Hex.decodeHex(p19)); target_p1a = new TsPacket(Hex.decodeHex(p1a)); target_p1b = new TsPacket(Hex.decodeHex(p1b)); target_p1c = new TsPacket(Hex.decodeHex(p1c)); target_p1d = new TsPacket(Hex.decodeHex(p1d)); target_p1e = new TsPacket(Hex.decodeHex(p1e)); target_p1f = new TsPacket(Hex.decodeHex(p1f)); target_p20 = new TsPacket(Hex.decodeHex(p20)); target_p21 = new TsPacket(Hex.decodeHex(p21)); target_p22 = new TsPacket(Hex.decodeHex(p22)); target_p23 = new TsPacket(Hex.decodeHex(p23)); target_p24 = new TsPacket(Hex.decodeHex(p24)); target_p25 = new TsPacket(Hex.decodeHex(p25)); target_p26 = new TsPacket(Hex.decodeHex(p26)); target_p27 = new TsPacket(Hex.decodeHex(p27)); target_p28 = new TsPacket(Hex.decodeHex(p28)); target_p29 = new TsPacket(Hex.decodeHex(p29)); target_p2a = new TsPacket(Hex.decodeHex(p2a)); target_p3b = new TsPacket(Hex.decodeHex(p3b)); target_p3c = new TsPacket(Hex.decodeHex(p3c)); target_p3d = new TsPacket(Hex.decodeHex(p3d)); target_p3e = new TsPacket(Hex.decodeHex(p3e)); target_p3f = new TsPacket(Hex.decodeHex(p3f)); }
From source file:joliex.mongodb.MongoDbConnector.java
@RequestResponse public Value insertMany(Value request) throws FaultException { Value v = Value.create();/* w ww.j a v a 2 s . c o m*/ String collectionName = request.getFirstChild("collection").strValue(); List<BsonDocument> documents = new ArrayList(); BsonDocument bsonDocument; try { for (int counterDocuments = 0; counterDocuments < request.getChildren("document") .size(); counterDocuments++) { bsonDocument = createDocument(request.getChildren("document").get(counterDocuments)); documents.add(bsonDocument); } if (request.hasChildren("writeConcern")) { WriteConcern writeConcern = new WriteConcern(); if (request.getFirstChild("writeConcern").hasChildren("journal")) { writeConcern.withJournal( request.getFirstChild("writeConcern").getFirstChild("journal").boolValue()); } if (request.getFirstChild("writeConcern").hasChildren("w")) { if (request.getFirstChild("writeConcern").getFirstChild("w").isInt()) { writeConcern.withW(request.getFirstChild("writeConcern").getFirstChild("w").intValue()); } if (request.getFirstChild("writeConcern").getFirstChild("w").isString()) { writeConcern.withW(request.getFirstChild("writeConcern").getFirstChild("w").strValue()); } } if (request.getFirstChild("writeConcern").hasChildren("timeout")) { writeConcern.withWTimeout( request.getFirstChild("writeConcern").getFirstChild("timeout").longValue(), TimeUnit.MILLISECONDS); } db.getCollection(collectionName, BsonDocument.class).withWriteConcern(writeConcern); } if (request.hasChildren("options")) { InsertManyOptions insertManyOptions = new InsertManyOptions(); insertManyOptions.ordered(request.getFirstChild("options").getFirstChild("ordered").boolValue()); insertManyOptions.ordered(request.getFirstChild("options").getFirstChild("ordered").boolValue()); insertManyOptions.bypassDocumentValidation( request.getFirstChild("options").getFirstChild("bypassDocumentValidation").boolValue()); db.getCollection(collectionName, BsonDocument.class).insertMany(documents, insertManyOptions); } else { db.getCollection(collectionName, BsonDocument.class).insertMany(documents); } ; db.getCollection(collectionName, BsonDocument.class).insertMany(documents); for (int counterDocuments = 0; counterDocuments < request.getChildren("document") .size(); counterDocuments++) { String str = new String(Hex.decodeHex(documents.get(counterDocuments).get("_id").asObjectId() .getValue().toHexString().toCharArray()), StandardCharsets.UTF_8); Value result = Value.create(); result.getNewChild("_id").assignValue(Value.create(str)); result.getFirstChild("_id").getNewChild("@type").assignValue(Value.create("ObjectID")); v.getChildren("results").add(result); } } catch (MongoException ex) { throw new FaultException("MongoException", ex); } catch (DecoderException ex) { Logger.getLogger(MongoDbConnector.class.getName()).log(Level.SEVERE, null, ex); } return v; }
From source file:net.padlocksoftware.padlock.validator.Validator.java
private PublicKey convertPublicKey(String publicKey, boolean isRSA) { PublicKey pub = null;// w w w. ja va 2 s . c om try { byte[] pubKey = Hex.decodeHex(publicKey.toCharArray()); X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(pubKey); KeyFactory keyFactory = KeyFactory.getInstance(isRSA ? "RSA" : "DSA"); if (isRSA) { pub = (RSAPublicKey) keyFactory.generatePublic(pubSpec); } else { pub = (DSAPublicKey) keyFactory.generatePublic(pubSpec); } } catch (InvalidKeySpecException ex) { logger.log(Level.FINE, null, ex); } catch (NoSuchAlgorithmException ex) { logger.log(Level.FINE, null, ex); } catch (DecoderException ex) { logger.log(Level.FINE, null, ex); } catch (ClassCastException ex) { logger.log(Level.FINE, null, ex); } return pub; }
From source file:com.silverpeas.util.StringUtil.java
/** * Decodes the specified text with hexadecimal values in bytes of those same values. The text is * considered to be in the UTF-8 charset. *//from w w w. j ava2s .com * @param hexText the text with hexadecimal-based characters. * @return the binary representation of the text. * @throws ParseException if an odd number or illegal of characters is supplied. */ public static byte[] fromHex(String hexText) throws ParseException { try { return Hex.decodeHex(hexText.toCharArray()); } catch (DecoderException ex) { throw new ParseException(ex.getMessage(), -1); } }
From source file:com.github.nlloyd.hornofmongo.MongoScope.java
private static final String hexToBase64(final String hex) { String base64 = null;/* ww w . ja v a 2 s . c o m*/ try { base64 = Base64.encodeBase64String(Hex.decodeHex(hex.toCharArray())); } catch (DecoderException e) { Context.throwAsScriptRuntimeEx(e); } return base64; }
From source file:com.microsoft.sqlserver.jdbc.datatypes.SQLServerSpatialDatatypeTest.java
@Test public void testCircularStringWkb() throws DecoderException { String geoWKT = "CIRCULARSTRING(2 1 3 4, 1 2 3, 0 7 3, 1 0 3, 2 1 3)"; byte[] geomWKB = Hex.decodeHex( "000000000207050000000000000000000040000000000000F03F000000000000F03F000000000000004000000000000000000000000000001C40000000000000F03F00000000000000000000000000000040000000000000F03F000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000001040000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF01000000020000000001000000FFFFFFFF0000000008" .toCharArray());//from w ww .j a va2 s . c om byte[] geogWKB = Hex.decodeHex( "E6100000020705000000000000000000F03F00000000000000400000000000000040000000000000F03F0000000000001C4000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000040000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000001040000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF01000000020000000001000000FFFFFFFF0000000008" .toCharArray()); Geometry geomWKT = Geometry.deserialize(geomWKB); Geography geogWKT = Geography.deserialize(geogWKB); assertEquals(geomWKT.asTextZM(), geoWKT); assertEquals(geogWKT.asTextZM(), geoWKT); }
From source file:com.ning.arecibo.util.timeline.times.TestTimelineCoder.java
private void checkCombinedTimelines(final String... timelines) throws Exception { final List<byte[]> timeParts = new ArrayList<byte[]>(); for (String timeline : timelines) { timeParts.add(Hex.decodeHex(timeline.toCharArray())); }//from w w w. ja va 2 s. c om int sampleCount = 0; int byteCount = 0; for (byte[] timePart : timeParts) { byteCount += timePart.length; sampleCount += timelineCoder.countTimeBytesSamples(timePart); } final byte[] concatedTimes = new byte[byteCount]; int offset = 0; for (byte[] timePart : timeParts) { final int length = timePart.length; System.arraycopy(timePart, 0, concatedTimes, offset, length); offset += length; } final byte[] newCombined = timelineCoder.combineTimelines(timeParts, null); final int newCombinedLength = timelineCoder.countTimeBytesSamples(newCombined); final TimelineCursorImpl concatedCursor = new TimelineCursorImpl(concatedTimes, sampleCount); final TimelineCursorImpl combinedCursor = new TimelineCursorImpl(newCombined, sampleCount); int counter = 0; for (int i = 0; i < sampleCount; i++) { final DateTime concatedTime = concatedCursor.getNextTime(); final DateTime combinedTime = combinedCursor.getNextTime(); Assert.assertEquals(combinedTime, concatedTime); counter++; } Assert.assertEquals(newCombinedLength, sampleCount); }
From source file:com.microsoft.sqlserver.jdbc.datatypes.SQLServerSpatialDatatypeTest.java
@Test public void testCompoundCurveWkb() throws DecoderException { String geoWKT = "COMPOUNDCURVE(CIRCULARSTRING(1 0 3, 0 1 3, 9 6 3, 8 7 3, -1 0 3), CIRCULARSTRING(-1 0 3, 7 9 3, -10 2 3), (-10 2 3, 77 77 77, 88 88 88, 2 6 4), (2 6 4, 3 3 6, 7 7 1))"; byte[] geomWKB = Hex.decodeHex( "0000000002050C000000000000000000F03F00000000000000000000000000000000000000000000F03F0000000000002240000000000000184000000000000020400000000000001C40000000000000F0BF00000000000000000000000000001C40000000000000224000000000000024C00000000000000040000000000040534000000000004053400000000000005640000000000000564000000000000000400000000000001840000000000000084000000000000008400000000000001C400000000000001C4000000000000008400000000000000840000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000405340000000000000564000000000000010400000000000001840000000000000F03F01000000030000000001000000FFFFFFFF0000000009080000000301030200000200" .toCharArray());//from ww w. j av a 2s. co m byte[] geogWKB = Hex.decodeHex( "E610000002050C0000000000000000000000000000000000F03F000000000000F03F0000000000000000000000000000184000000000000022400000000000001C4000000000000020400000000000000000000000000000F0BF00000000000022400000000000001C40000000000000004000000000000024C0000000000040534000000000004053400000000000005640000000000000564000000000000018400000000000000040000000000000084000000000000008400000000000001C400000000000001C4000000000000008400000000000000840000000000000084000000000000008400000000000000840000000000000084000000000000008400000000000405340000000000000564000000000000010400000000000001840000000000000F03F01000000030000000001000000FFFFFFFF0000000009080000000301030200000200" .toCharArray()); Geometry geomWKT = Geometry.deserialize(geomWKB); Geography geogWKT = Geography.deserialize(geogWKB); assertEquals(geomWKT.asTextZM(), geoWKT); assertEquals(geogWKT.asTextZM(), geoWKT); }