InputStream do not read properly

Hello,
Can you say me, where I make a mistake.
I am writing a proxy.When I read from InputStream in,
like:
try {
byte[] buf = new byte[4096];
int bytesIn = 0;
while (((bytesIn = in.read(buf)) >= 0))
{
String sss1 = new String(buf);
out.write(buf, 0, bytesIn);
}
} catch (Exception e) {
String errMsg = "Error getting HTTP body: " + e;
debugOut.println(errMsg);
}

So,when I look in sss1 contents,there have extra information like:

3

79
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3a
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
2d

The result is incorrect page displaying.
Can you say me, where I make a mistake.
Or how I can remove this extra information, so that page can to display correct in the browser.
[1436 byte] By [dani_b_angelov] at [2007-11-20 8:17:42]
# 1 Re: InputStream do not read properly
public String(byte[] bytes)

Constructs a new String by decoding the specified array of bytes using the platform's default charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

The behavior of this constructor when the given bytes are not valid in the default charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required.

Parameters:
bytes - the bytes to be decoded into characters
Since:
JDK1.1

It seems that the charset is using something and modifying the lenght of the String as the text above says.
Gurzi at 2007-11-10 2:15:26 >
# 2 Re: InputStream do not read properly
Or how I can remove this extra information, so that page can to display correct in the browser.Have you tried using an InputStreamReader (http://java.sun.com/javase/6/docs/api/java/io/InputStreamReader.html)? This is the standard bridge from byte streams to character streams.

Furious activity is no substitute for understanding...
H.H. Williams
dlorde at 2007-11-10 2:16:26 >
# 3 Re: InputStream do not read properly
Did you saw the length of the buf array ??

When you use the out.write you are using an offset, try seeing if the buf lenght is greater that the offset that you used in the out.write
Gurzi at 2007-11-10 2:17:26 >
# 4 Re: InputStream do not read properly
I found the problem.
This happends when in the header is set "Transfer-Encoding: chunked".
So that extra info is from chunk.
Thanks
dani_b_angelov at 2007-11-10 2:18:31 >
# 5 Re: InputStream do not read properly
Thanks for letting us know the solution :thumb:

We [teachers] make the road, others will make the journey...
V. Hugo
dlorde at 2007-11-10 2:19:33 >