Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes After encoding data size is increasing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "After encoding data size is increasing" Watch "After encoding data size is increasing" New topic
Author

After encoding data size is increasing

Siddesh Basapura
Greenhorn

Joined: Nov 03, 2010
Posts: 4
Hi,

I am having a text data in XML format and it's length is around 816814 bytes. It contains some image data as well as some text data.
We are using ZLIB algorithm for compressing and after compressing, the compressed data length is 487239 bytes.

After compressing we are encoding data using BASE64Encoder. But after encoding the compressed data, size is increasing and length of encoded data is 666748 bytes.

Why after encoding, data size is increasing? Is there any other best encoding techniques?

Regards,
Siddesh
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Siddesh Bm wrote:
After compressing we are encoding data using BASE64Encoder. But after encoding the compressed data, size is increasing and length of encoded data is 666748 bytes.

Why after encoding, data size is increasing? Is there any other best encoding techniques?


That's how base64 encoding works... it takes bytes which has 256 possible values and limits them to only 64 possible values (plus one or two for control purposes). These values are limited to the ASCII printable range, and hence, can pass through systems that will choke on binary data.

So what happens when 8 bits of a byte must fit into bytes that effectively only has 5 bits ? Obviously, you need more bytes.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11418
    
  16

encoding is NOT the same thing as compression, as you probably know.

Base64 is often used on binary data that needs to be transmitted across a system that isn't really designed for binary. Depending on what you're doing, you may not even need to encode it. And per the wikipedia, on average, a file is expected to grow about 37% when you base64 encode it, which is almost exactly what your numbers are.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Siddesh Basapura
Greenhorn

Joined: Nov 03, 2010
Posts: 4
Hi Guys,

Thanks for the replay.
Now i come to know how BASE64 encoder will works by looking you replay and after gone through the wiki link "http://en.wikipedia.org/wiki/Base64#Examples".


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: After encoding data size is increasing