BufferedOutputStream being padded with spaces?

H

hystable

Can anyone help me? I've got an EJB that has a BufferedOutputStream
which writes a byte[] out to a socket. When this byte[] comes into the
EJB, there are no spaces at the end. When the byte[] leaves the EJB,
there are spaces added to the end of it. It seems like maybe the
BufferedOutputStream is filling the buffer with spaces (apparently
about 160)? Has anyone heard of this before? Here's basically what I'm
doing:

public byte[] sendsock(byte[] authrequest) throws IOException
echoSocket = new Socket(testIP, testPort);
outBuffStream = new
BufferedOutputStream(echoSocket.getOutputStream());
outBuffStream.write(authrequest);

Does anyone have any ideas as to how the spaces would be getting
introduced into the byte[]?

Thanks in advance.

Curtis
 
J

jan V

EJB, there are no spaces at the end. When the byte[] leaves the EJB,
there are spaces added to the end of it. It seems like maybe the
BufferedOutputStream is filling the buffer with spaces (apparently
about 160)? Has anyone heard of this before?

Nope. And I'd say, trust me, BufferedOutputStream does not alter the flow of
bytes going through it in any way.
Does anyone have any ideas as to how the spaces would be getting
introduced into the byte[]?

Why don't you use a debugger and single-step through your code? You should
be able to find the culprit yourself pretty fast this way..
 
E

Esmond Pitt

Does anyone have any ideas as to how the spaces would be getting
introduced into the byte[]?

I would guess that you are putting them there at some point on the
target side, and that you are ignoring the return value of the read(),
assuming that the entire array got read.
 
H

HalcyonWild

I suppose you should not be using the Buffered streams for such things.
I have faced similar problems with File IO using Buffered streams.
I was reading data from a DB, and writing it to a file.
While writing to a file with Buffered Stream, I noticed it truncated
some bytes (instead of adding spaces). I used a simple FileOutputStream
and the problem was solved.
 
T

Thomas Hawtin

HalcyonWild said:
I suppose you should not be using the Buffered streams for such things.
I have faced similar problems with File IO using Buffered streams.
I was reading data from a DB, and writing it to a file.
While writing to a file with Buffered Stream, I noticed it truncated
some bytes (instead of adding spaces). I used a simple FileOutputStream
and the problem was solved.

I'd like to see that explained with reference to the source code.

More likely the buffered stream isn't filling up your array completely,
as it need not. If there is some data buffered it will not read anything
from the underlying stream (or at least the version in front of behaves
like that).

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top