/hudson-remoting/src/main/java/hudson/remoting/forward/CopyThread.java

http://github.com/hudson/hudson · Java · 37 lines · 27 code · 4 blank · 6 comment · 1 complexity · 7042fff1965c3ef9e0fc6316bc30cbca MD5 · raw file

  1. package hudson.remoting.forward;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.OutputStream;
  5. /**
  6. * Copies a stream and close them at EOF.
  7. *
  8. * @author Kohsuke Kawaguchi
  9. */
  10. final class CopyThread extends Thread {
  11. private final InputStream in;
  12. private final OutputStream out;
  13. public CopyThread(String threadName, InputStream in, OutputStream out) {
  14. super(threadName);
  15. this.in = in;
  16. this.out = out;
  17. }
  18. public void run() {
  19. try {
  20. try {
  21. byte[] buf = new byte[8192];
  22. int len;
  23. while ((len = in.read(buf)) > 0)
  24. out.write(buf, 0, len);
  25. } finally {
  26. in.close();
  27. out.close();
  28. }
  29. } catch (IOException e) {
  30. // TODO: what to do?
  31. }
  32. }
  33. }