public class CountingWriter extends Writer
Writer
which delegates all operations
to an underlying instance of Writer
, but counts the
characters that are written to the stream along the way.
The current count of characters can be retrieved with getCount()
.Constructor and Description |
---|
CountingWriter(Writer out)
Creates a writer wrapping
out which counts the
number of characters written into it. |
Modifier and Type | Method and Description |
---|---|
CountingWriter |
append(char c) |
CountingWriter |
append(@Nullable CharSequence csq) |
CountingWriter |
append(@Nullable CharSequence csq,
int start,
int end) |
void |
close() |
void |
flush() |
long |
getCount() |
void |
write(char[] cbuf) |
void |
write(char[] cbuf,
int off,
int len) |
void |
write(int c) |
void |
write(@Nullable String str) |
void |
write(@Nullable String str,
int off,
int len) |
public CountingWriter(Writer out)
out
which counts the
number of characters written into it. It will of course
not take into account the characters which have already
been written to out
, or those which may be written
to out
directly in the future (i.e. by keeping a
reference to out
and using it outside of this class,
which of course is really not recommended).out
- public long getCount()
public void write(int c) throws IOException
write
in class Writer
IOException
public void write(char[] cbuf) throws IOException
write
in class Writer
IOException
public void write(char[] cbuf, int off, int len) throws IOException
write
in class Writer
IOException
public void write(@Nullable String str) throws IOException
write
in class Writer
IOException
public void write(@Nullable String str, int off, int len) throws IOException
write
in class Writer
IOException
public CountingWriter append(@Nullable CharSequence csq) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public CountingWriter append(@Nullable CharSequence csq, int start, int end) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public CountingWriter append(char c) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class Writer
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Writer
IOException