[Htmlparser-cvs] htmlparser/src/org/htmlparser/lexer Page.java,1.35,1.36
Brought to you by:
derrickoswald
From: Derrick O. <der...@us...> - 2004-05-23 19:42:24
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32030 Modified Files: Page.java Log Message: Incorporate feature request submitted by Bradford A. Folkens #943197 Accept gzip / deflate content encodings by setting request property "Accept-Encoding" to "gzip, deflate" in Page.setConnection(), if possible, and handling those encodings. No test case added because it needs a specially configured HTTP server. Index: Page.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/Page.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Page.java 7 May 2004 23:30:37 -0000 1.35 --- Page.java 23 May 2004 19:42:14 -0000 1.36 *************** *** 40,43 **** --- 40,45 ---- import java.net.URLConnection; import java.net.UnknownHostException; + import java.util.zip.GZIPInputStream; + import java.util.zip.InflaterInputStream; import org.htmlparser.util.EncodingChangeException; *************** *** 319,326 **** --- 321,337 ---- String type; String charset; + String contentEncoding; mConnection = connection; try { + try + { + getConnection ().setRequestProperty ("Accept-Encoding", "gzip, deflate"); + } + catch (IllegalStateException ise) // already connected + { + // assume all request properties have already been set + } getConnection ().connect (); } *************** *** 343,347 **** try { ! stream = new Stream (getConnection ().getInputStream ()); try { --- 354,370 ---- try { ! contentEncoding = connection.getContentEncoding(); ! if ((null != contentEncoding) && (-1 != contentEncoding.indexOf ("gzip"))) ! { ! stream = new Stream (new GZIPInputStream (getConnection ().getInputStream ())); ! } ! else if ((null != contentEncoding) && (-1 != contentEncoding.indexOf ("deflate"))) ! { ! stream = new Stream (new InflaterInputStream (getConnection ().getInputStream ())); ! } ! else ! { ! stream = new Stream (getConnection ().getInputStream ()); ! } try { |