Package eu.bandm.tools.util.files
Class PrintWriter_limited
java.lang.Object
java.io.Writer
java.io.PrintWriter
eu.bandm.tools.util.files.PrintWriter_limited
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
Prints only the n first characters and igores the rest.
Useful in debugging for printing the prefix of a structure dump
which would otherwise be (ergonomically) too large for the context.
(For instance, whole tdom dumps, of which only the head information
needs to be readable.)
Since needed for interactive use, the os's default encoding is
appropriate.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSignals to a caller that the number of characters to print has been reached. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intInternal counter of characters.protected booleanFlag that limit has been reached.static final StringPublic cache for the os-dependent line-separator string, as retrieved bySystem.getProperty("line.separator").protected final intLimit on characters.Fields inherited from class java.io.PrintWriter
out -
Constructor Summary
ConstructorsConstructorDescriptionPrintWriter_limited(Writer out, int maxcount) Constructor setting the target of the prints and the limit in character count. -
Method Summary
Methods inherited from class java.io.PrintWriter
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, writeMethods inherited from class java.io.Writer
nullWriter
-
Field Details
-
LS
Public cache for the os-dependent line-separator string, as retrieved bySystem.getProperty("line.separator"). -
count
protected int countInternal counter of characters. -
maxcount
protected final int maxcountLimit on characters. -
fin
protected boolean finFlag that limit has been reached.
-
-
Constructor Details
-
PrintWriter_limited
Constructor setting the target of the prints and the limit in character count. Uses the os's default encoding.- Parameters:
out- the underlying print writermaxcount- the maximum number of characters to print
-
-
Method Details
-
reset
public void reset()Reset the counter and start counting anew. -
print
Print a string, but only the firstcountcharacters. When this limit is reached, throwPrintWriter_limited.PrintFinished. Flush the output after each call.- Overrides:
printin classPrintWriter- Throws:
UncheckedIOException- if the underlying PrintWriter throws an IOException.PrintWriter_limited.PrintFinished
-
println
Print a string followed by a line feed.- Overrides:
printlnin classPrintWriter
-