Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2005

Tip: Looking for answers? Try searching our database.

BufferedOutputStream being padded with spaces?

Thread view: 
hystable@yahoo.com - 01 Aug 2005 18:33 GMT
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
jan V - 01 Aug 2005 19:07 GMT
> 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..
Esmond Pitt - 02 Aug 2005 02:27 GMT
> 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.
HalcyonWild - 03 Aug 2005 20:00 GMT
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.
Thomas Hawtin - 03 Aug 2005 20:27 GMT
> 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
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.