Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.module.jaxb.ser;
 
 
 

Author(s):
Ryan Heaton
    public DataHandlerJsonSerializer() { super(DataHandler.class); }
    
    @Override
    public void serialize(DataHandler valueJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonProcessingException
    {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        /* for copy-through, a small buffer should suffice: ideally
         * we might want to reuse a generic byte buffer, but for now
         * there's no serializer context to hold them.
         * 
         * Also: it'd be nice not to have buffer all data, but use a
         * streaming output. But currently JsonGenerator won't allow
         * that.
         */
        byte[] buffer = new byte[1024 * 4]; //10k?
        InputStream in = value.getInputStream();
        int len = in.read(buffer);
        while (len > 0) {
            out.write(buffer, 0, len);
            len = in.read(buffer);
        }
        jgen.writeBinary(out.toByteArray());
    }
    @Override
    public JsonNode getSchema(SerializerProvider providerType typeHint)
    {
        ObjectNode o = createSchemaNode("array"true);
        ObjectNode itemSchema = createSchemaNode("string"); //binary values written as strings?
        o.put("items"itemSchema);
        return o;
    }
New to GrepCode? Check out our FAQ X