Package java.io
Class FilterWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public abstract class FilterWriter extends Writer
Wraps an existing
Writer and performs some transformation on the
output data while it is being written. Transformations can be anything from a
simple byte-wise filtering output data to an on-the-fly compression or
decompression of the underlying writer. Writers that wrap another writer and
provide some additional functionality on top of it usually inherit from this
class.- See Also:
FilterReader
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedFilterWriter(Writer out)Constructs a new FilterWriter on the Writerout. -
Method Summary
Modifier and Type Method Description voidclose()Closes this writer.voidflush()Flushes this writer to ensure all pending data is sent out to the target writer.voidwrite(char[] buffer, int offset, int count)Writescountcharacters from the char arraybufferstarting at positionoffsetto the target writer.voidwrite(int oneChar)Writes the specified characteroneCharto the target writer.voidwrite(String str, int offset, int count)Writescountcharacters from the stringstrstarting at positionindexto this writer.
-
Field Details
-
out
The Writer being filtered.
-
-
Constructor Details
-
FilterWriter
Constructs a new FilterWriter on the Writerout. All writes are now filtered through this writer.- Parameters:
out- the target Writer to filter writes on.
-
-
Method Details
-
close
Closes this writer. This implementation closes the target writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- if an error occurs attempting to close this writer.
-
flush
Flushes this writer to ensure all pending data is sent out to the target writer. This implementation flushes the target writer.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- if an error occurs attempting to flush this writer.
-
write
Writescountcharacters from the char arraybufferstarting at positionoffsetto the target writer.- Specified by:
writein classWriter- Parameters:
buffer- the buffer to write.offset- the index of the first character inbufferto write.count- the number of characters inbufferto write.- Throws:
IOException- if an error occurs while writing to this writer.
-
write
Writes the specified characteroneCharto the target writer. Only the two least significant bytes of the integeroneCharare written.- Overrides:
writein classWriter- Parameters:
oneChar- the char to write to the target writer.- Throws:
IOException- if an error occurs while writing to this writer.
-
write
Writescountcharacters from the stringstrstarting at positionindexto this writer. This implementation writesstrto the target writer.- Overrides:
writein classWriter- Parameters:
str- the string to be written.offset- the index of the first character instrto write.count- the number of chars instrto write.- Throws:
IOException- if an error occurs while writing to this writer.
-