Author: sebb
Date: Mon Sep  1 09:09:40 2008
New Revision: 691010

URL: http://svn.apache.org/viewvc?rev=691010&view=rev
Log:
Bug 45694 - Support GZIP compressed logs

Modified:
    
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java
    jakarta/jmeter/trunk/xdocs/changes.xml

Modified: 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java?rev=691010&r1=691009&r2=691010&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java
 (original)
+++ 
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/util/accesslog/TCLogParser.java
 Mon Sep  1 09:09:40 2008
@@ -20,12 +20,15 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.StringTokenizer;
 import java.util.Vector;
+import java.util.zip.GZIPInputStream;
 
 import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
 import org.apache.jmeter.testelement.TestElement;
@@ -170,26 +173,17 @@
     }
 
     /**
-     * Creates a new File object.
-     *
-     * @param filename
-     */
-    public File openFile(String filename) {
-        return new File(filename);
-    }
-
-    /**
      * parse the entire file.
      *
      * @return boolean success/failure
      */
     public int parse(TestElement el, int parseCount) {
         if (this.SOURCE == null) {
-            this.SOURCE = this.openFile(this.FILENAME);
+            this.SOURCE = new File(this.FILENAME);
         }
         try {
             if (this.READER == null) {
-                this.READER = new BufferedReader(new FileReader(this.SOURCE));
+                this.READER = getReader(this.SOURCE);
             }
             return parse(this.READER, el, parseCount);
         } catch (Exception exception) {
@@ -198,6 +192,24 @@
         return -1;// indicate that an error occured
     }
 
+    private static BufferedReader getReader(File file) throws IOException {
+        if (! isGZIP(file)) {
+            return new BufferedReader(new FileReader(file));
+        }
+        GZIPInputStream in = new GZIPInputStream(new FileInputStream(file));
+        return new BufferedReader(new InputStreamReader(in));
+    }
+
+    private static boolean isGZIP(File file) throws IOException {
+        FileInputStream in = new FileInputStream(file);
+        try {
+            return in.read() == (GZIPInputStream.GZIP_MAGIC & 0xFF)
+                && in.read() == (GZIPInputStream.GZIP_MAGIC >> 8);
+        } finally {
+            in.close();
+        }
+    }
+
     /**
      * parse a set number of lines from the access log. Keep in mind the number
      * of lines parsed will depend the filter and number of lines in the log.

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=691010&r1=691009&r2=691010&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Mon Sep  1 09:09:40 2008
@@ -104,6 +104,7 @@
 <li>Added __unescapeHtml() function: decodes Html-encoded text.</li>
 <li>Added __escapeHtml() function: encodes text using Html-encoding.</li>
 <li>Allow spaces in JMeter path names (apply work-round for Java bug 
4496398)</li>
+<li>Bug 45694 - Support GZIP compressed logs</li>
 </ul>
 
 <h3>Non-functional changes</h3>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to