Example usage for org.apache.commons.codec.binary Hex decodeHex

List of usage examples for org.apache.commons.codec.binary Hex decodeHex

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Hex decodeHex.

Prototype

public static byte[] decodeHex(char[] data) throws IllegalArgumentException 

Source Link

Document

Converts an array of characters representing hexadecimal values into an array of bytes of those same values.

Usage

From source file:it.scoppelletti.programmerpower.security.spi.RC5ParameterSpecFactory.java

public AlgorithmParameterSpec newInstance(Properties props, String prefix) {
    int rounds, version, wordSize;
    String name, value;/*from w  w  w .  ja va  2  s  .c om*/
    byte[] iv;
    AlgorithmParameterSpec param;

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_VERSION);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    version = Integer.parseInt(value);

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_ROUNDS);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    rounds = Integer.parseInt(value);

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_WORDSIZE);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        throw new ArgumentNullException(name);
    }

    wordSize = Integer.parseInt(value);

    name = Strings.concat(prefix, RC5ParameterSpecFactory.PROP_IV);
    value = props.getProperty(name);
    if (Strings.isNullOrEmpty(value)) {
        iv = null;
    } else {
        try {
            iv = Hex.decodeHex(value.toCharArray());
        } catch (DecoderException ex) {
            throw SecurityUtils.toSecurityException(ex);
        }
    }

    if (iv != null) {
        param = new RC5ParameterSpec(version, rounds, wordSize, iv);
    } else {
        param = new RC5ParameterSpec(version, rounds, wordSize);
    }

    return param;
}

From source file:descriptordump.Main.java

