Example usage for com.fasterxml.jackson.dataformat.cbor CBORGenerator writeString

List of usage examples for com.fasterxml.jackson.dataformat.cbor CBORGenerator writeString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.cbor CBORGenerator writeString.

Prototype

@Override
    public final void writeString(SerializableString sstr) throws IOException 

Source Link

Usage

From source file:org.apache.nutch.tools.CommonCrawlDataDumper.java

private byte[] serializeCBORData(String jsonData) {
    CBORFactory factory = new CBORFactory();

    CBORGenerator generator = null;
    ByteArrayOutputStream stream = null;

    try {/*from   w  w w .ja va 2 s  .c o m*/
        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;
}