Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions

Interface used to create GetContentProcessor.Handlers that are used for handling of HTTP GET content.

<T> Type of result returned by handlers
public abstract class GetContentProcessor<T>
Method called to create handler instance
    public abstract Handler<T> createHandler();
    public static abstract class Handler<T>
Factory method to use for creating a wrapper that exposes this handler as a simple, to allow adapting to input sources that require a stream.
        public OutputStream asStream() {
            return new OutputStreamWrapper(this);
        // // // Sequence of stateful calls for success case
Method used when content can only be delivered in chunks: if so, this method may be called zero or more times before completeContentProcessing() is called.
        public abstract void processContent(byte[] contentint offsetint lengththrows IOException;
Method called once stateful content processing has been successfully completed, and last chunk of data is being delivered.

Note that if this method is called, contentProcessingFailed(java.lang.Throwable) is NOT called.

        public abstract T completeContentProcessing() throws IOException;
        // // // Sequence of stateful calls for error case(s)
Method called to indicate that content access failed, due to an unhandled java.lang.Exception (either thrown by processor itself, or by client). Processor is expected to handle any necessary cleanup.

Note that if this method is called, completeContentProcessing() is NOT called.

        public abstract void contentProcessingFailed(Throwable t);
    /* Helper classes
    public static class OutputStreamWrapper extends OutputStream
        protected final GetContentProcessor.Handler<?> _handler;
        public OutputStreamWrapper(GetContentProcessor.Handler<?> h) {
            if (h == null) {
                throw new NullPointerException("Can not pass null handler");
             = h;
        @Override public void close() { }
        @Override public void flush() { }
        public void write(byte[] bthrows IOException {
            .processContent(b, 0, b.length);
        public void write(byte[] bint offint lenthrows IOException {
        public void write(int bthrows IOException {
            byte[] bytes = new byte[1];
            bytes[0] = (byteb;
            .processContent(bytes, 0, 1);
New to GrepCode? Check out our FAQ X