How to create a datastore.Text object out of an array of dynamically created Strings?

Posted by Adrogans on Stack Overflow See other posts from Stack Overflow or by Adrogans
Published on 2014-08-20T22:16:45Z Indexed on 2014/08/20 22:20 UTC
Read the original article Hit count: 103

Filed under:
|
|

I am creating a Google App Engine server for a project where I receive a large quantity of data via an HTTP POST request.

The data is separated into lines, with 200 characters per line. The number of lines can go into the hundreds, so 10's of thousands of characters total.

What I want to do is concatenate all of those lines into a single Text object, since Strings have a maximum length of 500 characters but the Text object can be as large as 1MB.

Here is what I thought of so far:

public void doPost(HttpServletRequest req, HttpServletResponse resp)
{
...

String[] audioSampleData = new String[numberOfLines];

for (int i = 0; i < numberOfLines; i++)
{
  audioSampleData[i] = req.getReader().readLine(); 
}

com.google.appengine.api.datastore.Text textAudioSampleData = new 
                         Text(audioSampleData[0] + audioSampleData[1] + ...);

...
}

But as you can see, I don't know how to do this without knowing the number of lines before-hand. Is there a way for me to iterate through the String indexes within the Text constructor? I can't seem to find anything on that.

Of note is that the Text object can't be modified after being created, and it must have a String as parameter for the constructor. (Documentation here)

Is there any way to this? I need all of the data in the String array in one Text object.

Many Thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about string