Class AbstractWindowsConsoleWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
The AbstractWindowsConsoleWriter class provides a foundation for writing text to the Windows console. It extends the standard Writer class and handles the common aspects of writing to the console, while leaving the actual console interaction to be implemented by concrete subclasses.
This class is necessary because standard Java output streams don't work well with the Windows console, particularly for non-ASCII characters and color output. Instead of using standard output streams, Windows terminal implementations use this writer to directly interact with the Windows console API.
Concrete subclasses must implement the writeConsole(char[], int)
method
to perform the actual writing to the console using platform-specific mechanisms
(e.g., JNI, JNA, or FFM).
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
void
write
(char[] cbuf, int off, int len) Writes a portion of a character array to the Windows console.protected abstract void
writeConsole
(char[] text, int len) Writes text to the Windows console.
-
Constructor Details
-
AbstractWindowsConsoleWriter
public AbstractWindowsConsoleWriter()
-
-
Method Details
-
writeConsole
Writes text to the Windows console.This method must be implemented by concrete subclasses to perform the actual writing to the Windows console using platform-specific mechanisms. The implementation should handle proper encoding and display of characters, including non-ASCII characters and ANSI escape sequences if supported.
- Parameters:
text
- the character array containing the text to writelen
- the number of characters to write- Throws:
IOException
- if an I/O error occurs
-
write
Writes a portion of a character array to the Windows console.This method handles the common logic for writing to the console, including creating a new character array if the offset is not zero and synchronizing access to the console. The actual writing is delegated to the
writeConsole(char[], int)
method implemented by subclasses.- Specified by:
write
in classWriter
- Parameters:
cbuf
- the character array containing the text to writeoff
- the offset from which to start reading characterslen
- the number of characters to write- Throws:
IOException
- if an I/O error occurs
-
flush
public void flush() -
close
public void close()
-