@Test public void testStream2Byte() throws Exception { String str = "中文"; InputStream in = StreamUtil.byte2InputStream(str.getBytes(Opslab.UTF_8)); byte[] bt = StreamUtil.stream2Byte(in); assertEquals(str, new String(bt)); }
public final static byte[] stream2Byte(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] b = new byte[1024]; while ((len = is.read(b, 0, b.length)) != -1) { baos.write(b, 0, len); } byte[] buffer = baos.toByteArray(); return buffer; }
StreamUtil { public final static byte[] stream2Byte(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] b = new byte[1024]; while ((len = is.read(b, 0, b.length)) != -1) { baos.write(b, 0, len); } byte[] buffer = baos.toByteArray(); return buffer; } }
StreamUtil { public final static byte[] stream2Byte(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] b = new byte[1024]; while ((len = is.read(b, 0, b.length)) != -1) { baos.write(b, 0, len); } byte[] buffer = baos.toByteArray(); return buffer; }  }
StreamUtil { public final static byte[] stream2Byte(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] b = new byte[1024]; while ((len = is.read(b, 0, b.length)) != -1) { baos.write(b, 0, len); } byte[] buffer = baos.toByteArray(); return buffer; }  final static String streamToString(InputStream in); final static byte[] stream2Byte(InputStream is); final static byte[] inputStream2Byte(InputStream inStream); final static InputStream byte2InputStream(byte[] b); final static void streamSaveAsFile(InputStream is, File outfile); }
StreamUtil { public final static byte[] stream2Byte(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] b = new byte[1024]; while ((len = is.read(b, 0, b.length)) != -1) { baos.write(b, 0, len); } byte[] buffer = baos.toByteArray(); return buffer; }  final static String streamToString(InputStream in); final static byte[] stream2Byte(InputStream is); final static byte[] inputStream2Byte(InputStream inStream); final static InputStream byte2InputStream(byte[] b); final static void streamSaveAsFile(InputStream is, File outfile);  }