- public void connect(Source source) throws ConnectException {
- Preconditions.checkNotNull(source, "source must not be null");
-
- this.source = source;
- try {
- final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.<String>builder().add(binary(source.format())).addAll(parameters(source.format())).build(), String.class));
- final InputStream processOutput = process.getInputStream();
- final OutputStream processInput = process.getOutputStream();
- final InputStream processError = process.getErrorStream();
- final PipedOutputStream pipedOutputStream = new PipedOutputStream();
- pipedInputStream = new PipedInputStream(pipedOutputStream);
- new Thread(new InputStreamDrainer(processError)).start();
- new Thread(new Runnable() {
-
- @Override
- public void run() {
- try {
- ByteStreams.copy(processOutput, pipedOutputStream);
- } catch (IOException ioe1) {
- /* okay, just exit. */
- }
- logger.finest("Reading stdout finished.");
- }
- }).start();
- new Thread(new Connection(source) {
-
- @Override
- protected int bufferSize() {
- return 4096;
- }
-
- @Override
- protected void feed(byte[] buffer) throws IOException {
- processInput.write(buffer);
- processInput.flush();
- }
-
- @Override
- protected void finish() throws IOException {
- processInput.close();
- processOutput.close();
- processError.close();
- }
- }).start();
- } catch (IOException ioe1) {
-
- }