Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.storemate.shared.compress;
  
  public enum Compression
  {
    
Indicates case where no compression algorithm is used
  
      NONE('N'"identity", 0),

    
Indicates use of LZF compression (fast, modest compression)
 
     LZF('L'"lzf", 1),

    
Indicates use of basic deflate compression, no header; 'Z' from zip (although technically closer to gzip)
 
     GZIP('Z'"gzip", 2)
     ;
     
     private final char _char;
 
     private final int _index;
 
     private final String _contentEncoding;
     
     private Compression(char cString contentEncint index)
     {
          = c;
          = index;
          = contentEnc;
     }
 
     public char asChar() { return ; }
     public int asIndex() { return ; }
 
     public String asContentEncoding()
     {
         // for NONE we could also use "identity" but...
         /*
         if (this == NONE) {
             return null;
         }
         */
         return ;
     }
 
     @Override
     public String toString() {
         return (this == ) ? "none" : ;
     }
    
    
Helper method that can be called to see if this Compression method is one of acceptable encodings that client has listed.
 
     public boolean isAcceptable(String acceptableEncodings)
     {
         if (acceptableEncodings == null) {
             return false;
         }
         // crude, but functional due to small number of legal values:
         return acceptableEncodings.indexOf() >= 0;
     }
 
     public static Compression from(String str)
     {
     	if (str == nullreturn null;
     	str = str.trim();
     	if (..equals(str)) {
     		return ;
     	}
     	if (..equals(str)) {
     		return ;
     	}
     	if (..equals(str)) {
     		return ;
     	}
     	return null;
     }
     
     /*
     public static Compression valueOf(byte b, boolean errorForUnknown) {
         return valueOf((char) b, errorForUnknown);
     }
     
     @Deprecated
     public static Compression valueOf(char c, boolean errorForUnknown)
     {
         if (c == '\0') return NONE;
         for (Compression comp : values()) {
             if (comp.asChar() == c) {
                 return comp;
             }
         }
         if (errorForUnknown) {
             throw new IllegalArgumentException("Unrecognized compression value: 0x"
                    +Integer.toHexString(c)+"");
        }
        return null;
    }
    */
    public static Compression forIndex(int indexboolean errorForUnknown)
    {
        for (Compression comp : values()) {
            if (comp.asIndex() == index) {
                return comp;
            }
        }
        if (errorForUnknown) {
            throw new IllegalArgumentException("Unrecognized compression value: 0x"
                    +Integer.toHexString(index)+" (currently only values 0 - 2 supported)");
        }
        return null;
    }

    
Factory method used for finding match for given HTTP Content-Encoding value, if possible. Will return null if no match done.
    public static Compression forContentEncoding(String contentEncoding)
    {
        if (contentEncoding == nullreturn null;
        contentEncoding = contentEncoding.trim();
        // not the cleanest, but should do for now:
        if (..equals((contentEncoding))) {
            return ;
        }
        if (..equals((contentEncoding))) {
            return ;
        }
        // can leave 'NONE' to default handling:
        return null;
    }
New to GrepCode? Check out our FAQ X