@Test public void testGetBytes() { try { FileInputStream in = new FileInputStream(new File(dataRoot, "file/a.txt")); byte[] data = StreamUtil.readBytes(in); StreamUtil.close(in); String s = new String(data); s = StringUtil.remove(s, '\r'); assertEquals("test file\n", s); in = new FileInputStream(new File(dataRoot, "file/a.txt")); String str = new String(StreamUtil.readChars(in)); StreamUtil.close(in); str = StringUtil.remove(str, '\r'); assertEquals("test file\n", str); } catch (FileNotFoundException e) { fail("StreamUtil.testGetBytes " + e.toString()); } catch (IOException e) { fail("StreamUtil.testGetBytes " + e.toString()); } }
/** Downloads resource as byte array. */ public static byte[] downloadBytes(String url) throws IOException { InputStream inputStream = new URL(url).openStream(); return StreamUtil.readBytes(inputStream); }