Tabnine Logo
StreamGobbler
Code IndexAdd Tabnine to your IDE (free)

How to use
StreamGobbler
in
org.apache.brooklyn.util.stream

Best Java code snippets using org.apache.brooklyn.util.stream.StreamGobbler (Showing top 12 results out of 315)

origin: org.apache.brooklyn/brooklyn-utils-common

  outgobbler = new StreamGobbler(outstream, out, (Logger) null);
  outgobbler.start();
  errgobbler = new StreamGobbler(errstream, err, (Logger) null);
  errgobbler.start();
if (outgobbler != null) outgobbler.blockUntilFinished();
if (errgobbler != null) errgobbler.blockUntilFinished();
origin: org.apache.brooklyn/brooklyn-utils-common

/**
 * @deprecate Use close() instead.
 */
@Deprecated
public void shutdown() {
  close();
}
origin: org.apache.brooklyn/brooklyn-utils-common

@Override
public void close() {
  running.set(false);
  interrupt();
}
origin: org.apache.brooklyn/brooklyn-utils-common

public StreamGobbler setPrefix(String prefix) {
  setLogPrefix(prefix);
  setPrintPrefix(prefix);
  return this;
}
public StreamGobbler setPrintPrefix(String prefix) {
origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testGobbleStream() throws Exception {
  byte[] bytes = new byte[] {'a','b','c'};
  InputStream stream = new ByteArrayInputStream(bytes);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  StreamGobbler gobbler = new StreamGobbler(stream, out, null);
  gobbler.start();
  try {
    gobbler.join(10*1000);
    assertFalse(gobbler.isAlive());
    assertEquals(new String(out.toByteArray()), "abc" + NL);
  } finally {
    gobbler.close();
    gobbler.interrupt();
  }
}

origin: org.apache.brooklyn/brooklyn-core

PipedInputStream insO = new PipedInputStream(); OutputStream outO = new PipedOutputStream(insO);
PipedInputStream insE = new PipedInputStream(); OutputStream outE = new PipedOutputStream(insE);
StreamGobbler sgsO = new StreamGobbler(insO, null, LOG); sgsO.setLogPrefix("[curl @ "+address+":stdout] ").start();
StreamGobbler sgsE = new StreamGobbler(insE, null, LOG); sgsE.setLogPrefix("[curl @ "+address+":stdout] ").start();
Map<String, ?> sshProps = MutableMap.<String, Object>builder().putAll(props).put("out", outO).put("err", outE).build();
int result = execScript(sshProps, "copying remote resource "+url+" to server",  ImmutableList.of(
sgsO.close();
sgsE.close();
if (result != 0) {
  LOG.debug("installing {} to {} on {}, curl failed, attempting local fetch and copy", new Object[] { url, destPath, this });
origin: org.apache.brooklyn/brooklyn-core

outgobbler = new StreamGobbler(outstream, out, (Logger)null);
outgobbler.start();
errgobbler = new StreamGobbler(errstream, err, (Logger)null);
errgobbler.start();
    outgobbler.join(joinTimeout);
    outgobbler.close();
    errgobbler.join(joinTimeout);
    errgobbler.close();
origin: org.apache.brooklyn/brooklyn-software-base

@Test(groups="Integration")
@SuppressWarnings("resource")
public void testWhichKnife() throws IOException, InterruptedException {
  // requires that knife is installed on the path of login shells
  Process p = Runtime.getRuntime().exec(new String[] { "bash", "-l", "-c", "which knife" });
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  new StreamGobbler(p.getInputStream(), out, log).start();
  new StreamGobbler(p.getErrorStream(), out, log).start();
  log.info("bash -l -c 'which knife' gives exit code: "+p.waitFor());
  Time.sleep(Duration.millis(1000));
  log.info("output:\n"+out);
  Assert.assertEquals(p.exitValue(), 0);
}
origin: org.apache.brooklyn/brooklyn-core

outgobbler = new StreamGobbler(output.getInputStream(), out, (Logger)null);
outgobbler.start();
errgobbler = new StreamGobbler(output.getErrorStream(), err, (Logger)null);
errgobbler.start();
  if (outgobbler != null) outgobbler.join(joinTimeout);
  if (errgobbler != null) errgobbler.join(joinTimeout);
} catch (InterruptedException e) {
  LOG.warn("Interrupted gobbling streams from ssh: "+command, e);
origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testGobbleMultiLineBlockingStream() throws Exception {
  PipedOutputStream pipedOutputStream = new PipedOutputStream();
  PipedInputStream stream = new PipedInputStream(pipedOutputStream);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  StreamGobbler gobbler = new StreamGobbler(stream, out, null);
  gobbler.start();
  try {
    pipedOutputStream.write("line1\n".getBytes());
    pipedOutputStream.flush();
    assertEqualsEventually(out, "line1" + NL);
    pipedOutputStream.write("line2\n".getBytes());
    pipedOutputStream.flush();
    assertEqualsEventually(out, "line1" + NL + "line2" + NL);
    pipedOutputStream.write("line".getBytes());
    pipedOutputStream.write("3\n".getBytes());
    pipedOutputStream.flush();
    assertEqualsEventually(out, "line1" + NL + "line2" + NL + "line3" + NL);
    pipedOutputStream.close();
    
    gobbler.join(10*1000);
    assertFalse(gobbler.isAlive());
    assertEquals(new String(out.toByteArray()), "line1" + NL + "line2" + NL + "line3" + NL);
  } finally {
    gobbler.close();
    gobbler.interrupt();
  }
}

origin: org.apache.brooklyn/brooklyn-software-cm-chef

@Test(groups="Integration")
@SuppressWarnings("resource")
public void testWhichKnife() throws IOException, InterruptedException {
  // requires that knife is installed on the path of login shells
  Process p = Runtime.getRuntime().exec(new String[] { "bash", "-l", "-c", "which knife" });
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  new StreamGobbler(p.getInputStream(), out, log).start();
  new StreamGobbler(p.getErrorStream(), out, log).start();
  log.info("bash -l -c 'which knife' gives exit code: "+p.waitFor());
  Time.sleep(Duration.millis(1000));
  log.info("output:\n"+out);
  Assert.assertEquals(p.exitValue(), 0);
}
origin: org.apache.brooklyn/brooklyn-core

  outgobbler = new StreamGobbler(outstream, out, (Logger) null);
  outgobbler.start();
  errgobbler = new StreamGobbler(errstream, err, (Logger) null);
  errgobbler.start();
if (outgobbler != null) outgobbler.blockUntilFinished();
if (errgobbler != null) errgobbler.blockUntilFinished();
org.apache.brooklyn.util.streamStreamGobbler

Most used methods

  • <init>
  • start
  • close
  • blockUntilFinished
    convenience -- equivalent to calling join()
  • interrupt
  • join
  • setLogPrefix
  • isAlive
  • onChar
  • onClose
  • onLine
  • setPrintPrefix
  • onLine,
  • setPrintPrefix

Popular in Java

  • Making http requests using okhttp
  • onCreateOptionsMenu (Activity)
  • setContentView (Activity)
  • requestLocationUpdates (LocationManager)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Collectors (java.util.stream)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now