/[projects]/android/SmsSend/src/dk/thoerup/smssend/SmsSend.java
ViewVC logotype

Diff of /android/SmsSend/src/dk/thoerup/smssend/SmsSend.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 751 by torben, Wed May 26 07:44:39 2010 UTC revision 752 by torben, Wed May 26 07:55:04 2010 UTC
# Line 330  public class SmsSend extends Activity { Line 330  public class SmsSend extends Activity {
330                    
331                    
332          public static byte[] getContent(String uri, int timeout) throws IOException {          public static byte[] getContent(String uri, int timeout) throws IOException {
                 byte buffer[] = new byte[256];  
                   
                 ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes  
                   
333                  URL url = new URL(uri);                  URL url = new URL(uri);
334                  URLConnection connection = url.openConnection();                  URLConnection connection = url.openConnection();
335                  HttpURLConnection c;                  
336                  connection.setConnectTimeout(timeout);                  connection.setConnectTimeout(timeout);
337                  InputStream is = connection.getInputStream();                  InputStream is = connection.getInputStream();
338                                    
339                  try {                  return readInputStream(is);
                         int count;  
                         while ( (count = is.read(buffer)) != -1) {  
                                 baos.write(buffer, 0, count);  
                         }  
                 } finally {  
                         try {  
                                 is.close();  
                                 baos.close();  
                         } catch (Exception e) {} //never mind if close throws an exception  
                 }  
                                   
                 return baos.toByteArray();  
340          }          }
341                    
342          public static byte[] postContent(String uri, String data,  int timeout) throws IOException {          public static byte[] postContent(String uri, String data,  int timeout) throws IOException {
                 byte buffer[] = new byte[256];  
                   
                 ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes  
                   
343                  URL url = new URL(uri);                  URL url = new URL(uri);
344                  HttpURLConnection connection = (HttpURLConnection) url.openConnection();                  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
345                  connection.setDoOutput(true);                  connection.setDoOutput(true);
# Line 371  public class SmsSend extends Activity { Line 351  public class SmsSend extends Activity {
351                                    
352                  InputStream is = connection.getInputStream();                  InputStream is = connection.getInputStream();
353                                    
354                    return readInputStream(is);
355    
356            }
357            
358            static byte[] readInputStream(InputStream is) throws IOException{
359                    byte buffer[] = new byte[1024];
360                    ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes
361                  try {                  try {
362                          int count;                          int count;
363                          while ( (count = is.read(buffer)) != -1) {                          while ( (count = is.read(buffer)) != -1) {
# Line 383  public class SmsSend extends Activity { Line 370  public class SmsSend extends Activity {
370                          } catch (Exception e) {} //never mind if close throws an exception                          } catch (Exception e) {} //never mind if close throws an exception
371                  }                  }
372                                                                    
373                  return baos.toByteArray();                  return baos.toByteArray();              
374          }          }
375    
376          OnItemSelectedListener methodSelected = new OnItemSelectedListener() {          OnItemSelectedListener methodSelected = new OnItemSelectedListener() {

Legend:
Removed from v.751  
changed lines
  Added in v.752

  ViewVC Help
Powered by ViewVC 1.1.20