PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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