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.
Roedy Green - 24 Oct 2007 13:08 GMT
>When decompressing, how can i first get the HuffmanTree out of the
>file and then read compressed bytes from the file?
ask the file I/O amanuensis to generate you some code.
Just tick off "read", "compressed", "serialised binary objects"
see http://mindprod.com/applet/fileio.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
ZelluX - 24 Oct 2007 13:44 GMT
On 10 24 , 8 08 , Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> >When decompressing, how can i first get the HuffmanTree out of the
> >file and then read compressed bytes from the file?
[quoted text clipped - 6 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
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?
bcr666 - 24 Oct 2007 15:48 GMT
> On 10 24 , 8 08 , Roedy Green <see_webs...@mindprod.com.invalid>
> wrote:
[quoted text clipped - 15 lines]
> 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.
Roedy Green - 24 Oct 2007 20:52 GMT
>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.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Gordon Beaton - 24 Oct 2007 16:18 GMT
> 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
--