public void start(String args[]) throws DecoderException, ParseException {
    File inputFile = null;// ww w .jav  a 2s. c  o m
    Charset cs = null;

    final Option charSetOption = Option.builder("c").required(false).longOpt("charset").desc(
            "?????????????")
            .hasArg().type(String.class).build();

    final Option fileNameOption = Option.builder("f").required().longOpt("filename")
            .desc("??").hasArg().type(String.class).build();

    Options opts = new Options();
    opts.addOption(fileNameOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine cl;
    HelpFormatter help = new HelpFormatter();
    try {
        cl = parser.parse(opts, args);

        try {
            cs = Charset.forName(cl.getOptionValue(charSetOption.getOpt()));
        } catch (Exception e) {
            LOG.error(
                    "?????????",
                    e);
            cs = Charset.defaultCharset();
        }
        inputFile = new File(cl.getOptionValue(fileNameOption.getOpt()));
        if (!inputFile.isFile()) {
            throw new ParseException("?????????");
        }

    } catch (ParseException e) {
        // print usage.
        help.printHelp("My Java Application", opts);
    }

    final Set<TABLE_ID> tids = new HashSet<>();
    tids.add(TABLE_ID.SDT_THIS_STREAM);
    tids.add(TABLE_ID.SDT_OTHER_STREAM);
    tids.add(TABLE_ID.NIT_THIS_NETWORK);
    tids.add(TABLE_ID.NIT_OTHER_NETWORK);
    tids.add(TABLE_ID.EIT_THIS_STREAM_8_DAYS);
    tids.add(TABLE_ID.EIT_THIS_STREAM_NOW_AND_NEXT);
    tids.add(TABLE_ID.EIT_OTHER_STREAM_8_DAYS);
    tids.add(TABLE_ID.EIT_OTHER_STREAM_NOW_AND_NEXT);

    LOG.info("Starting application...");
    LOG.info("ts filename   : " + inputFile.getAbsolutePath());
    LOG.info("charset       : " + cs);

    Set<Section> sections = new HashSet<>();
    try {
        FileInputStream input = new FileInputStream(inputFile);
        InputStreamReader stream = new InputStreamReader(input, cs);
        BufferedReader buffer = new BufferedReader(stream);

        String line;
        long lines = 0;
        while ((line = buffer.readLine()) != null) {
            byte[] b = Hex.decodeHex(line.toCharArray());
            Section s = new Section(b);
            if (s.checkCRC() == CRC_STATUS.NO_CRC_ERROR && tids.contains(s.getTable_id_const())) {
                sections.add(s);
                LOG.trace("1????");
            } else {
                LOG.error("?????? = " + s);
            }
            lines++;
        }
        LOG.info(
                "?? = " + lines + " ? = " + sections.size());
        input.close();
        stream.close();
        buffer.close();
    } catch (FileNotFoundException ex) {
        LOG.fatal("???????", ex);
    } catch (IOException ex) {
        LOG.fatal("???????", ex);
    }

    SdtDescGetter sde = new SdtDescGetter();

    NitDescGetter nide = new NitDescGetter();

    EitDescGetter eide = new EitDescGetter();

    for (Section s : sections) {
        sde.process(s);
        nide.process(s);
        eide.process(s);
    }

    Set<Descriptor> descs = new HashSet<>();
    descs.addAll(sde.getUnmodifiableDest());
    descs.addAll(nide.getUnmodifiableDest());
    descs.addAll(eide.getUnmodifiableDest());

    Set<Integer> dtags = new TreeSet<>();
    for (Descriptor d : descs) {
        dtags.add(d.getDescriptor_tag());
    }

    for (Integer i : dtags) {
        LOG.info(Integer.toHexString(i));
    }
}

From source file:net.solarnetwork.node.support.DataCollectorSerialPortBeanParameters.java

public void setMagicHex(String hex) {
    if (hex == null || (hex.length() % 2) == 1) {
        setMagic(null);// w  w w  .  j a  va 2 s  .c  o m
    }
    try {
        setMagic(Hex.decodeHex(hex.toCharArray()));
    } catch (DecoderException e) {
        // fail silently, sorry
    }
}

From source file:libepg.epg.util.datetime.DateTimeFieldConverterTest.java

@Test
@ExpectedExceptionMessage("^??????????.*$")
public void testBytesTOSqlDateTime3() throws Exception {
    LOG.info("_24");
    byte[] source = Hex.decodeHex("e07c240000".toCharArray());
    Timestamp result = DateTimeFieldConverter.BytesToSqlDateTime(source);
}

From source file:de.resol.vbus.HeaderTest.java

@Test
public void testCalcAndCompareChecksumV0() throws Exception {
    byte[] testBuffer1 = Hex.decodeHex("aa000021772000050000000000000042".toCharArray());
    assertEquals(true, Header.calcAndCompareChecksumV0(testBuffer1, 1, 14));

    testBuffer1[15] = 0x41;//w w  w.j a  v  a  2  s .  c o  m
    assertEquals(false, Header.calcAndCompareChecksumV0(testBuffer1, 1, 14));
}

From source file:com.continusec.client.VerifiableMap.java

private static final byte[][] parseAuditPath(ResponseData rd) throws DecoderException {
    byte[][] auditPath = new byte[256][];
    // since we have no guarantees that the map is case insensitive, iterate through each header
    for (String k : rd.headers.keySet()) {
        if (k != null && k.toLowerCase().equals("x-verified-proof")) {
            for (String h : rd.headers.get(k)) {
                for (String p : h.split(",")) {
                    String[] bits = p.split("/");
                    if (bits.length == 2) {
                        auditPath[Integer.parseInt(bits[0].trim())] = Hex
                                .decodeHex(bits[1].trim().toCharArray());
                    }/*ww  w .  ja v a2 s .c  o m*/
                }
            }
        }
    }
    return auditPath;
}

From source file:libepg.epg.section.eit.descriptor.extendedeventdescriptor.ExtendedEventDescriptorTest.java

/**
 * Test of getItems method, of class ExtendedEventDescriptor.
 *
 * @throws org.apache.commons.codec.DecoderException
 */// w ww  .  ja v a 2s.  co m
@Test
public void testGetItems() throws DecoderException {
    LOG.debug("getItems");
    ExtendedEventDescriptor instance = target1;
    byte[] expResult = Hex.decodeHex(
            "084856414846624d46dc3c673f4d3878cf3f373f4d4c2132683248fe4c7045673877b5f3214a0e32360f214bfa42673358423436483865fd306c4559cf42673c6a0e49540f346b3648cb3d223f26b7bfacfd3b52c9e2ce3a22abe9ce4c34c0c3bf4c2132683248ce463bf2447ce1adecba0e330f472fc742603f26b7bffa48603d77ce1b7cc7d3e5f91972386532211b7db7b7bfceacfb0e5745420f4c213268fcce40243326fab3b33f74472fc70e5745421b6f5e732cce352448ac0f3c21213945503e6cb7fd4c2132683248cbcaeb1b6f41637339e20f392dacc3bffae8a6e4af3925adca"
                    .toCharArray());
    byte[] result = instance.getItems();
    assertArrayEquals(expResult, result);
}

From source file:com.knewton.mapreduce.example.StudentEventMapperTest.java

/**
 * Test the end time range filters in the mapper.
 *//*  w w w  .j a v  a  2 s. co  m*/
@Test
public void testEndRangeStudentEvents() throws Exception {
    conf.set(PropertyConstants.END_DATE.txt, "2013-03-28T23:03:02.394Z");
    underTest.setup(mockedContext);

    // send event outside of time range

    // Mar.29.2013.03:07:21.0.0
    DateTime dt = new DateTime(2013, 3, 29, 3, 7, 21, DateTimeZone.UTC);
    long eventId = dt.getMillis();
    ByteBuffer randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    ByteBuffer columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    CellName cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    Cell column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext, never()).write(any(LongWritable.class), any(StudentEventWritable.class));

    // send event inside of time range

    // Mar.28.2013.19:53:38.0.0
    dt = new DateTime(2013, 3, 28, 19, 53, 10, DateTimeZone.UTC);
    eventId = dt.getMillis();
    randomKey = RandomStudentEventGenerator.getRandomIdBuffer();
    columnName = ByteBuffer.wrap(new byte[8]);
    columnName.putLong(eventId);
    columnName.rewind();
    cellName = simpleDenseCellType.cellFromByteBuffer(columnName);
    column = new BufferCell(cellName, ByteBuffer.wrap(Hex.decodeHex(eventDataString.toCharArray())));
    underTest.map(randomKey, column, mockedContext);
    verify(mockedContext).write(any(LongWritable.class), any(StudentEventWritable.class));
}

