Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.client.call;
  
  import java.io.*;
  
Helper class used for creating one of standard PutContentProvider implementations.
 
 public class PutContentProviders
 {
     public static StdPutContentProvider forFile(File flong length) {
         return new FileBacked(flength);
     }
 
     public static StdPutContentProvider forBytes(byte[] bytes) {
         return forBytes(bytes, 0, bytes.length);
     }
 
     public static StdPutContentProvider forBytes(byte[] bytesCompression complong origLen) {
         return forBytes(ByteContainer.simple(bytes, 0, bytes.length), comporigLen);
     }
 
     public static StdPutContentProvider forBytes(byte[] bytesint offsetint len) {
         return new ByteBacked(ByteContainer.simple(bytesoffsetlen));
     }
 
     public static StdPutContentProvider forBytes(ByteContainer bytesCompression complong origLen) {
         return new ByteBacked(bytescomporigLen);
     }
    
    
Intermediate base class used for building actual PutContentProvider instances.
 
     public abstract static class StdPutContentProvider
         implements PutContentProvider
     {
         protected final Compression _existingCompression;
         protected final long _uncompressedLength;
 
         protected final AtomicInteger _contentHash = new AtomicInteger(.);
 
         protected StdPutContentProvider() {
              = null;
              = 0L;
         }
 
         protected StdPutContentProvider(Compression complong uncompressedLength) {
              = comp;
              = uncompressedLength;
         }
 
         protected StdPutContentProvider(StdPutContentProvider base) {
              = base._existingCompression;
              = base._uncompressedLength;
         }
         
         public abstract StdPutContentProvider withCompression(Compression complong uncompLen);
        
        
Default implementation does not require any clean up, so implementation is empty.
 
         @Override
         public void release() { }
         
         @Override
         public int getContentHash() {
             return .get();
         }
 
         @Override
         public void setContentHash(int hash) {
             // Should get same value always, but just to make sure we never
             // change value, or overwrite with "no hash"
             .compareAndSet(.hash);
         }
 
         @Override
         public Compression getExistingCompression() {
             return ;
         }
 
         @Override
         public long uncompressedLength() {
             return ;
         }
     }
 
     /*
     /**********************************************************************
     /* Simple standard implementation for byte[] backed
     /**********************************************************************
      */

    
Simple PutContentProvider implementation that is backed by a raw byte array.
    protected static class ByteBacked extends StdPutContentProvider
    {
        protected final ByteContainer _bytes;
        public ByteBacked(ByteContainer data) {
            super();
             = data;
        }
        public ByteBacked(ByteContainer data,
                Compression complong originalLength) {
            super(comporiginalLength);
             = data;
        }
        @Override
        public ByteBacked withCompression(Compression complong uncompLen) {
            return new ByteBacked(compuncompLen);
        }
        
        @Override public long length() { return (long.byteLength(); }
        @Override public ByteContainer contentAsBytes() { return ; }
        @Override public File contentAsFile() { return null; }
        @Override public InputStream contentAsStream() { return null; }
    }
    
    /*
    /**********************************************************************
    /* Simple standard implementations for providers
    /**********************************************************************
     */
    
    
Simple PutContentProvider implementation that is backed by a java.io.File.
    protected static class FileBacked
        extends StdPutContentProvider
    {
        protected final File _file;
        protected final long _length;
        public FileBacked(File filelong length) {
            this(filelengthnull, 0L);
        }
        public FileBacked(File filelong length,
                Compression existingCompressionlong uncompressedLength) {
            super(existingCompressionuncompressedLength);
             = file;
             = length;
        }
        @Override
        public FileBacked withCompression(Compression complong uncompLen) {
            return new FileBacked(compuncompLen);
        }
        
        @Override public long length() { return ; }
        @Override public ByteContainer contentAsBytes() { return null; }
        @Override public File contentAsFile() { return ; }
        @Override public InputStream contentAsStream() { return null; }
    }
New to GrepCode? Check out our FAQ X