abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r503948 - in /incubator/abdera/java/trunk: client/src/main/java/org/apache/abdera/protocol/client/ protocol/src/main/java/org/apache/abdera/protocol/util/
Date Tue, 06 Feb 2007 01:24:43 GMT
Author: jmsnell
Date: Mon Feb  5 17:24:43 2007
New Revision: 503948

URL: http://svn.apache.org/viewvc?view=rev&rev=503948
Log:
Consolidating utility classes

Removed:
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/ContentEncodingUtil.java
Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java?view=diff&rev=503948&r1=503947&r2=503948
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java
Mon Feb  5 17:24:43 2007
@@ -27,7 +27,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.protocol.client.util.AutoReleasingInputStream;
-import org.apache.abdera.protocol.util.ContentEncodingUtil;
+import org.apache.abdera.protocol.util.EncodingUtil;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.URIException;
@@ -155,7 +155,7 @@
       String ce = getHeader("Content-Encoding");
       in = method.getResponseBodyAsStream();
       if (ce != null)
-        in = ContentEncodingUtil.getDecodingInputStream(in, ce);
+        in = EncodingUtil.getDecodingInputStream(in, ce);
     }
     return new AutoReleasingInputStream(method,in);
   }

Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java?view=diff&rev=503948&r1=503947&r2=503948
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
(original)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
Mon Feb  5 17:24:43 2007
@@ -17,6 +17,14 @@
 */
 package org.apache.abdera.protocol.util;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.InflaterInputStream;
+
 import org.apache.commons.codec.net.QCodec;
 
 public class EncodingUtil {
@@ -35,5 +43,37 @@
     } catch (Exception e) {
       return value;
     }
+  }
+  
+  public enum ContentEncoding { GZIP, XGZIP, DEFLATE }
+  
+  public static OutputStream getEncodedOutputStream(OutputStream out, ContentEncoding encoding)
throws IOException {
+    return getEncodedOutputStream(out, new ContentEncoding[] {encoding});
+  }
+  
+  public static OutputStream getEncodedOutputStream(OutputStream out, ContentEncoding...
encodings) throws IOException {
+    for (ContentEncoding encoding:encodings) {
+      switch(encoding) {
+        case GZIP:
+          out = new GZIPOutputStream(out); break;
+        case DEFLATE:
+          out = new DeflaterOutputStream(out); break;
+      }
+    }
+    return out;
+  }
+  
+  public static InputStream getDecodingInputStream(InputStream in, String ce) throws IOException
{
+    String[] encodings = CacheControlParser.splitAndTrim(ce, ",", false);
+    for (int n = encodings.length -1; n >= 0; n--) {
+      switch(ContentEncoding.valueOf(encodings[n].toUpperCase().replaceAll("-", ""))) {
+        case GZIP:
+        case XGZIP:
+          in = new GZIPInputStream(in); break;
+        case DEFLATE:
+          in = new InflaterInputStream(in); break;
+      }
+    }
+    return in;
   }
 }



Mime
View raw message