/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

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