Package com.fasterxml.clustermate.client.call

Source Code of com.fasterxml.clustermate.client.call.GetContentProcessorForBytes

package com.fasterxml.clustermate.client.call;

import java.io.IOException;

import com.fasterxml.storemate.shared.util.ByteAggregator;

/**
* Simple {@link GetContentProcessor} implementation for GETting content
* and aggregating it in (and returning as) {@link ByteAggregator}.
*/
public class GetContentProcessorForBytes extends GetContentProcessor<ByteAggregator>
{
    @Override public GetContentProcessorForBytes.Handler createHandler() {
        return new Handler();
    }

    /**
     * Simple {@link PutContentProvider} implementation that is backed by
     * specific File. More advanced implementations would probably try creating
     * new temporary files instead.
     */
    public static class Handler extends GetContentProcessor.Handler<ByteAggregator>
    {
        protected  ByteAggregator _bytes;
       
        public Handler() { }

        @Override
        public boolean processContent(byte[] content, int offset, int length)
            throws IOException
        {
            _bytes = ByteAggregator.with(_bytes, content, offset, length);
            // yeah, let's get all there is?
            return true;
        }

        @Override
        public ByteAggregator completeContentProcessing() throws IOException
        {
            if (_bytes == null) {
                _bytes = new ByteAggregator();
            }
            return _bytes;
        }

        @Override
        public void contentProcessingFailed(Throwable cause) { }
    }
}
TOP

Related Classes of com.fasterxml.clustermate.client.call.GetContentProcessorForBytes

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.