0

Possible Duplicate:
OutOfMemoryError : When receiving XML response of 2.3 MB

I got the responds string from the web service which is the large amount of Binary string in XML format. I can able to store the respond data into the Object. but i want to parse the respond and store that into the local data base. so i have to convert the object data to String. If i convert the object data to string. It occurs "Memory issue".

my respond is like this

<xmlstring>
<oneslip>78364</oneslip>
<threeslip>Hello</threeslip>
<twoslip>3</twoslip>
<Binarydata>"Here the large amount of binary data"</Binarydata>

<oneslip>78364</oneslip>
<threeslip>Hello</threeslip>
<twoslip>3</twoslip>
<Binarydata>"Here the large amount of binary data"</Binarydata>

..
..
..

Upto 50

</xmlstring>
Community
  • 1
  • 1
Rajesh Rajaram
  • 3,271
  • 4
  • 29
  • 48

2 Answers2

0

Try StringBuffer

bufferedReader = new BufferedReader(
                     new InputStreamReader(
                         response.getEntity().getContent()));

StringBuffer stringBuffer = new StringBuffer("");
String line = "";
String LineSeparator = System.getProperty("line.separator");

while ((line = bufferedReader.readLine()) != null) {
    stringBuffer.append(line + LineSeparator); 
}

bufferedReader.close();
posdef
  • 6,498
  • 11
  • 46
  • 94
Froyo
  • 455
  • 1
  • 8
  • 21
  • Why not `StringBuilder`? Firstly, why `String` does not accept large size data? Did we try finding the reason for this? – overexchange Jul 10 '17 at 18:28
0

If your database represents the data as binary (as opposed to character), then using an intermediate string seems the wrong way to do this. You could use Blob.setBinaryStream to obtain a stream for writing the data to the db. Then you could transfer things to that stream in manageable chunks, directly from your input stream to the output stream, without having to buffer the whole thing.

If you want to transfer the whole content of the input stream, without even looking at it, you could even set the BLOB column directly to the data from that stream using CallableStatement.setBlob(String,InputStream).

If you have to convert things to character, as the database uses a clob instead of a blob, then similar approaches exist for clob as well, and you could still avoid the intermediate String.

MvG
  • 57,380
  • 22
  • 148
  • 276