I am trying to do the following and don't know where things are blowing up.
Step 1. Read a small XML file.
Step 2. Using java.util.zip, Deflate that file.
Step 3. Using Base64, encode the deflated byte array and write it to a
file.
Step 4. Some foolin around stuff goes on not related to the above, coffee
and donuts kind of thing...
Step 5. Using Base64, decode the above, saved file. Note: get an error
here, see below.
Step 6. Using java.util.zip, Inflate the byte array
Step 7. Use the reconstituted XML and continue on with my life in a smiling
manner...
When I have all the pieces put together in 3 files, (Deflate, Inflate and
Base64) I get the following error when I try to Inflate...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Input
to decode
not an even multiple of 4 characters; pad with =.
at Base64.decode(Base64.java:187)
at DirectInflater.main(DirectInflater.java:24)
The annoying thing is that if I comment out the Base64 steps the
Deflate/Inflate routines work great. If I comment out the Deflate/Inflate
and
just do the Encode/Decode parts it works great too! It's only when I try to
put the pieces together that it chokes.
Does anyone have any experience they could offer? If anyone would like I
can send the source for this "proof of concept". The Inflate and Deflate
code is a modified version of the examples found in a book called Java I/O
by Elliotte Harold and the Base64 code is from Roedy Green's site,
unchanged. The XML file is irrelevant and in fact the code chokes on any
file I give it. I have tried other Base64 examples including the
undocumented Encoder and Decoder in the sun packages, all with the same
result. Any ideas anyone?
Thanks in advance,
Greg Sliker
Have you verified that the encoded file is in fact a multiple of four? If not,
you can pad the end as a workaround.
Thanks for the reply and I'll working away at it.
Greg Sliker
"Ken Kalish" <kk...@javakk.com> wrote in message
news:3b63d8d6...@news.earthlink.net...
>From what I read regarding the Base64 method I would have thought that it
>would take care of the padding for me (with "=" as needed).
my version of Base64 does. See Base64 in the Java glossary.
For more detail, please look up the key words mentioned in this post in
the Java Glossary at: http://mindprod.com/gloss.html
--
Roedy Green, Canadian Mind Products
Custom computer programming since 1963. Ready to take on new work.