#27911

Actually, i do have a question regarding this class. I’m noticing that the BufferedInputStream is created (bis), but never used. Should bis be used instead of is to read the data?

Thanks,

Tim

Also, note how we modified it to catch and report the exceptions. Let me know if this is still ok, please.

<br /> public byte[] getResourceAsBytes(String resource, boolean debugOn) throws IOException {<br /> ByteArrayOutputStream fos = new ByteArrayOutputStream();<br /> byte buffer[] = new byte[2048];<br /> <br /> InputStream is = null;<br /> BufferedInputStream bis = null;<br /> <br /> try {<br /> URL src = new URL(resource);<br /> URLConnection urlConnect = src.openConnection();<br /> urlConnect.connect();<br /> is = urlConnect.getInputStream();<br /> bis = new BufferedInputStream(is);<br /> <br /> int read;<br /> do {<br /> read = is.read(buffer, 0, buffer.length);<br /> if (read > 0) {<br /> fos.write(buffer, 0, read);<br /> }<br /> } while (read > -1);<br /> <br /> } catch (Exception e) {<br /> e.printStackTrace();<br /> return new byte[0];<br /> } finally {<br /> fos.close();<br /> bis.close();<br /> is.close();<br /> }<br /> <br /> return fos.toByteArray();<br /> }<br />