From source file:libepg.epg.section.eventinformationtable.descriptor.extendedeventdescriptor.ExtendedEventDescriptorTest.java

/**
 * Test of getItems method, of class ExtendedEventDescriptor.
 *
 * @throws org.apache.commons.codec.DecoderException
 *///from ww  w  .ja  va  2  s  .c om
@Test
public void testGetItems() throws DecoderException {
    LOG.info("getItems");
    ExtendedEventDescriptor instance = target1;
    byte[] expResult = Hex.decodeHex(
            "084856414846624d46dc3c673f4d3878cf3f373f4d4c2132683248fe4c7045673877b5f3214a0e32360f214bfa42673358423436483865fd306c4559cf42673c6a0e49540f346b3648cb3d223f26b7bfacfd3b52c9e2ce3a22abe9ce4c34c0c3bf4c2132683248ce463bf2447ce1adecba0e330f472fc742603f26b7bffa48603d77ce1b7cc7d3e5f91972386532211b7db7b7bfceacfb0e5745420f4c213268fcce40243326fab3b33f74472fc70e5745421b6f5e732cce352448ac0f3c21213945503e6cb7fd4c2132683248cbcaeb1b6f41637339e20f392dacc3bffae8a6e4af3925adca"
                    .toCharArray());
    byte[] result = instance.getItems();
    assertArrayEquals(expResult, result);
}

From source file:libepg.epg.section.body.eventinformationtable.EventInformationTableRepeatingPartTest.java

/**
 * Test of getData method, of class EventInformationTableRepeatingPart.
 *///from   w  w w  .j  a  v a 2  s  .  com
@Test
public void testGetData() throws DecoderException {
    LOG.info("getData");
    EventInformationTableRepeatingPart instance = target;
    byte[] expResult = Hex.decodeHex(data);
    byte[] result = instance.getData();
    assertArrayEquals(expResult, result);
}