This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Size Limitation in BASE64Encoder

 
Nobutaka Fukuhara
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
I have a problem. I tried to encode 15MB bytes data(byte[]) by sun.misc.Base64Encoder.encode() but "CharacterEncoder::encodeBuffer internal error" was occurred .
Is it the limitation?
If you know the reason or some information, please give it to me.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried increasing the memory available to your application?
I'm thinking that the default behaviour for the encoder would be to load the binary data (15Mb in you case) then convert to Base64 and return the String.
The output from Base64 encoding is longer than the input, essentially it returns 4 bytes output for every 3 bytes input. Therefore your output is 20Mb, and it's trying to hold all this in memory.
You might want to look at the algorithm for Base64 encoding and create a streaming version. That is a program that reads 3 bytes, encodes it and writes 4 bytes then gets the next chunk.
If you wrapped Buffered Streams around this you would probably still get acceptable performance.
Dave
 
Nobutaka Fukuhara
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I'll checke it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!