Class IndentablePrintStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- de.christofreichardt.diagnosis.io.IndentablePrintStream
-
- All Implemented Interfaces:
Indentable,Closeable,Flushable,Appendable,AutoCloseable
- Direct Known Subclasses:
NullPrintStream,TracePrintStream
public abstract class IndentablePrintStream extends PrintStream implements Indentable
The base class of all indentable print streams.- Author:
- Christof Reichardt
-
-
Field Summary
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description IndentablePrintStream(OutputStream out)This constructor passes the given OutputStream to the underlying PrintStream implementation.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract voidlock()Acquires a lock to prevent concurrent access to theIndentablePrintStream.abstract IndentablePrintStreamprintfIndentln(String format, Object... args)A convenience method to print an indented string onto the stream using the specified format string and the given arguments.abstract IndentablePrintStreamprintIndent(String s)Prints an indented string.abstract IndentablePrintStreamprintIndentln(String s)Prints an indented string together with a line feed.abstract IndentablePrintStreamprintIndentString()Prints only the current indentation.abstract voidrunWithLock(Runnable runnable)The givenRunnablewill be executed when the lock could be acquired.abstract voidunlock()Unlocks the lock.-
Methods inherited from class java.io.PrintStream
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write
-
Methods inherited from class java.io.FilterOutputStream
write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
IndentablePrintStream
public IndentablePrintStream(OutputStream out)
This constructor passes the given OutputStream to the underlying PrintStream implementation.- Parameters:
out- the desired OutputStream
-
-
Method Detail
-
printIndent
public abstract IndentablePrintStream printIndent(String s)
Description copied from interface:IndentablePrints an indented string.- Specified by:
printIndentin interfaceIndentable- Parameters:
s- the string to be printed- Returns:
- the indentable stream itself
-
printIndentln
public abstract IndentablePrintStream printIndentln(String s)
Description copied from interface:IndentablePrints an indented string together with a line feed.- Specified by:
printIndentlnin interfaceIndentable- Parameters:
s- the string to be printed- Returns:
- the indentable stream itself
-
printIndentString
public abstract IndentablePrintStream printIndentString()
Description copied from interface:IndentablePrints only the current indentation.- Specified by:
printIndentStringin interfaceIndentable- Returns:
- the indentable stream itself
-
printfIndentln
public abstract IndentablePrintStream printfIndentln(String format, Object... args)
Description copied from interface:IndentableA convenience method to print an indented string onto the stream using the specified format string and the given arguments.- Specified by:
printfIndentlnin interfaceIndentable- Parameters:
format- the format stringargs- the to be printed arguments- Returns:
- the indentable stream itself
-
lock
public abstract void lock()
Acquires a lock to prevent concurrent access to theIndentablePrintStream. This is useful if multiple threads are writing to theIndentablePrintStream.
-
unlock
public abstract void unlock()
Unlocks the lock.
-
runWithLock
public abstract void runWithLock(Runnable runnable)
The givenRunnablewill be executed when the lock could be acquired.- Parameters:
runnable- should contain print statements
-
-