1

I would like to assign a text which is 10kbyte or 100Kbyte to a string . In Java am not able to assign text with more than 16kb size .Any idea on how to assign long text to longEnglishText in the code snippet below, will be appreciated.

My Junit code is :

@Test
public void testLongEnglishTextSentimentWithXML() {
    Form form = new Form();
    form.param("text", longEnglishText);
    form.param("outputMode", "xml");
    Response resp = 
            target.path("serviceURL").request().post(Entity.form(form));
    assertEquals(resp.getStatus(), 200);
    Result  result = resp.readEntity(Result.class);
    assertEquals("ERROR", result.getStatus());
    assertEquals("outofMemory-error",result.getStatusInfo());
}

Thanks, Divya

gkrls
  • 2,618
  • 2
  • 15
  • 29
user1477232
  • 457
  • 1
  • 8
  • 17
  • 4
    put the text into a longtext.txt file and read the file? – Absurd-Mind Aug 13 '14 at 12:49
  • StringBuilder with n KB chunks in a loop? – TJ- Aug 13 '14 at 12:50
  • 1
    Out of curiosity, what Java environment limits Strings to 16kb? You should add that to tags. – Torben Aug 13 '14 at 12:51
  • what is Form class here? – Adi Aug 13 '14 at 12:52
  • it represents HTML form. isn't there limitation on http request data size that can go with request? – Adi Aug 13 '14 at 12:57
  • @Torben The limit comes from [static constrains in JLS](http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#9279). A Java file can not be bigger than 64K. The maximum string literal size ranges therefore between around 10,6K (6 bytes per char) and 64K (1 byte per char == pure ASCII string). (16K if you take 4 Bytes per char) – Absurd-Mind Aug 13 '14 at 13:00

1 Answers1

0

So what you actually want to do is define string constants larger than 64kB and use it in your unit test. Can't do that. You have to create a workaround.

https://stackoverflow.com/a/2738598/1047418

Community
  • 1
  • 1
Torben
  • 3,805
  • 26
  • 31