commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From George Armhold <armh...@cs.rutgers.edu>
Subject Re: [HttpClient] GetMethod.getResponseBody().available() for download estimation?
Date Tue, 02 Mar 2004 12:20:33 GMT
Well I've been able to get a ProgressMonitorInputStream working with
GetMethod.  I can now get a ProgressMonitor to pop up for my
downloads.  I've had to wrap the InputStream returned from
getResponseBodyAsStream() with a FilterInputStream that returns the
contentLength for available().  I also had to extend GetMethod to make
getResponseContentLength() public.  Why is it protected??  This is
kind of ugly, but it works.

/**
  * supply a hard-coded value for available() method.
  */
class FixedInputStream extends FilterInputStream {
   private int contentLength;

   public FixedInputStream(InputStream is,
			  int contentLength) {
     super(is);
     this.contentLength = contentLength;
   }

   public int available() throws IOException {
     return contentLength;
   }
}

/**
  * expose protected method getResponseContentLength.
  */
class FixedGetMethod extends GetMethod {

   public FixedGetMethod(String url) {
     super(url);
   }

   public int getResponseContentLength() {
     return super.getResponseContentLength();
   }
}



-- 
George Armhold
Rutgers University
eLearning Grant, DCIS


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message