public static void copy(InputStream in, OutputStream out, int num_bytes)
    throws IOException
  {
    if(num_bytes == 0)
      return;

    int n;

    if(num_bytes < 0)
    {
      byte[] b = new byte[2048];
      while((n = in.read(b, 0, b.length)) > 0)
        out.write(b, 0, n);
    }
    else
    {
      int offset = 0;
      byte[] b = new byte[num_bytes];
      while(num_bytes > 0 && (n = in.read(b, offset, num_bytes)) > 0)
      {
        offset += n;
        num_bytes -= n;
      }
      out.write(b);
    }
  }
public static void copy(InputStream in, OutputStream out, int num_bytes)
    throws IOException
  {
    if(num_bytes == 0)
      return;

    int n;

    if(num_bytes < 0)
    {
      byte[] b = new byte[2048];
      while((n = in.read(b, 0, b.length)) > 0)
        out.write(b, 0, n);
    }
    else
    {
      int offset = 0;
      byte[] b = new byte[num_bytes];
      while(num_bytes > 0 && (n = in.read(b, offset, num_bytes)) > 0)
      {
        offset += n;
        num_bytes -= n;
      }
      out.write(b);
    }
  }
public static void copy ( InputStream in , OutputStream out , int num_bytes ) throws IOException { if ( num_bytes == 0 ) return ; int n ; if ( num_bytes < 0 ) { byte [ ] b = new byte [ 2048 ] ; while ( ( n = in . read ( b , 0 , b . length ) ) > 0 ) out . write ( b , 0 , n ) ; } else { int offset = 0 ; byte [ ] b = new byte [ num_bytes ] ; while ( num_bytes > 0 && ( n = in . read ( b , offset , num_bytes ) ) > 0 ) { offset += n ; num_bytes -= n ; } out . write ( b ) ; } }
Copies the input stream into the output stream (num_bytes)

@param in the input stream to read data
@param out the output stream to write data
@param num_bytes the number of bytes to copy
Copies the input stream into the output stream ( num_bytes )