List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:gobblin.metrics.reporter.KafkaAvroEventReporterWithSchemaRegistryTest.java
@Test public void test() throws Exception { MetricContext context = MetricContext.builder("context").build(); MockKafkaPusher pusher = new MockKafkaPusher(); KafkaAvroSchemaRegistry registry = Mockito.mock(KafkaAvroSchemaRegistry.class); Mockito.when(registry.register(Mockito.any(Schema.class))).thenAnswer(new Answer<String>() { @Override//from ww w. java 2s.c o m public String answer(InvocationOnMock invocation) throws Throwable { return register((Schema) invocation.getArguments()[0]); } }); Mockito.when(registry.register(Mockito.any(Schema.class), Mockito.anyString())) .thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) throws Throwable { return register((Schema) invocation.getArguments()[0]); } }); KafkaEventReporter kafkaReporter = KafkaAvroEventReporter.forContext(context).withKafkaPusher(pusher) .withSchemaRegistry(registry).build("localhost:0000", "topic"); GobblinTrackingEvent event = new GobblinTrackingEvent(0l, "namespace", "name", Maps.<String, String>newHashMap()); context.submitEvent(event); try { Thread.sleep(100); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } kafkaReporter.report(); try { Thread.sleep(100); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } byte[] nextMessage = pusher.messageIterator().next(); DataInputStream is = new DataInputStream(new ByteArrayInputStream(nextMessage)); Assert.assertEquals(is.readByte(), KafkaAvroSchemaRegistry.MAGIC_BYTE); byte[] readId = new byte[20]; Assert.assertEquals(is.read(readId), 20); String readStringId = Hex.encodeHexString(readId); Assert.assertTrue(this.schemas.containsKey(readStringId)); Schema schema = this.schemas.get(readStringId); Assert.assertFalse(schema.toString().contains("avro.java.string")); is.close(); }
From source file:ch.cyberduck.core.azure.AzureAttributesFeature.java
@Override public PathAttributes find(final Path file) throws BackgroundException { if (file.isRoot()) { return PathAttributes.EMPTY; }//from w ww . j a va 2 s. c o m try { if (containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlockBlob blob = session.getClient() .getContainerReference(containerService.getContainer(file).getName()) .getBlockBlobReference(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); options.setRetryPolicyFactory(new RetryNoRetry()); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); attributes.setChecksum( Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); attributes.setETag(properties.getEtag()); return attributes; } } catch (StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch (URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
From source file:com.zimbra.cs.store.triton.TritonBlobStoreManager.java
@Override public String getLocator(byte[] hash) { return Hex.encodeHexString(hash); }
From source file:ch.rgw.tools.PasswordEncryptionService.java
public String generateSaltAsHexString() throws NoSuchAlgorithmException { return Hex.encodeHexString(generateSalt()); }
From source file:com.msopentech.odatajclient.engine.utils.URIUtils.java
/** * Turns primitive values into their respective URI representation. * * @param obj primitive value/*from ww w.j av a 2s.c om*/ * @return URI representation */ public static String escape(final Object obj) { String value; try { value = (obj instanceof UUID) ? "guid'" + obj.toString() + "'" : (obj instanceof byte[]) ? "X'" + Hex.encodeHexString((byte[]) obj) + "'" : ((obj instanceof ODataTimestamp) && ((ODataTimestamp) obj).getTimezone() == null) ? "datetime'" + URLEncoder.encode(((ODataTimestamp) obj).toString(), ODataConstants.UTF8) + "'" : ((obj instanceof ODataTimestamp) && ((ODataTimestamp) obj).getTimezone() != null) ? "datetimeoffset'" + URLEncoder.encode(((ODataTimestamp) obj).toString(), ODataConstants.UTF8) + "'" : (obj instanceof ODataDuration) ? "time'" + ((ODataDuration) obj).toString() + "'" : (obj instanceof BigDecimal) ? new DecimalFormat( EdmSimpleType.Decimal.pattern()) .format((BigDecimal) obj) + "M" : (obj instanceof Double) ? new DecimalFormat( EdmSimpleType.Double.pattern()) .format((Double) obj) + "D" : (obj instanceof Float) ? new DecimalFormat( EdmSimpleType.Single .pattern()) .format((Float) obj) + "f" : (obj instanceof Long) ? ((Long) obj) .toString() + "L" : (obj instanceof String) ? "'" + URLEncoder .encode((String) obj, ODataConstants.UTF8) + "'" : obj.toString(); } catch (Exception e) { LOG.warn("While generating key segment for '{}', using toString()", obj, e); value = obj.toString(); } return value; }
From source file:com.consol.citrus.ws.message.SoapAttachmentTest.java
@Test public void testFromBinaryAttachment() throws Exception { reset(attachment);/* w w w . j a v a2s . c o m*/ expect(attachment.getContentId()).andReturn("img").once(); expect(attachment.getContentType()).andReturn("application/octet-stream").times(2); expect(attachment.getDataHandler()).andReturn(new DataHandler( new StaticTextDataSource("This is img text content!", "application/octet-stream", "UTF-8", "img"))); replay(attachment); SoapAttachment soapAttachment = SoapAttachment.from(attachment); Assert.assertEquals(soapAttachment.getContentId(), "img"); Assert.assertEquals(soapAttachment.getContentType(), "application/octet-stream"); Assert.assertEquals(soapAttachment.getContent(), Base64.encodeBase64String("This is img text content!".getBytes(Charset.forName("UTF-8")))); Assert.assertEquals(soapAttachment.getCharsetName(), Charset.defaultCharset().displayName()); Assert.assertNotNull(soapAttachment.getDataHandler()); Assert.assertEquals(soapAttachment.getSize(), 25L); soapAttachment.setEncodingType(SoapAttachment.ENCODING_BASE64_BINARY); Assert.assertEquals(soapAttachment.getContent(), Base64.encodeBase64String("This is img text content!".getBytes(Charset.forName("UTF-8")))); soapAttachment.setEncodingType(SoapAttachment.ENCODING_HEX_BINARY); Assert.assertEquals(soapAttachment.getContent(), Hex.encodeHexString("This is img text content!".getBytes(Charset.forName("UTF-8"))).toUpperCase()); verify(attachment); }
From source file:epgtools.dumpepgfromts.dataextractor.AbstractDataExtractor.java
/** * ????//ww w . j a v a2 s. c om * * @param s * @throws IllegalArgumentException<br> * 1:???????????????<br> * 2:?CRC??????<br> */ protected final void checkSection(Section s) throws IllegalArgumentException { final String hexDump = Hex.encodeHexString(s.getData()); if (s.checkCRC() != Section.CRC_STATUS.NO_CRC_ERROR) { throw new IllegalArgumentException("CRC?? = " + hexDump); } if (!this.tableIds.contains(s.getTable_id_const())) { StringBuilder sb = new StringBuilder(); sb.append("??ID?????\n"); sb.append("??ID\n"); for (TABLE_ID id : this.tableIds) { sb.append(id).append("\n"); } sb.append("?ID = ").append(s.getTable_id_const()).append("\n"); sb.append(" = ").append(hexDump).append("\n"); throw new IllegalArgumentException(sb.toString()); } }
From source file:com.buaa.cfs.fs.FileEncryptionInfo.java
@Override public String toString() { StringBuilder builder = new StringBuilder("{"); builder.append("cipherSuite: " + cipherSuite); builder.append(", cryptoProtocolVersion: " + version); builder.append(", edek: " + Hex.encodeHexString(edek)); builder.append(", iv: " + Hex.encodeHexString(iv)); builder.append(", keyName: " + keyName); builder.append(", ezKeyVersionName: " + ezKeyVersionName); builder.append("}"); return builder.toString(); }
From source file:ch.cyberduck.core.azure.AzureAttributesFinderFeature.java
@Override public PathAttributes find(final Path file) throws BackgroundException { if (file.isRoot()) { return PathAttributes.EMPTY; }//ww w . j ava 2 s. c o m try { if (containerService.isContainer(file)) { final PathAttributes attributes = new PathAttributes(); final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(file).getName()); container.downloadAttributes(null, null, context); final BlobContainerProperties properties = container.getProperties(); attributes.setETag(properties.getEtag()); attributes.setModificationDate(properties.getLastModified().getTime()); return attributes; } else { final CloudBlob blob = session.getClient() .getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); final BlobRequestOptions options = new BlobRequestOptions(); blob.downloadAttributes(AccessCondition.generateEmptyCondition(), options, context); final BlobProperties properties = blob.getProperties(); final PathAttributes attributes = new PathAttributes(); attributes.setSize(properties.getLength()); attributes.setModificationDate(properties.getLastModified().getTime()); if (StringUtils.isNotBlank(properties.getContentMD5())) { attributes.setChecksum( Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(properties.getContentMD5())))); } attributes.setETag(properties.getEtag()); return attributes; } } catch (StorageException e) { throw new AzureExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch (URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
From source file:com.google.u2f.server.impl.U2FServerReferenceImpl.java
@Override public RegistrationRequest getRegistrationRequest(String accountName, String appId) { Log.info(">> getRegistrationRequest " + accountName); byte[] challenge = challengeGenerator.generateChallenge(accountName); EnrollSessionData sessionData = new EnrollSessionData(accountName, appId, challenge); String sessionId = dataStore.storeSessionData(sessionData); String challengeBase64 = Base64.encodeBase64URLSafeString(challenge); Log.info("-- Output --"); Log.info(" sessionId: " + sessionId); Log.info(" challenge: " + Hex.encodeHexString(challenge)); Log.info("<< getRegistrationRequest " + accountName); return new RegistrationRequest(U2FConsts.U2F_V2, challengeBase64, appId, sessionId); }