--- dao/DaoAdresseService/src/dk/daoas/daoadresseservice/util/HttpUtil.java 2015/02/17 09:06:42 2321 +++ dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/util/HttpUtil.java 2015/03/20 13:57:47 2457 @@ -114,6 +114,7 @@ URLConnection connection = url.openConnection(); connection.setConnectTimeout(timeout); + connection.setReadTimeout(timeout); InputStream is = connection.getInputStream(); return readInputStream(is); @@ -137,20 +138,16 @@ 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 { + //try /; //start buffer size - instead of default 32bytes + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(32768)) { 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(); + is.close(); + return baos.toByteArray(); + } } }