List of usage examples for javax.xml.bind DatatypeConverter printHexBinary
public static String printHexBinary(byte[] val)
Converts an array of bytes into a string.
From source file:gov.ca.cwds.rest.util.jni.CmsPKCompressor.java
public String compressBase64ToHex(String base64) throws IOException { return DatatypeConverter.printHexBinary(compressBytes(DatatypeConverter.parseBase64Binary(base64))) .toLowerCase();// ww w. ja va2s . c o m }
From source file:io.confluent.connect.jdbc.EmbeddedDerby.java
private static String formatLiteral(Object value) throws SQLException { if (value == null) { return "NULL"; } else if (value instanceof CharSequence) { return "'" + value + "'"; } else if (value instanceof Blob) { Blob blob = ((Blob) value); byte[] blobData = blob.getBytes(1, (int) blob.length()); return "CAST(X'" + DatatypeConverter.printHexBinary(blobData) + "' AS BLOB)"; } else if (value instanceof byte[]) { return "X'" + DatatypeConverter.printHexBinary((byte[]) value) + "'"; } else {/* w w w. j a v a 2s . c o m*/ return value.toString(); } }
From source file:com.shuffle.bitcoin.blockchain.Btcd.java
@Override protected boolean send(Bitcoin.Transaction t) throws ExecutionException, InterruptedException, CoinNetworkException { if (!t.canSend || t.sent) { return false; }/*from w ww . ja v a2 s. c om*/ String hexTx = null; try { hexTx = DatatypeConverter.printHexBinary(t.bitcoinj().bitcoinSerialize()); } catch (BlockStoreException e) { return false; } catch (IOException er) { return false; } String requestBody = "{\"jsonrpc\":\"2.0\",\"id\":\"null\",\"method\":\"sendrawtransaction\", \"params\":[\"" + hexTx + "\"]}"; HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(); } catch (IOException e) { return false; } connection.setDoOutput(true); try { connection.setRequestMethod("POST"); } catch (java.net.ProtocolException e) { return false; } connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Accept", "application/json"); Base64 b = new Base64(); String authString = rpcuser + ":" + rpcpass; String encoding = b.encodeAsString(authString.getBytes()); connection.setRequestProperty("Authorization", "Basic " + encoding); connection.setRequestProperty("Content-Length", Integer.toString(requestBody.getBytes().length)); connection.setDoInput(true); OutputStream out; try { out = connection.getOutputStream(); } catch (IOException e) { return false; } try { out.write(requestBody.getBytes()); } catch (IOException e) { return false; } try { if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) return false; } catch (IOException e) { return false; } InputStream is; try { is = connection.getInputStream(); } catch (IOException e) { return false; } BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while (true) { try { if ((line = rd.readLine()) == null) break; } catch (IOException e) { return false; } response.append(line); response.append('\r'); } try { rd.close(); } catch (IOException e) { return false; } JSONObject json = new JSONObject(response.toString()); if (json.isNull("result")) { JSONObject errorObj = json.getJSONObject("error"); String errorMsg = errorObj.getString("message"); String parsed = errorMsg.substring(0, 37); // transaction is already in mempool, return true if (parsed.equals("TX rejected: already have transaction")) { return true; } throw new CoinNetworkException(errorMsg); } return true; }
From source file:com.microsoftopentechnologies.windowsazurestorage.WAStorageClient.java
/** * * @param listener// w w w . j a v a 2s . c o m * @param blob * @param src * @throws StorageException * @throws IOException * @throws InterruptedException * @returns Md5 hash of the uploaded file in hexadecimal encoding */ protected static String upload(TaskListener listener, CloudBlockBlob blob, FilePath src) throws StorageException, IOException, InterruptedException { MessageDigest md = DigestUtils.getMd5Digest(); long startTime = System.currentTimeMillis(); try (InputStream inputStream = src.read(); DigestInputStream digestInputStream = new DigestInputStream(inputStream, md)) { blob.upload(digestInputStream, src.length(), null, getBlobRequestOptions(), Utils.updateUserAgent()); } long endTime = System.currentTimeMillis(); listener.getLogger() .println("Uploaded blob with uri " + blob.getUri() + " in " + getTime(endTime - startTime)); return DatatypeConverter.printHexBinary(md.digest()); }
From source file:biz.astute.test.simulator.rest.RequestContext.java
/** * Compute hash if first character is {@link #HASH_IDENTIFIER}. * @param value value/* ww w . ja v a2 s .co m*/ * @return non-null and hashed if needed * @throws UnsupportedEncodingException encoding exception * @throws NoSuchAlgorithmException algorithm exception */ private String hashIt(final String value) throws UnsupportedEncodingException, NoSuchAlgorithmException { final MessageDigest md = getDigest(); md.update(value.substring(1).getBytes(CharEncoding.UTF_8)); return DatatypeConverter.printHexBinary(md.digest()); }
From source file:net.bluehornreader.model.ReadArticlesColl.java
@Override public String toString() { String bmp = bitmap == null ? "<NULL>" : DatatypeConverter.printHexBinary(bitmap); return "ReadArticlesColl{" + "userId='" + userId + '\'' + ", feedId='" + feedId + '\'' + ", first=" + first + ", bitmap=" + bmp + '}'; }
From source file:com.marklogic.client.test.EvalTest.java
private void runAndTestXQuery(ServerEvaluationCall call) throws JsonProcessingException, IOException, SAXException, ParserConfigurationException, DatatypeConfigurationException { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(this.getClass().getClassLoader().getResourceAsStream("1-empty-1.0.xml")); call = call.addNamespace("myPrefix", "http://marklogic.com/test").addVariable("myPrefix:myString", "Mars") .addVariable("myArray", new JacksonHandle().with(new ObjectMapper().createArrayNode().add("item1").add("item2"))) .addVariable("myObject", new JacksonHandle().with(new ObjectMapper().createObjectNode().put("item1", "value1"))) .addVariable("myAnyUri", "http://marklogic.com/a") .addVariable("myBinary", DatatypeConverter.printHexBinary(",".getBytes())) .addVariable("myBase64Binary", DatatypeConverter.printBase64Binary(new byte[] { 1, 2, 3 })) .addVariable("myHexBinary", DatatypeConverter.printHexBinary(new byte[] { 1, 2, 3 })) .addVariable("myDuration", "P100D").addVariable("myDocument", new DOMHandle(document)) .addVariable("myQName", "myPrefix:a") //.addVariable("myAttribute", "<a a=\"a\"/>") .addVariable("myComment", "<!--a-->").addVariable("myElement", "<a a=\"a\"/>") .addVariable("myProcessingInstruction", "<?a?>") .addVariable("myText", new StringHandle("a").withFormat(Format.TEXT)) // the next three use built-in methods of ServerEvaluationCall .addVariable("myBool", true).addVariable("myInteger", 1234567890123456789l) .addVariable("myBigInteger", "123456789012345678901234567890") .addVariable("myDecimal", "1111111111111111111.9999999999") .addVariable("myDouble", 11111111111111111111.7777777777).addVariable("myFloat", 1.1) .addVariable("myGDay", "---01").addVariable("myGMonth", "--01") .addVariable("myGMonthDay", "--01-01").addVariable("myGYear", "1901") .addVariable("myGYearMonth", "1901-01").addVariable("myDate", "2014-09-01") .addVariable("myDateTime", DatatypeFactory.newInstance().newXMLGregorianCalendar(septFirst).toString()) .addVariable("myTime", "00:01:01"); EvalResultIterator results = call.eval(); try {/*from w ww .j a va2s . com*/ EvalResult result = results.next(); assertEquals("myString should = 'Mars'", "Mars", result.getAs(String.class)); assertEquals("myString should be Type.STRING", EvalResult.Type.STRING, result.getType()); assertEquals("myString should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myArray should = [\"item1\",\"item2\"]", new ObjectMapper().readTree("[\"item1\",\"item2\"]"), result.getAs(JsonNode.class)); assertEquals("myArray should be Type.JSON", EvalResult.Type.JSON, result.getType()); assertEquals("myArray should be Format.JSON", Format.JSON, result.getFormat()); result = results.next(); assertEquals("myObject should = {\"item1\":\"value1\"}", new ObjectMapper().readTree("{\"item1\":\"value1\"}"), result.getAs(JsonNode.class)); assertEquals("myObject should be Type.JSON", EvalResult.Type.JSON, result.getType()); assertEquals("myObject should be Format.JSON", Format.JSON, result.getFormat()); result = results.next(); assertEquals("myAnyUri looks wrong", "http://marklogic.com/a", result.getString()); assertEquals("myAnyUri should be Type.ANYURI", EvalResult.Type.ANYURI, result.getType()); assertEquals("myAnyUri should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myBinary looks wrong", ",", result.getString()); assertEquals("myBinary should be Type.BINARY", EvalResult.Type.BINARY, result.getType()); assertEquals("myBinary should be Format.UNKNOWN", Format.UNKNOWN, result.getFormat()); result = results.next(); assertArrayEquals("myBase64Binary should = 1, 2, 3", new byte[] { 1, 2, 3 }, DatatypeConverter.parseBase64Binary(result.getString())); assertEquals("myBase64Binary should be Type.BASE64BINARY", EvalResult.Type.BASE64BINARY, result.getType()); assertEquals("myBase64Binary should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertArrayEquals("myHexBinary should = 1, 2, 3", new byte[] { 1, 2, 3 }, DatatypeConverter.parseHexBinary(result.getString())); assertEquals("myHexBinary should be Type.HEXBINARY", EvalResult.Type.HEXBINARY, result.getType()); assertEquals("myHexBinary should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDuration should = P100D", "P100D", result.getString()); assertEquals("myDuration should be Type.DURATION", EvalResult.Type.DURATION, result.getType()); assertEquals("myDuration should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myQName doesn't look right", "myPrefix:a", result.getString()); assertEquals("myQName should be Type.QNAME", EvalResult.Type.QNAME, result.getType()); assertEquals("myQName should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDocument doesn't look right", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<search:options xmlns:search=\"http://marklogic.com/appservices/search\"/>", result.getString()); assertEquals("myDocument should be Type.XML", EvalResult.Type.XML, result.getType()); assertEquals("myDocument should be Format.XML", Format.XML, result.getFormat()); result = results.next(); assertEquals("myAttribute looks wrong", "a", result.getString()); assertEquals("myAttribute should be Type.ATTRIBUTE", EvalResult.Type.ATTRIBUTE, result.getType()); assertEquals("myAttribute should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myComment should = <!--a-->", "<!--a-->", result.getString()); assertEquals("myComment should be Type.COMMENT", EvalResult.Type.COMMENT, result.getType()); assertEquals("myComment should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myElement looks wrong", "<a a=\"a\"/>", result.getString()); assertEquals("myElement should be Type.XML", EvalResult.Type.XML, result.getType()); assertEquals("myElement should be Format.XML", Format.XML, result.getFormat()); result = results.next(); assertEquals("myProcessingInstruction should = <?a?>", "<?a?>", result.getString()); assertEquals("myProcessingInstruction should be Type.PROCESSINGINSTRUCTION", EvalResult.Type.PROCESSINGINSTRUCTION, result.getType()); assertEquals("myProcessingInstruction should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myText should = a", "a", result.getString()); assertEquals("myText should be Type.TEXTNODE", EvalResult.Type.TEXTNODE, result.getType()); assertEquals("myText should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myBool should = true", true, result.getBoolean()); assertEquals("myBool should be Type.BOOLEAN", EvalResult.Type.BOOLEAN, result.getType()); assertEquals("myBool should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myInteger should = 1234567890123456789l", 1234567890123456789l, result.getNumber().longValue()); assertEquals("myInteger should be Type.INTEGER", EvalResult.Type.INTEGER, result.getType()); assertEquals("myInteger should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myBigInteger looks wrong", new BigInteger("123456789012345678901234567890"), new BigInteger(result.getString())); assertEquals("myBigInteger should be Type.STRING", EvalResult.Type.STRING, result.getType()); assertEquals("myBigInteger should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDecimal looks wrong", 1111111111111111111.9, result.getNumber().doubleValue(), .001); assertEquals("myDecimal should be Type.DECIMAL", EvalResult.Type.DECIMAL, result.getType()); assertEquals("myDecimal should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myDouble looks wrong", 1.11111111111111E19, result.getNumber().doubleValue(), .001); assertEquals("myDouble should be Type.DOUBLE", EvalResult.Type.DOUBLE, result.getType()); assertEquals("myDouble should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myFloat looks wrong", 1.1, result.getNumber().floatValue(), .001); assertEquals("myFloat should be Type.FLOAT", EvalResult.Type.FLOAT, result.getType()); assertEquals("myFloat should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGDay looks wrong", "---01", result.getString()); assertEquals("myGDay should be Type.GDAY", EvalResult.Type.GDAY, result.getType()); assertEquals("myGDay should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGMonth looks wrong", "--01", result.getString()); assertEquals("myGMonth should be Type.GMONTH", EvalResult.Type.GMONTH, result.getType()); assertEquals("myGMonth should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGMonthDay looks wrong", "--01-01", result.getString()); assertEquals("myGMonthDay should be Type.GMONTHDAY", EvalResult.Type.GMONTHDAY, result.getType()); assertEquals("myGMonthDay should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGYear looks wrong", "1901", result.getString()); assertEquals("myGYear should be Type.GYEAR", EvalResult.Type.GYEAR, result.getType()); assertEquals("myGYear should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myGYearMonth looks wrong", "1901-01", result.getString()); assertEquals("myGYearMonth should be Type.GYEARMONTH", EvalResult.Type.GYEARMONTH, result.getType()); assertEquals("myGYearMonth should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); // the lexical format MarkLogic uses to serialize a date assertEquals("myDate should = '2014-09-01", "2014-09-01", result.getString()); assertEquals("myDate should be Type.DATE", EvalResult.Type.DATE, result.getType()); assertEquals("myDate should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); // the lexical format MarkLogic uses to serialize a dateTime assertEquals("myDateTime should = '2014-09-01T00:00:00+02:00'", "2014-09-01T00:00:00+02:00", result.getString()); assertEquals("myDateTime should be Type.DATETIME", EvalResult.Type.DATETIME, result.getType()); assertEquals("myDateTime should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myTime looks wrong", "00:01:01", result.getString()); assertEquals("myTime should be Type.TIME", EvalResult.Type.TIME, result.getType()); assertEquals("myTime should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myCtsQuery should be Type.OTHER", EvalResult.Type.OTHER, result.getType()); assertEquals("myCtsQuery should be Format.TEXT", Format.TEXT, result.getFormat()); result = results.next(); assertEquals("myFunction should be Type.OTHER", EvalResult.Type.OTHER, result.getType()); assertEquals("myFunction should be Format.TEXT", Format.TEXT, result.getFormat()); } finally { results.close(); } }
From source file:com.ibm.opensirf.jaxrs.ObjectApi.java
private static String bytesToHex(byte[] bytes) { return DatatypeConverter.printHexBinary(bytes); }
From source file:com.amazonaws.services.kinesis.producer.Daemon.java
private static String protobufToHex(com.google.protobuf.Message msg) { return DatatypeConverter.printHexBinary(msg.toByteArray()); }