@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 String. */ public static String downloadString(String url) throws IOException { InputStream inputStream = new URL(url).openStream(); return new String(StreamUtil.readChars(inputStream)); }