private static final byte [] EMPTYBYTEARRAY = new byte [0];
/**
* Ensure all remaining data will be output.
*/
public void flush() throws IOException {
if( def.finished() ) return;
/**
* Now this is tricky: We force the Deflater to flush
* its data by switching compression level.
* As yet, a perplexingly simple workaround for
* http://developer.java.sun.com/developer/bugParade/bugs/4255743.html
*/
def.setInput(EMPTYBYTEARRAY, 0, 0);
def.setLevel(Deflater.NO_COMPRESSION); deflate();
def.setLevel(Deflater.DEFAULT_COMPRESSION); deflate();
super.flush(); }
The other thing you have to be careful of when using DeflaterOutputStream or InflaterInputStream is spurious NullPointerExceptions from native code if the connection happens to close while a deflate/inflate is being performed. We worked around that particular problem by extending the 'read' of the InflaterInputStream and the 'deflate' call of the DeflaterOutputStream to catch an NPE and rethrow an IOX.
Thanks, Sam
otisg wrote:
I'm not too familiar with HttpClient source code any more, but it seems to me that this should be easy to add. Please correct me if I am wrong. I will be using HttpClient to pull large amounts of data from the web in a few months, and allowing compressed content may translate to less bandwidth and a lower hosting bill :)
Otis
________________________________________________ Get your own "800" number Voicemail, fax, email, and a lot more http://www.ureach.com/reg/tag
---- On Mon, 17 Nov 2003, =?ISO-8859-15?Q?Sven_K=F6hler?= ([EMAIL PROTECTED]) wrote:
Hi,may answer
If i send the right accept-encoding headers, the web-server
with a gzip or deflate compressed stream. Does HttpClientdecompress it?
If yes, how can i turn that off?---------------------------------------------------------------------
To unsubscribe, e-mail:[EMAIL PROTECTED]
For additional commands, e-mail:[EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]