0

The POST Message response that is returned from the server to my Android app is an essay. The String datatype unfortunately cannot store the entire essay.

Can you suggest a data-type i can use like this:

HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();

String result = EntityUtils.toString(resEntity);

when i System.out.println(result) it doesn't show me the entire essay.

user3760741
  • 163
  • 1
  • 1
  • 10
  • 2
    Two strings? Or maybe three? – Theolodis Jul 09 '14 at 19:11
  • 1
    What is the actual limitation you are seeing, in Java? In your database? From [what I am reading](http://stackoverflow.com/questions/1179983/how-many-characters-can-a-java-string-have) an essay should not go over the max amount of characters a string can hold. However, you may want to look at your heap size according to that post I linked – chancea Jul 09 '14 at 19:15
  • You should be able to get a string of max length java.lang.Integer.MAX_VALUE which is 2147483647 or (2^31 - 1). Is your string is of greater length than this? – Srikanth Ganji Jul 09 '14 at 19:17
  • How can i detect when the string becomes full – user3760741 Jul 09 '14 at 19:18
  • a string is full from what both Srikanth Ganji and I said, at (2^31 -1) characters long. Or at half your maximum heap size. – chancea Jul 09 '14 at 19:19
  • See [how-many-characters-can-a-java-string-have](http://stackoverflow.com/questions/1179983/how-many-characters-can-a-java-string-have) and [strings-maximum-length-in-java-calling-length-method](http://stackoverflow.com/questions/816142/strings-maximum-length-in-java-calling-length-method) – azurefrog Jul 09 '14 at 19:19
  • 3
    I very, *very* much doubt that the problem is actually that the value is larger than the theoretical capabilities of `String`. You may be running out of memory, but that's a different matter. Unfortunately, you haven't described the actual failure. – Jon Skeet Jul 09 '14 at 19:20
  • when i System.out.println(result) it doesnot display the entire essay – user3760741 Jul 09 '14 at 19:21
  • 3
    That doesn't mean that result doesn't have the data, just that you're having an issue printing it. Compare `result.length()` to the length of the essay on the server. – azurefrog Jul 09 '14 at 19:24
  • @user3760741 That's a limitation of `System.out.println` on your JVM, not of the `String` type. – GriffeyDog Jul 09 '14 at 19:29
  • If the server is from your own development, you may want to consider some other way of storing and transmitting essays. Binary or XML. – ADTC Jul 10 '14 at 02:06

1 Answers1

10

I don't think that this is String size problem.

Eg.

An A4 page covered with characters stores about 5000 characters. Acording to this, the maximum length of String is 2147483647 characters.

2147483647/5000 = 429496 pages

The Encyclopædia Britannica has 32640 pages and about 44000000 words with average 6.1 characters per word.

Why are you trying to send 8 Encyclopædias?

Community
  • 1
  • 1
nervosol
  • 1,295
  • 3
  • 24
  • 46