@Test public void readBytesShouldReturnEmptyByteArrayForNullInputStream() throws Exception { assertThat(IoUtil.readBytes((InputStream)null), is(new byte[] {})); }
public static byte[] readBytes( InputStream stream ) throws IOException { if (stream == null) return new byte[] {}; byte[] buffer = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); boolean error = false; try { int numRead = 0; while ((numRead = stream.read(buffer)) > -1) { output.write(buffer, 0, numRead); } } catch (IOException e) { error = true; throw e; } catch (RuntimeException e) { error = true; throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } output.flush(); return output.toByteArray(); }
IoUtil { public static byte[] readBytes( InputStream stream ) throws IOException { if (stream == null) return new byte[] {}; byte[] buffer = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); boolean error = false; try { int numRead = 0; while ((numRead = stream.read(buffer)) > -1) { output.write(buffer, 0, numRead); } } catch (IOException e) { error = true; throw e; } catch (RuntimeException e) { error = true; throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } output.flush(); return output.toByteArray(); } }
IoUtil { public static byte[] readBytes( InputStream stream ) throws IOException { if (stream == null) return new byte[] {}; byte[] buffer = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); boolean error = false; try { int numRead = 0; while ((numRead = stream.read(buffer)) > -1) { output.write(buffer, 0, numRead); } } catch (IOException e) { error = true; throw e; } catch (RuntimeException e) { error = true; throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } output.flush(); return output.toByteArray(); } private  IoUtil(); }
IoUtil { public static byte[] readBytes( InputStream stream ) throws IOException { if (stream == null) return new byte[] {}; byte[] buffer = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); boolean error = false; try { int numRead = 0; while ((numRead = stream.read(buffer)) > -1) { output.write(buffer, 0, numRead); } } catch (IOException e) { error = true; throw e; } catch (RuntimeException e) { error = true; throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } output.flush(); return output.toByteArray(); } private  IoUtil(); static byte[] readBytes( InputStream stream ); static byte[] readBytes( File file ); static String read( Reader reader ); static String read( InputStream stream ); static String read( InputStream stream,
                               String charset ); static String read( File file ); static void write( String content,
                              File file ); static void write( String content,
                              OutputStream stream ); static void write( String content,
                              Writer writer ); static void write( InputStream input,
                              OutputStream stream ); static void write( InputStream input,
                              OutputStream stream,
                              int bufferSize ); static void write( Reader input,
                              Writer writer ); static boolean isSame( InputStream input1,
                                  InputStream input2 ); static InputStream getResourceAsStream( String resourcePath,
                                                   ClassLoader classLoader,
                                                   Class<?> clazz ); static void closeQuietly( Closeable closeable ); }
IoUtil { public static byte[] readBytes( InputStream stream ) throws IOException { if (stream == null) return new byte[] {}; byte[] buffer = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); boolean error = false; try { int numRead = 0; while ((numRead = stream.read(buffer)) > -1) { output.write(buffer, 0, numRead); } } catch (IOException e) { error = true; throw e; } catch (RuntimeException e) { error = true; throw e; } finally { try { stream.close(); } catch (IOException e) { if (!error) throw e; } } output.flush(); return output.toByteArray(); } private  IoUtil(); static byte[] readBytes( InputStream stream ); static byte[] readBytes( File file ); static String read( Reader reader ); static String read( InputStream stream ); static String read( InputStream stream,
                               String charset ); static String read( File file ); static void write( String content,
                              File file ); static void write( String content,
                              OutputStream stream ); static void write( String content,
                              Writer writer ); static void write( InputStream input,
                              OutputStream stream ); static void write( InputStream input,
                              OutputStream stream,
                              int bufferSize ); static void write( Reader input,
                              Writer writer ); static boolean isSame( InputStream input1,
                                  InputStream input2 ); static InputStream getResourceAsStream( String resourcePath,
                                                   ClassLoader classLoader,
                                                   Class<?> clazz ); static void closeQuietly( Closeable closeable );  }