Class AbstractWindowsConsoleWriter
- java.lang.Object
-
- java.io.Writer
-
- org.jline.terminal.impl.AbstractWindowsConsoleWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public abstract class AbstractWindowsConsoleWriter extends java.io.WriterBase class for writing to Windows console.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:
Writer
-
-
Constructor Summary
Constructors Constructor Description AbstractWindowsConsoleWriter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()voidwrite(char[] cbuf, int off, int len)Writes a portion of a character array to the Windows console.protected abstract voidwriteConsole(char[] text, int len)Writes text to the Windows console.
-
-
-
Method Detail
-
writeConsole
protected abstract void writeConsole(char[] text, int len) throws java.io.IOExceptionWrites 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:
java.io.IOException- if an I/O error occurs
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionWrites 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:
writein classjava.io.Writer- 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:
java.io.IOException- if an I/O error occurs
-
flush
public void flush()
- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer
-
-