• Post Reply Bookmark Topic Watch Topic
  • New Topic

maximum size of String  RSS feed

 
sakuja jangra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I have got a condition where I have to pass a string to a web service. ealier this service was accepting parameter as CSV file but now that's taking that parameter as String. I have to pass the String with the condition that size of String cant be greater than 80 MB. I know this is bad design but cant think of any other option at present(due to time constraint and contract with the web service).
My question is how can we decide the size of String doesn't cross 80 MB(It can be somewhat less for that matter). I hope that is based on JVM allocation of memory. but I want that independant of that. I searched internet but couldn't find any pointer towards that.

Please help. thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please reserve this forum for adbanced Java questions. I have moved this post to a more appropriate forum.
 
Joe Ess
Bartender
Posts: 9439
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not aware of any defined limit but String.length() returns an int, so the length is practically limited to Integer.MAX_VALUE (give or take for encoding). If you are seeing an OutOfMemoryError, that's because the default heap size for the JVM is 64 Megs. You can control the heap size through the -Xmx command line parameter described here.
 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Within the JVM, each char in a String requires two bytes- -so Paul's answer requires an extra factor of two. However if you're not sure that the JVM memory usage is what's required here, then several other answers are possible. Possibly your clients want to know that the string content will fit in a file with maximum size 80 Mb, for example. If that's the case, you would need to know what type of file encoding is used. And if the encoding is a variable-length encoding such as UTF-8, then different chars require different numbers of bytes (from 1-3 each) and you would need to know about the content of each String in order to answer this question. So, I think you need to find out where this requirement is really coming from, and what exactly they think it means.
 
sakuja jangra
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!