--- android/SmsSend/src/dk/thoerup/smssend/SmsSend.java 2010/05/26 07:44:39 751 +++ android/SmsSend/src/dk/thoerup/smssend/SmsSend.java 2010/05/26 07:55:04 752 @@ -330,36 +330,16 @@ 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 - URL url = new URL(uri); URLConnection connection = url.openConnection(); - HttpURLConnection c; + connection.setConnectTimeout(timeout); InputStream is = connection.getInputStream(); - try { - 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(); + return readInputStream(is); } 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 - URL url = new URL(uri); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); @@ -371,6 +351,13 @@ InputStream is = connection.getInputStream(); + return readInputStream(is); + + } + + static byte[] readInputStream(InputStream is) throws IOException{ + byte buffer[] = new byte[1024]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes try { int count; while ( (count = is.read(buffer)) != -1) { @@ -383,7 +370,7 @@ } catch (Exception e) {} //never mind if close throws an exception } - return baos.toByteArray(); + return baos.toByteArray(); } OnItemSelectedListener methodSelected = new OnItemSelectedListener() {