I am trying to call a web service, the response contains a big string, getting out of memory issue the code is
 URL u = new URL(SharedVariables.server);
           URLConnection uc = u.openConnection();
           HttpURLConnection connection = (HttpURLConnection) uc;
           connection.setConnectTimeout(SharedVariables.connectionTimedOutValue);
           connection.setDoOutput(true);
           connection.setDoInput(true);
           connection.setRequestProperty("SOAPAction", SOAP_ACTION);
           connection.setRequestMethod("POST");
           connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");
           String xmldata = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
                            "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> "+ 
                            "<soap:Body>"+
                            "<GetCaseCriminalTicketLinks xmlns=\"http://tempuri.org/\">"+   
                            Req.getRequestXml()+                            
                            "</GetCaseCriminalTicketLinks>"+
                            "</soap:Body>"+
                            "</soap:Envelope>";        
           OutputStream out = connection.getOutputStream();
                Writer wout = new OutputStreamWriter(out);
                wout.write(xmldata);
                wout.flush();                   
                out.flush();                    
              BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()),8 * 1024);
              String result;    
              while ((result=rd.readLine()) != null) {
              int length = result.length();               
               String temp = result.substring(316, (length - 100));           
               JSONObject tempJson = new JSONObject(temp);}
The log is
Caused by: java.lang.OutOfMemoryError
at java.lang.String.<init>(String.java:513)
at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:650)
at java.lang.StringBuilder.toString(StringBuilder.java:664)
at java.io.BufferedReader.readLine(BufferedReader.java:398)
this line is causing
while ((result=rd.readLine()) != null) 
Any suggestions ?
Thanks
 
     
    