FileDocCategorySizeDatePackage
StreamCopier.javaAPI DocExample764Sun Mar 28 19:05:44 BST 1999com.macfaq.io

StreamCopier

public class StreamCopier extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidcopy(java.io.InputStream in, java.io.OutputStream out)


    // do not allow other threads to read from the
    // input or write to the output while copying is
    // taking place
    
    synchronized (in) {
      synchronized (out) {

        byte[] buffer = new byte[256];
        while (true) {
          int bytesRead = in.read(buffer);
          if (bytesRead == -1) break;
          out.write(buffer, 0, bytesRead);
        }
      }
    }
  
public static voidmain(java.lang.String[] args)


    try {
      copy(System.in, System.out);
    }
    catch (IOException e) {
      System.err.println(e);
    }