Class AbstractWindowsConsoleWriter

java.lang.Object
java.io.Writer
org.jline.terminal.impl.AbstractWindowsConsoleWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public abstract class AbstractWindowsConsoleWriter extends Writer
Base 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:
  • Constructor Details

    • AbstractWindowsConsoleWriter

      public AbstractWindowsConsoleWriter()
  • Method Details

    • writeConsole

      protected abstract void writeConsole(char[] text, int len) throws IOException
      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 write
      len - the number of characters to write
      Throws:
      IOException - if an I/O error occurs
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      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 class Writer
      Parameters:
      cbuf - the character array containing the text to write
      off - the offset from which to start reading characters
      len - the number of characters to write
      Throws:
      IOException - if an I/O error occurs
    • flush

      public void flush()
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer