List of usage examples for org.apache.commons.codec.binary Hex encodeHexString
public static String encodeHexString(byte[] data)
From source file:com.bitbreeds.webrtc.sctp.impl.SCTPImpl.java
/** * Run the onMessage callback/* www . ja va 2 s .com*/ * @param data input to callback */ protected void runOnMessage(DataStorage data) { /** * @see <a href="https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-12">data channel spec</a> */ if (parameters == null && data.getProtocolId() == SCTPPayloadProtocolId.WEBRTC_DCEP) { final byte[] msgData = data.getPayload(); DataChannelMessageType msg = DataChannelMessageType.fromInt(unsign(msgData[0])); if (DataChannelMessageType.OPEN.equals(msg)) { logger.debug("Received open: " + Hex.encodeHexString(msgData)); DataChannelType type = DataChannelType.fromInt(unsign(msgData[2])); DataChannelPriority priority = DataChannelPriority .fromInt(intFromTwoBytes(copyRange(msgData, new ByteRange(2, 4)))); int relParam = intFromFourBytes(copyRange(msgData, new ByteRange(4, 8))); int labelLength = SignalUtil.intFromTwoBytes(copyRange(msgData, new ByteRange(8, 10))); int protocolLength = SignalUtil.intFromTwoBytes(copyRange(msgData, new ByteRange(10, 12))); byte[] label = SignalUtil.copyRange(msgData, new ByteRange(12, 12 + labelLength)); byte[] protocol = SignalUtil.copyRange(msgData, new ByteRange(12 + labelLength, 12 + labelLength + protocolLength)); /** * Store params */ parameters = new ReliabilityParameters(relParam, type, priority, label, protocol); logger.info("Updated channel with parameters: " + parameters); /** * Send ack and do not process anymore */ byte[] ack = new byte[] { sign(DataChannelMessageType.ACK.getType()) }; this.writer.send(ack, SCTPPayloadProtocolId.WEBRTC_DCEP); logger.debug("Sending ack: " + Hex.encodeHexString(ack)); return; } else { throw new IllegalArgumentException("PPID " + SCTPPayloadProtocolId.WEBRTC_DCEP + " should be sent with " + DataChannelMessageType.OPEN); } } logger.trace("Flags: " + data.getFlags() + " Stream: " + data.getStreamId() + " Stream seq: " + data.getStreamSequence()); logger.trace("Data as hex: " + Hex.encodeHexString(data.getPayload())); logger.trace("Data as string: " + new String(data.getPayload()) + ":"); ReceiveService.TsnStatus status = sackCreator.handleTSN(data.getTSN()); if (status != ReceiveService.TsnStatus.DUPLICATE) { receivedBytes.getAndAdd(data.getPayload().length); if (data.getFlags().isOrdered()) { /** * * TODO here we have to do something to ensure ordering * * Stream identifier and stream sequence must be used. * * Messages could be 'stored' until the correct sequence * number is received, or maybe we can rely on resend for that? * * Must be careful not to add TSN if I mean to drop the * message and rely on resend... * * Drop * */ this.writer.runOnMessage(data.getPayload()); } else { this.writer.runOnMessage(data.getPayload()); } } else { duplicateCount.incrementAndGet(); } }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileC.java
private void incorporateOCSPRefs(CompleteRevocationRefsType completeRevocationRefs, ValidationContext ctx) { if (!ctx.getNeededOCSPResp().isEmpty()) { OCSPRefsType ocspRefs = this.xadesObjectFactory.createOCSPRefsType(); completeRevocationRefs.setOCSPRefs(ocspRefs); List<OCSPRefType> ocspRefList = ocspRefs.getOCSPRef(); for (BasicOCSPResp basicOcspResp : ctx.getNeededOCSPResp()) { try { OCSPRefType ocspRef = this.xadesObjectFactory.createOCSPRefType(); DigestAlgAndValueType digestAlgAndValue = getDigestAlgAndValue( OCSPUtils.fromBasicToResp(basicOcspResp).getEncoded(), DigestAlgorithm.SHA1); LOG.info("Add a reference for OCSP produced at " + basicOcspResp.getProducedAt() + " digest " + Hex.encodeHexString(digestAlgAndValue.getDigestValue())); ocspRef.setDigestAlgAndValue(digestAlgAndValue); OCSPIdentifierType ocspIdentifier = xadesObjectFactory.createOCSPIdentifierType(); ocspRef.setOCSPIdentifier(ocspIdentifier); Date producedAt = basicOcspResp.getProducedAt(); GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(); cal.setTime(producedAt); ocspIdentifier.setProducedAt(this.datatypeFactory.newXMLGregorianCalendar(cal)); ResponderIDType responderId = this.xadesObjectFactory.createResponderIDType(); ocspIdentifier.setResponderID(responderId); RespID respId = basicOcspResp.getResponderId(); ResponderID ocspResponderId = respId.toASN1Object(); DERTaggedObject derTaggedObject = (DERTaggedObject) ocspResponderId.toASN1Object(); if (2 == derTaggedObject.getTagNo()) { ASN1OctetString keyHashOctetString = (ASN1OctetString) derTaggedObject.getObject(); responderId.setByKey(keyHashOctetString.getOctets()); } else { X509Name name = X509Name.getInstance(derTaggedObject.getObject()); responderId.setByName(name.toString()); }/* w ww. j av a2 s .c o m*/ ocspRefList.add(ocspRef); } catch (IOException ex) { throw new RuntimeException(ex); } } } }
From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java
/** * Calculates the MD2 digest and returns the value as a 32 character hex string. * * @param data//from ww w . j a v a 2s . c o m * Data to digest * @return MD2 digest as a hex string * @throws IOException * On error reading from the stream * @since 1.7 */ public static String md2Hex(final InputStream data) throws IOException { return Hex.encodeHexString(md2(data)); }
From source file:com.chumbok.aauth.otp.TOTP.java
public static String getTOTPCode(String secretKey, long time) { Base32 base32 = new Base32(); byte[] bytes = base32.decode(secretKey); String hexKey = Hex.encodeHexString(bytes); String hexTime = Long.toHexString(time); return TOTP.generateTOTP(hexKey, hexTime, "6"); }
From source file:io.undertow.servlet.test.streams.AbstractServletInputStreamTestCase.java
private void runTestViaJavaImpl(final String message, String url) throws IOException { HttpURLConnection urlcon = null; try {//from ww w . j a v a 2s. c o m String uri = getBaseUrl() + "/servletContext/" + url; urlcon = (HttpURLConnection) new URL(uri).openConnection(); urlcon.setInstanceFollowRedirects(true); urlcon.setRequestProperty("Connection", "close"); urlcon.setRequestMethod("POST"); urlcon.setDoInput(true); urlcon.setDoOutput(true); OutputStream os = urlcon.getOutputStream(); os.write(message.getBytes()); os.close(); Assert.assertEquals(StatusCodes.OK, urlcon.getResponseCode()); InputStream is = urlcon.getInputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); byte[] buf = new byte[256]; int len; while ((len = is.read(buf)) > 0) { bytes.write(buf, 0, len); } is.close(); final String response = new String(bytes.toByteArray(), 0, bytes.size()); if (!message.equals(response)) { System.out.println(String.format("response=%s", Hex.encodeHexString(response.getBytes()))); } Assert.assertEquals(message, response); } finally { if (urlcon != null) { urlcon.disconnect(); } } }
From source file:com.moz.fiji.schema.tools.TestScanTool.java
@Test public void testFijiScanStartAndLimitRow() throws Exception { final Fiji fiji = getFiji(); TableLayoutDesc desc = FijiTableLayouts.getLayout(FijiTableLayouts.FOO_TEST); ((RowKeyFormat2) desc.getKeysFormat()).setEncoding(RowKeyEncoding.RAW); final FijiTableLayout layout = FijiTableLayout.newLayout(desc); final long timestamp = 10L; new InstanceBuilder(fiji).withTable(layout.getName(), layout).withRow("gwu@usermail.example.com") .withFamily("info").withQualifier("email").withValue(timestamp, "gwu@usermail.example.com") .withQualifier("name").withValue(timestamp, "Garrett Wu").withRow("aaron@usermail.example.com") .withFamily("info").withQualifier("email").withValue(timestamp, "aaron@usermail.example.com") .withQualifier("name").withValue(timestamp, "Aaron Kimball") .withRow("christophe@usermail.example.com").withFamily("info").withQualifier("email") .withValue(timestamp, "christophe@usermail.example.com").withQualifier("name") .withValue(timestamp, "Christophe Bisciglia").withRow("kiyan@usermail.example.com") .withFamily("info").withQualifier("email").withValue(timestamp, "kiyan@usermail.example.com") .withQualifier("name").withValue(timestamp, "Kiyan Ahmadizadeh").withRow("john.doe@gmail.com") .withFamily("info").withQualifier("email").withValue(timestamp, "john.doe@gmail.com") .withQualifier("name").withValue(timestamp, "John Doe").withRow("jane.doe@gmail.com") .withFamily("info").withQualifier("email").withValue(timestamp, "jane.doe@gmail.com") .withQualifier("name").withValue(timestamp, "Jane Doe").build(); final FijiTable table = fiji.openTable(layout.getName()); try {//from w w w . j av a 2s . c o m assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString() + "info:name")); assertEquals(18, mToolOutputLines.length); assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString() + "info:name,info:email")); assertEquals(30, mToolOutputLines.length); EntityIdFactory eif = EntityIdFactory.getFactory(layout); EntityId startEid = eif.getEntityId("christophe@usermail.example.com"); //second row EntityId limitEid = eif.getEntityId("john.doe@gmail.com"); //second to last row String startHbaseRowKey = Hex.encodeHexString(startEid.getHBaseRowKey()); String limitHbaseRowKey = Hex.encodeHexString(limitEid.getHBaseRowKey()); assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString() + "info:name", "--start-row=hbase=hex:" + startHbaseRowKey, // start at the second row. "--limit-row=hbase=hex:" + limitHbaseRowKey // end at the 2nd to last row (exclusive). )); assertEquals(9, mToolOutputLines.length); } finally { ResourceUtils.releaseOrLog(table); } }
From source file:libepg.epg.section.body.servicedescriptiontable.ServiceDescriptionTableBody.java
@Override /**//from www. ja v a2s . c om * ????????? */ public String toString() { List<ServiceDescriptionTableRepeatingPart> l = this.getSDTRepeatingPartList(); StringBuilder s = new StringBuilder(); for (ServiceDescriptionTableRepeatingPart sdtrp : l) { s.append(sdtrp); } Object[] parameters = { super.toString(), Integer.toHexString(this.getTransport_stream_id()), Integer.toHexString(this.getReserved2()), this.getVersion_number(), this.getCurrent_next_indicator(), Integer.toHexString(this.getSection_number()), Integer.toHexString(this.getLast_section_number()), Integer.toHexString(this.getOriginal_network_id()), Integer.toHexString(this.getReserved_future_use2()), Hex.encodeHexString(this.getRepeatingPart()), s.toString() }; return TABLE_DESC.format(parameters); }
From source file:libepg.epg.section.sectionreconstructor.PayLoadSplitter.java
/** * 1:payload_unit_start_indicator?1?????0?????2??????????1?<br> * 2:payload_unit_start_indicator?1?????0????<br> * ?2???????????????<br>//from w w w .ja va 2 s . c o m * ????+1??????????2?<br> * 3:payload_unit_start_indicator?0????????1? * * @return ??? <br> */ public synchronized Map<PAYLOAD_PART_KEY, byte[]> getSplittedPayLoad() { if (LOG.isTraceEnabled()) { LOG.trace(this.packet); } Map<PAYLOAD_PART_KEY, byte[]> temp = new HashMap<>(); EXEC: { if (this.packet .getPayload_unit_start_indicator() == TsPacket.PAYLOAD_UNIT_START_INDICATOR.NOT_START_POINT) { LOG.trace("????"); temp.put(PAYLOAD_PART_KEY.ALL_PAYLOAD, this.packet.getPayload()); break EXEC; } if (this.packet .getPayload_unit_start_indicator() == TsPacket.PAYLOAD_UNIT_START_INDICATOR.START_PES_OR_START_SECTION) { LOG.trace("???"); int pointerField = ByteConverter.byteToInt(this.packet.getPayload()[0]); int tempLength = this.packet.getPayload().length - 1; byte[] tempArray = new byte[tempLength]; System.arraycopy(this.packet.getPayload(), 1, tempArray, 0, tempArray.length); if (LOG.isTraceEnabled()) { MessageFormat msg1 = new MessageFormat( "?={0} ={1} 2??={2}"); Object[] parameters1 = { pointerField, Hex.encodeHexString(this.packet.getPayload()), Hex.encodeHexString(tempArray) }; LOG.trace(msg1.format(parameters1)); } if (pointerField == 0) { temp.put(PAYLOAD_PART_KEY.PAYLOAD_AFTER_2_BYTE, tempArray); break EXEC; } else { byte[] prev = new byte[pointerField]; System.arraycopy(tempArray, 0, prev, 0, prev.length); temp.put(PAYLOAD_PART_KEY.PREV_POINTER, prev); byte[] next = new byte[tempArray.length - pointerField]; System.arraycopy(tempArray, pointerField, next, 0, next.length); temp.put(PAYLOAD_PART_KEY.NEXT_POINTER, next); break EXEC; } } } dumpMap(temp); return Collections.unmodifiableMap(temp); }
From source file:libepg.epg.util.datetime.DateTimeFieldConverter.java
/** * ?????java.sql.Timestamp??? <br> * MJD ??16 16 ??????246?4210BCD???<br> * ?????????????1??? <br>/*from www . jav a 2 s. com*/ * 93/10/13 12:45:00?0xC079124500???? * * @param source * @return ???Timestamp * @throws IndexOutOfBoundsException ?????5??? * @throws java.text.ParseException ??????1???????????????? * */ public static synchronized java.sql.Timestamp BytesToSqlDateTime(byte[] source) throws ParseException { if (source.length != 5) { throw new IndexOutOfBoundsException( "?????5????????" + " ?=" + Hex.encodeHexString(source)); } if (Arrays.equals(source, UNDEFINED_DATETIME_BLOCK.getData())) { throw new ParseException("?????????? ? = " + Hex.encodeHexString(source), 0); } StringBuilder sb = new StringBuilder(); byte[] mjd = new byte[2]; System.arraycopy(source, 0, mjd, 0, mjd.length); sb.append(mjdToString(mjd)); byte[] hms = new byte[3]; System.arraycopy(source, 2, hms, 0, hms.length); sb.append(BcdTimeToString(hms)); String dateStr = sb.toString(); java.text.SimpleDateFormat dateParser = new java.text.SimpleDateFormat(DATE_PATTERN); dateParser.setLenient(false); long dt = dateParser.parse(dateStr).getTime(); if (LOG.isTraceEnabled()) { LOG.trace(dt); } return new java.sql.Timestamp(dt); }
From source file:libepg.epg.section.body.eventinformationtable.EventInformationTableRepeatingPart.java
@Override public String toString() { String start = "", stop = ""; try {/*from ww w. jav a2s. c o m*/ start = this.getStart_time_Object().toString(); stop = this.getStopTime_Object().toString(); } catch (ParseException ex) { Logger.getLogger(EventInformationTableRepeatingPart.class.getName()).log(Level.SEVERE, null, ex); } Object[] parameters = { this.data, Integer.toHexString(this.getEvent_id()), Hex.encodeHexString(this.getStart_time()), start, Hex.encodeHexString(this.getDuration()), stop, Integer.toHexString(this.getRunning_status()), Integer.toHexString(this.getFree_CA_mode()), this.getDescriptors_loop_length(), this.getDescriptors_loop() }; return EIT_RP_DESC.format(parameters); }