Search in sources :

Example 1 with CBORGenerator

use of com.fasterxml.jackson.dataformat.cbor.CBORGenerator in project nutch by apache.

the class CommonCrawlDataDumper method serializeCBORData.

private byte[] serializeCBORData(String jsonData) {
    CBORFactory factory = new CBORFactory();
    CBORGenerator generator = null;
    ByteArrayOutputStream stream = null;
    try {
        stream = new ByteArrayOutputStream();
        generator = factory.createGenerator(stream);
        // Writes CBOR tag
        writeMagicHeader(generator);
        generator.writeString(jsonData);
        generator.flush();
        stream.flush();
        return stream.toByteArray();
    } catch (Exception e) {
        LOG.warn("CBOR encoding failed: " + e.getMessage());
    } finally {
        try {
            generator.close();
            stream.close();
        } catch (IOException e) {
        // nothing to do
        }
    }
    return null;
}
Also used : CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CBORGenerator(com.fasterxml.jackson.dataformat.cbor.CBORGenerator) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

CBORFactory (com.fasterxml.jackson.dataformat.cbor.CBORFactory)1 CBORGenerator (com.fasterxml.jackson.dataformat.cbor.CBORGenerator)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ParseException (java.text.ParseException)1