Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to seek in ByteArrayOutputStream and ByteArrayInputStream?

807569Jul 17 2006 — edited Jul 21 2006
Hi.

I have a class whose structure is similar to a TCP packet ( packet header, packet data)

So i want to read first packet's data(in order to read data's size in bytes) and then fill the packet's header.
To do this i have to seek into the stream forward (to the packet's data start point) and then backward (to the packet's start point).

I have this application in C# and the code for seeking looks like this

BinaryWriter writer = new BinaryWriter(mBuffer);
writer.Seek(0, SeekOrigin.Begin);

where mBuffer is a MemoryStream object;


To adapt it in java i have made these convertions:
MemoryStream converted to ByteArrayOutputStream.

BinaryWriter converted to
BufferedOutputStream bos = new BufferedOutputStream(mBuffer);
		DataOutputStream writer=new DataOutputStream(bos);
where mBuffer is a ByteArrayOutputStream object;


Searching the java API i didn't found any seek method in class DataOutputStream neither to it's super classes in java.io hierarchy.

So how can i seek forward and backward in ByteArrayOutputStream and ByteArrayInputStream objects?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2006
Added on Jul 17 2006
9 comments
229 views