How to use both ObjectStream and ByteArrayStream to access one file?

Z

ZelluX

Hello, I want to write a simple Zip compression and decompression tool
in Java.

Now I'm confronted with a problem,
i store compression infomation in a serializable HuffmanTree, and use
ObjectOutputStream to write the whole tree in a binary file, after
that, i append compressed bytes to the end of the file.

When decompressing, how can i first get the HuffmanTree out of the
file and then read compressed bytes from the file?

Or any better solution to this problem?

Many thanks.
 
Z

ZelluX

ask the file I/O amanuensis to generate you some code.
Just tick off "read", "compressed", "serialised binary objects"

seehttp://mindprod.com/applet/fileio.html

Thanks for that.

But what if i want to write the compression code myself?
then how to store both the tree and the compressed infomation in a
file?
 
B

bcr666

Thanks for that.

But what if i want to write the compression code myself?
then how to store both the tree and the compressed infomation in a
file?

I would just make the compressed information a Serializable Object,
then just write it to the ObjectOutputStream after the tree.
 
G

Gordon Beaton

Now I'm confronted with a problem, i store compression infomation in
a serializable HuffmanTree, and use ObjectOutputStream to write the
whole tree in a binary file, after that, i append compressed bytes
to the end of the file.

It will hurt when you do that. Don't.

Store either both as serialized Objects or both as "bytes" in the
file, don't try to be too clever. Read Thing 1 and Thing 2 from the
file using one kind of stream, and separate them in your code.

/gordon

--
 
R

Roedy Green

But what if i want to write the compression code myself?
then how to store both the tree and the compressed infomation in a
file?

You use that code as a model. You write your own class to replace the
GZIP.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top