137 |
|
|
138 |
static byte[] readInputStream(InputStream is) throws IOException{ |
static byte[] readInputStream(InputStream is) throws IOException{ |
139 |
byte buffer[] = new byte[1024]; |
byte buffer[] = new byte[1024]; |
140 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes |
//try /; //start buffer size - instead of default 32bytes |
141 |
try { |
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(32768)) { |
142 |
int count; |
int count; |
143 |
|
|
144 |
while ( (count = is.read(buffer)) != -1) { |
while ( (count = is.read(buffer)) != -1) { |
145 |
baos.write(buffer, 0, count); |
baos.write(buffer, 0, count); |
146 |
} |
} |
147 |
} finally { |
is.close(); |
148 |
try { |
return baos.toByteArray(); |
149 |
is.close(); |
} |
|
baos.close(); |
|
|
} catch (Exception e) {} //never mind if close throws an exception |
|
|
} |
|
|
|
|
|
return baos.toByteArray(); |
|
150 |
} |
} |
151 |
|
|
152 |
} |
} |