PageRenderTime 19ms CodeModel.GetById 8ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin-module-codegen-engine/src/main/resources/templates/stash/ssh/SshScmRequest.java.vtl

https://bitbucket.org/mmeinhold/amps
Unknown | 50 lines | 40 code | 10 blank | 0 comment | 0 complexity | f50e6d629706a09b0ec8df0d6f1df158 MD5 | raw file
 1package ${PACKAGE};
 2
 3import com.atlassian.stash.scm.ssh.AbstractSshRequest;
 4import com.atlassian.stash.scm.ssh.ExitCodeCallback;
 5import org.slf4j.Logger;
 6import org.slf4j.LoggerFactory;
 7
 8import java.io.IOException;
 9import java.io.InputStream;
10import java.io.OutputStream;
11
12public class ${REQUEST_CLASSNAME} extends AbstractSshRequest
13{
14
15    private static final Logger log = LoggerFactory.getLogger(${REQUEST_CLASSNAME}.class);
16
17    private static final int BUFFER_SIZE = 1024;
18
19    private final InputStream in;
20    private final OutputStream out;
21    private final ExitCodeCallback exitCodeCallback;
22
23    public ${REQUEST_CLASSNAME}(InputStream in, OutputStream out, ExitCodeCallback exitCodeCallback)
24    {
25        this.in = in;
26        this.out = out;
27        this.exitCodeCallback = exitCodeCallback;
28    }
29
30    @Override
31    public void handleRequest() throws IOException
32    {
33        // example code (simply echoing the input stream back to client)
34        final byte[] buffer = new byte[BUFFER_SIZE];
35        long bytesCopied = 0;
36        int n;
37        while (-1 != (n = in.read(buffer)))
38        {
39            out.write(buffer, 0, n);
40            out.flush();
41            bytesCopied += n;
42        }
43        log.trace(bytesCopied + " bytes copied");
44        // end example code
45
46        // mark the request as successful
47        exitCodeCallback.onExit(0);
48    }
49
50}