From: <bra...@us...> - 2010-03-20 01:14:14
|
Revision: 2991 http://archive-access.svn.sourceforge.net/archive-access/?rev=2991&view=rev Author: bradtofel Date: 2010-03-20 01:14:08 +0000 (Sat, 20 Mar 2010) Log Message: ----------- FEATURE: actually tries to devine if a stream is chunked or not before setting the chunked inputs stream wrapper. Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java 2010-03-20 01:11:51 UTC (rev 2990) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/Resource.java 2010-03-20 01:14:08 UTC (rev 2991) @@ -66,8 +66,49 @@ */ public void setChunkedEncoding() throws IOException { validate(); - is = new ChunkedInputStream(is); + // peek ahead and make sure we have a line with hex numbers: + int max = 50; + is.mark(max+2); + int cur = 0; + boolean isChunked = false; + while(cur < max) { + int nextC = is.read(); + if(nextC == 10) { + // must have read at least 1 hex char: + if(cur > 0) { + nextC = is.read(); + if(nextC == 13) { + isChunked = true; + break; + } + } + } else { + // better be a hex character: + if(!isHex(nextC)) { + break; + } + } + cur++; + } + is.reset(); + if(isChunked) { + is = new ChunkedInputStream(is); + } } + + private boolean isHex(int c) { + if((c >= '0') && (c <= '9')) { + return true; + } + if((c >= 'a') && (c <= 'f')) { + return true; + } + if((c >= 'A') && (c <= 'F')) { + return true; + } + return false; + } + /** * @return * @throws IOException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |