All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cedarsoftware.io.writers.ByteArrayWriter Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
package com.cedarsoftware.io.writers;

import java.io.IOException;
import java.io.Writer;
import java.util.Base64;

import com.cedarsoftware.io.WriterContext;

import static com.cedarsoftware.io.JsonWriter.JsonClassWriter;
import static com.cedarsoftware.io.JsonWriter.writeBasicString;

public class ByteArrayWriter implements JsonClassWriter {

    @Override
    public void writePrimitiveForm(Object o, Writer output, WriterContext context) throws IOException {
        final byte[] bytes = (byte[]) o;
        writeBasicString(output, Base64.getEncoder().encodeToString(bytes));
    }

    @Override
    public boolean hasPrimitiveForm(WriterContext context) {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy