Codota Logo
ThreadLocalPrintStream
Code IndexAdd Codota to your IDE (free)

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

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

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: org.apache.brooklyn/brooklyn-utils-common

/** installs a thread local print stream to System.out if one is not already set;
 * caller may then #capture and #captureTee on it.
 * @return the ThreadLocalPrintStream which System.out is using */
public synchronized static ThreadLocalPrintStream stdout() {
  PrintStream oldOut = System.out;
  if (oldOut instanceof ThreadLocalPrintStream) return (ThreadLocalPrintStream)oldOut;
  ThreadLocalPrintStream newOut = new ThreadLocalPrintStream(System.out);
  System.setOut(newOut);
  return newOut;
}
origin: org.apache.brooklyn/brooklyn-utils-common

public String end() {
  if (streamToRestore!=null)
    stream.setThreadLocalPrintStream(streamToRestore);
  else
    stream.clearThreadLocalPrintStream();
  finished = true;
  return out.toString();
}
public boolean isActive() {
origin: org.apache.brooklyn/brooklyn-utils-common

/** creates a capturing context which sees the output to this stream, without interrupting the original target */
public OutputCapturingContext captureTee() {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  PrintStream toRestore = setThreadLocalPrintStream(new TeeOutputStream(getDelegate(), out));
  return new OutputCapturingContext(this, out, toRestore);
}

origin: org.apache.brooklyn/brooklyn-rest-resources

OutputCapturingContext stdout = ThreadLocalPrintStream.stdout().captureTee();
OutputCapturingContext stderr = ThreadLocalPrintStream.stderr().captureTee();
origin: org.apache.brooklyn/brooklyn-utils-common

/** simple example showing how a capture to stdout can be set up */
@Test
public void testStdoutCapture() {
  OutputCapturingContext capture = ThreadLocalPrintStream.stdout().captureTee();
  System.out.println("hello");
  String out = capture.end();
  Assert.assertEquals("hello", out.trim());
  
  System.out.println("goodbye - not captured, restored normal output");
  Assert.assertEquals("hello", out.trim());
}
origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testStdoutCaptureDetail() {
  ThreadLocalPrintStream.stdout();
  System.out.println("1 - not captured, but next goes to capture only");
  OutputCapturingContext capture = ThreadLocalPrintStream.stdout().capture();
  final String TWO = "2 - captured";
  System.out.println(TWO);
  Assert.assertEquals(TWO, capture.getOutputSoFar().trim());
  String out = capture.end();
  Assert.assertEquals(TWO, out.trim());
  System.out.println("3 - not captured, restored normal output");
  Assert.assertEquals(TWO, capture.getOutputSoFar().trim());
}

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

@Test
public void testStderrCaptureDetail() {
  ThreadLocalPrintStream.stderr();
  System.err.println("1 - not captured, but next goes to capture only");
  OutputCapturingContext capture = ThreadLocalPrintStream.stderr().capture();
  final String TWO = "2 - captured";
  System.err.println(TWO);
  Assert.assertEquals(TWO, capture.getOutputSoFar().trim());
  String out = capture.end();
  Assert.assertEquals(TWO, out.trim());
  System.err.println("3 - not captured, restored normal output");
  Assert.assertEquals(TWO, capture.getOutputSoFar().trim());
}

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

/** constructor which installs a ByteArrayOutputStream to this stream */
public OutputCapturingContext(ThreadLocalPrintStream stream) {
  this.stream = stream;
  this.out = new ByteArrayOutputStream();
  this.streamToRestore = stream.setThreadLocalPrintStream(out);
}
/** constructor for a capturing context which is already installed */
origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testStdoutCaptureTeeDetail() {
  ThreadLocalPrintStream.stdout();
  System.out.println("1 - not captured, but next go to capture and stdout");
  OutputCapturingContext capture1 = ThreadLocalPrintStream.stdout().captureTee();
  OutputCapturingContext capture2 = ThreadLocalPrintStream.stdout().captureTee();
  final String TWO = "2 - captured";
  System.out.println(TWO);
  Assert.assertEquals(TWO, capture1.getOutputSoFar().trim());
  Assert.assertEquals(TWO, capture2.getOutputSoFar().trim());
  String out2 = capture2.end();
  
  final String THREE = "3 - captured by 1";
  System.out.println(THREE);
  String out1 = capture1.end();
  
  System.out.println("4 - not captured, restored normal output");
  Assert.assertEquals(TWO, out2.trim());
  Assert.assertEquals(TWO+Os.LINE_SEPARATOR+THREE, out1.trim());
}
origin: org.apache.brooklyn/brooklyn-utils-common

/** installs a thread local print stream to System.err if one is not already set;
 * caller may then #capture and #captureTee on it.
 * @return the ThreadLocalPrintStream which System.err is using */
public synchronized static ThreadLocalPrintStream stderr() {
  PrintStream oldErr = System.err;
  if (oldErr instanceof ThreadLocalPrintStream) return (ThreadLocalPrintStream)oldErr;
  ThreadLocalPrintStream newErr = new ThreadLocalPrintStream(System.err);
  System.setErr(newErr);
  return newErr;
}
org.apache.brooklyn.util.streamThreadLocalPrintStream

Most used methods

  • captureTee
    creates a capturing context which sees the output to this stream, without interrupting the original
  • stderr
    installs a thread local print stream to System.err if one is not already set; caller may then #captu
  • stdout
    installs a thread local print stream to System.out if one is not already set; caller may then #captu
  • <init>
  • capture
    creates a capturing context which eats the output to this stream, blocking the original target
  • clearThreadLocalPrintStream
  • getDelegate
  • setThreadLocalPrintStream
    sets the PrintStream that callers from this thread should see; returns any previously custom PrintSt

Popular in Java

  • Updating database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • notifyDataSetChanged (ArrayAdapter)
  • findViewById (Activity)
  • FileInputStream (java.io)
    A FileInputStream obtains input bytes from a file in a file system. What files are available depends
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now