Hi All,
Can someone show me how to override the 
PostMethod.addContentLengthRequestHeader() to do nothing? I am not very 
familiar with the HttpClient documentation.

Cheers,
Manohar


On 7/18/05, Michael Schwager <[EMAIL PROTECTED]> wrote:
> 
> Ahhh... got it! Thanks again, Mike and Gustavo, for your help. I
> can't use the InputStream as such, because it is an abstract class...
> just for starters. And I have to keep reading from the
> BufferedInputStream until I get -1. ...Ehm, I knew that... :-) Guess
> I'm a little freaked out now having to learn a whole new body of
> knowledge with this http-client, and I'm missing the obvious...
> anyway...
> 
> Mike, I see what you're doing with the ByteArrayOutputStream(), and
> that's a good way, but because I'm fixated on copy the input stream
> directly to a byte array I ended up doing the following (also, I want
> to protect my application against any website that may have a bogus,
> really really large, image). Note that 2048 is the default buffer
> size of a Buffered InputStream but I wanted to be explicit so that the
> BIS.read() and check for the large filesize were all obviously in sync
> with each other:
> 
> final int MAXBYTES=100000;
> byte[] inputBytes=new inputBytes[MAXBYTES];
> InputStream IS = method.getResponseBodyAsStream();
> BufferedInputStream BIS = new BufferedInputStream(IS, 2048);
> while ((returnCode = BIS.read(inputBytes, i, 2048)) != -1) {
> i+=returnCode;
> if (i>=MAXBYTES-2048) {
> System.err.println("Image is too large!");
> throw (new java.io.IOException());
> }
> }
> icon = new ImageIcon(inputBytes);
> 
> On 7/14/05, Michael Becke <[EMAIL PROTECTED]> wrote:
> > Hi Michael,
> >
> > As Gustavo has said you need to read the response stream until it
> > returns -1. This indicates that all data has been read. You have two
> > options.
> >
> > - buffer the content manually:
> >
> > byte[] temp = new byte[1024];
> > int length = 0;
> > ByteArrayOutputStream buffer = new ByteArrayOutputStream();
> >
> > InputStream is = get.getResponseBodyAsStream();
> > while ((length = is.read(temp)) != -1) {
> > buffer.write(temp, 0, length);
> > }
> > ImageIcon icon = new ImageIcon(buffer.toByteArray());
> >
> > - or:
> >
> > ImageIcon icon = new ImageIcon(get.getResponseBody());
> >
> > Mike
> >
> > On 7/14/05, Michael Schwager <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > > Java: 1.4.2 HttpClient: 3.0 rc3
> > > If I want to display a PNG file as an ImageIcon, ...
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

Reply via email to