Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.clustermate.client.call;
 
 import java.io.*;

Simple GetContentProcessor implementation for GETting content and storing it in java.io.File specified.
 
    protected final File _file;
    public GetContentProcessorForFiles(File f) {  = f; }
        return new Handler();
    }

    
Simple 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<File>
    {
        protected final File _file;
        protected FileOutputStream _out;
        
        public Handler(File f) {
            if (f == nullthrow new IllegalArgumentException("Can not pass null File");
             = f;
        }
        @Override
        public void processContent(byte[] contentint offsetint length)
            throws IOException
        {
            if ( == null) {
                 = new FileOutputStream();
            }
            if (length > 0) {
                .write(contentoffsetlength);
            }
        }
        @Override
        public File completeContentProcessing() throws IOException
        {
            /* one tricky thing: empty files have no content, and so {@link #processContent}
             * will not be called. But we still want the (empty) File...
             */
            if ( == null) {
                 = new FileOutputStream();
            }
            .close();
            return ;
        }
        @Override
        public void contentProcessingFailed(Throwable cause)
        {
            if ( != null) {
                try {
                    .close();
                } catch (IOException e) { }            
                .delete();
            }
        }
    }
New to GrepCode? Check out our FAQ X