Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
   * file except in compliance with the License. You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software distributed under
   * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
   * OF ANY KIND, either express or implied. See the License for the specific language
   * governing permissions and limitations under the License.
  */
 
 package com.ning.compress.lzf;
 
 
Decoder that handles decoding of sequence of encoded LZF chunks, combining them into a single contiguous result byte array. This class has been mostly replaced by ChunkDecoder, although static methods are left here and may still be used for convenience. All static methods use com.ning.compress.lzf.util.ChunkDecoderFactory.optimalInstance() to find actual ChunkDecoder instance to use.

Author(s):
Tatu Saloranta (tatu.saloranta@iki.fi)
See also:
ChunkDecoder
 
 public class LZFDecoder
 {
    
Lazily initialized "fast" instance that may use sun.misc.Unsafe to speed up decompression
 
     protected final static AtomicReference<ChunkDecoder_fastDecoderRef = new AtomicReference<ChunkDecoder>();

    
Lazily initialized "safe" instance that DOES NOT use sun.misc.Unsafe for decompression, just standard JDK functionality.
 
     protected final static AtomicReference<ChunkDecoder_safeDecoderRef = new AtomicReference<ChunkDecoder>();
 
     /*
     ///////////////////////////////////////////////////////////////////////
     // Factory methods for ChunkDecoders
     ///////////////////////////////////////////////////////////////////////
      */

    
Accessor method that can be used to obtain ChunkDecoder that uses all possible optimization methods available, including sun.misc.Unsafe for memory access.
 
     public static ChunkDecoder fastDecoder() {
         // race conditions are ok here, we don't really mind
         ChunkDecoder dec = .get();
         if (dec == null) { // 
             dec = ChunkDecoderFactory.optimalInstance();
             .compareAndSet(nulldec);
         }
         return dec;
     }

    
Accessor method that can be used to obtain ChunkDecoder that only uses standard JDK access methods, and should work on all Java platforms and JVMs.
 
     public static ChunkDecoder safeDecoder() {
         // race conditions are ok here, we don't really mind
         ChunkDecoder dec = .get();
         if (dec == null) { // 
             dec = ChunkDecoderFactory.safeInstance();
             .compareAndSet(nulldec);
         }
         return dec;
     }
     
     /*
     ///////////////////////////////////////////////////////////////////////
     // Basic API, general
     ///////////////////////////////////////////////////////////////////////
      */

    
Helper method that checks resulting size of an LZF chunk, regardless of whether it contains compressed or uncompressed contents.
 
     public static int calculateUncompressedSize(byte[] dataint offsetint lengththrows LZFException {
         return ChunkDecoder.calculateUncompressedSize(datalengthlength);
     }
 
     /*
     ///////////////////////////////////////////////////////////////////////
     // Basic API, fast decode methods
     ///////////////////////////////////////////////////////////////////////
      */
    
    public static byte[] decode(final byte[] inputBufferthrows LZFException {
        return fastDecoder().decode(inputBuffer, 0, inputBuffer.length);
    }
    
    public static byte[] decode(final byte[] inputBufferint offsetint lengththrows LZFException {
        return fastDecoder().decode(inputBufferoffsetlength);
    }
    
    public static int decode(final byte[] inputBufferfinal byte[] targetBufferthrows LZFException {
        return fastDecoder().decode(inputBuffer, 0, inputBuffer.lengthtargetBuffer);
    }
    public static int decode(final byte[] sourceBufferint offsetint lengthfinal byte[] targetBuffer)
            throws LZFException {
        return fastDecoder().decode(sourceBufferoffsetlengthtargetBuffer);        
    }
    /*
    ///////////////////////////////////////////////////////////////////////
    // Basic API, "safe" decode methods
    ///////////////////////////////////////////////////////////////////////
     */
    public static byte[] safeDecode(final byte[] inputBufferthrows LZFException {
        return safeDecoder().decode(inputBuffer, 0, inputBuffer.length);
    }
    public static byte[] safeDecode(final byte[] inputBufferint offsetint lengththrows LZFException {
        return safeDecoder().decode(inputBufferoffsetlength);
    }
    public static int safeDecode(final byte[] inputBufferfinal byte[] targetBufferthrows LZFException {
        return safeDecoder().decode(inputBuffer, 0, inputBuffer.lengthtargetBuffer);
    }
    public static int safeDecode(final byte[] sourceBufferint offsetint lengthfinal byte[] targetBuffer)
            throws LZFException {
        return safeDecoder().decode(sourceBufferoffsetlengthtargetBuffer);        
    }
New to GrepCode? Check out our FAQ X