Class NaftahOutputTransformer

java.lang.Object
java.io.OutputStream
org.daiitech.naftah.utils.script.NaftahOutputTransformer
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class NaftahOutputTransformer extends OutputStream
An OutputStream wrapper that transforms text for proper visual display when printed to an output stream (e.g., console or file).

If text is detected and reshaping is enabled, the text will be reshaped before being written. Otherwise, the original content is passed through.

Note: The methods shouldReshape(), containsArabic(String), and shape(String) are assumed to be implemented elsewhere.

Author:
Chakib Daii
  • Field Details

    • original

      private final OutputStream original
      The original output stream to which the transformed or raw output will be written.
  • Constructor Details

    • NaftahOutputTransformer

      public NaftahOutputTransformer(OutputStream original)
      Constructs a new NaftahOutputTransformer wrapping the specified output stream.
      Parameters:
      original - the original output stream
  • Method Details

    • getPrintStream

      public static PrintStream getPrintStream(OutputStream original)
      Returns a PrintStream that wraps the provided output stream and applies text transformation.
      Parameters:
      original - the original output stream to wrap
      Returns:
      a PrintStream using NaftahOutputTransformer
    • write

      public void write(int b) throws IOException
      Writes a single byte to the original output stream. This method serves as a fallback when writing raw byte data.
      Specified by:
      write in class OutputStream
      Parameters:
      b - the byte to write
      Throws:
      IOException - if an I/O error occurs
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Writes a portion of a byte array to the output stream. If the content contains text and reshaping is enabled, it reshapes the text before writing. Otherwise, writes the original byte sequence.
      Overrides:
      write in class OutputStream
      Parameters:
      b - the byte array containing the data
      off - the start offset in the array
      len - the number of bytes to write
      Throws:
      IOException - if an I/O error occurs