mcardle     2005/11/02 17:54:59 CET

  Modified files:
    src/org/jahia/esi/cache FragmentCache.java 
  Log:
  *switched to org.apache.commons.codec.binary.Base64 instead of homemade 
version
  
  Revision  Changes    Path
  1.3       +12 -28    esi_server/src/org/jahia/esi/cache/FragmentCache.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/esi_server/src/org/jahia/esi/cache/FragmentCache.java.diff?r1=1.2&r2=1.3&f=h
  
  
  
  Index: FragmentCache.java
  ===================================================================
  RCS file: 
/home/cvs/repository/esi_server/src/org/jahia/esi/cache/FragmentCache.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FragmentCache.java        2 Nov 2005 15:50:13 -0000       1.2
  +++ FragmentCache.java        2 Nov 2005 16:54:58 -0000       1.3
  @@ -1,10 +1,13 @@
   package org.jahia.esi.cache;
   
   import java.util.*;
  +import java.io.UnsupportedEncodingException;
  +
   import com.twmacinta.util.*;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.commons.httpclient.HttpMethod;
  +import org.apache.commons.codec.binary.Base64;
   import org.jahia.esi.cache.CacheObject;
   import org.jahia.esi.cache.ContentCacheObject;
   import org.jahia.esi.EsiConst;
  @@ -35,7 +38,8 @@
       //is referenced by entries in hashCache. If it's 0, then the entry in 
contentCache can removed safely
       //private HashMap countCache = new HashMap();
   
  -    
  +    static Base64 base64 = null;
  +
   
       /**
        * The singleton.
  @@ -51,7 +55,7 @@
       }
   
       FragmentCache() {
  -
  +       base64 = new Base64();
       }
   
       public HashMap getHashCache() {
  @@ -293,37 +297,17 @@
           return hashCache;
       }
   
  -
  -    /**
  -     * Usable caracters for key generation
  -     */
  -    private static final String m_strBase64Chars = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  -
  -    //TODO: user Base64 commons class instead
       /**
        * Convert a byte array into a Base64 string (as used in mime formats)
        */
       private static String toBase64(byte[] aValue) {
  -        int byte1;
  -        int byte2;
  -        int byte3;
  -        int iByteLen = aValue.length;
  -        StringBuffer tt = new StringBuffer();
  -
  -        for (int i = 0; i < iByteLen; i += 3) {
  -            boolean bByte2 = (i + 1) < iByteLen;
  -            boolean bByte3 = (i + 2) < iByteLen;
  -            byte1 = aValue[i] & 0xFF;
  -            byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
  -            byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
  -
  -            tt.append(m_strBase64Chars.charAt(byte1 / 4));
  -            tt.append(m_strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) 
* 16)));
  -            tt.append(((bByte2) ? m_strBase64Chars.charAt((byte3 / 64) + 
((byte2 & 0xF) * 4)) : '='));
  -            tt.append(((bByte3) ? m_strBase64Chars.charAt(byte3 & 0x3F) : 
'='));
  +        try {
  +            byte[] sbtytes = base64.encode(aValue );
  +            return new String(sbtytes,  "ISO-8859-1" );
  +        } catch (UnsupportedEncodingException e) {
  +            log.error(e);
           }
  -
  -        return tt.toString();
  +        return null;
       }
   
   
  

Reply via email to