Class ExpandedTabWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable

    public class ExpandedTabWriter
    extends FilterWriter
    Writes characters to a stream while expanding tabs ('\t') into spaces.
    Since:
    2.0
    Author:
    Martin Desruisseaux (IRD)
    • Field Summary

      • Fields inherited from class FilterWriter

        out
      • Fields inherited from class Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      ExpandedTabWriter​(Writer out)
      Constructs a filter which replaces tab characters ('\t') by spaces.
      ExpandedTabWriter​(Writer out, int tabWidth)
      Constructs a filter which replaces tab characters ('\t') by spaces, using the specified tab width.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getTabWidth()
      Returns the tab width.
      void setTabWidth​(int tabWidth)
      Sets the tab width.
      void write​(char[] buffer, int offset, int length)
      Writes a portion of an array of characters.
      void write​(int c)
      Writes a single character.
      void write​(String string, int offset, int length)
      Writes a portion of a string.
      • Methods inherited from class FilterWriter

        close, flush
      • Methods inherited from class Writer

        append, append, append, nullWriter, write, write
      • Methods inherited from class Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExpandedTabWriter

        public ExpandedTabWriter​(Writer out)
        Constructs a filter which replaces tab characters ('\t') by spaces. Tab widths default to 8 characters.
        Parameters:
        out - A writer object to provide the underlying stream.
      • ExpandedTabWriter

        public ExpandedTabWriter​(Writer out,
                                 int tabWidth)
                          throws IllegalArgumentException
        Constructs a filter which replaces tab characters ('\t') by spaces, using the specified tab width.
        Parameters:
        out - A writer object to provide the underlying stream.
        tabWidth - The tab width. Must be greater than 0.
        Throws:
        IllegalArgumentException - if tabWidth is not greater than 0.
    • Method Detail

      • setTabWidth

        public void setTabWidth​(int tabWidth)
                         throws IllegalArgumentException
        Sets the tab width.
        Parameters:
        tabWidth - The tab width. Must be greater than 0.
        Throws:
        IllegalArgumentException - if tabWidth is not greater than 0.
      • getTabWidth

        public int getTabWidth()
        Returns the tab width.
        Returns:
        The tabulation width.
      • write

        public void write​(int c)
                   throws IOException
        Writes a single character.
        Overrides:
        write in class FilterWriter
        Throws:
        IOException - If an I/O error occurs.
      • write

        public void write​(char[] buffer,
                          int offset,
                          int length)
                   throws IOException
        Writes a portion of an array of characters.
        Overrides:
        write in class FilterWriter
        Parameters:
        buffer - Buffer of characters to be written
        offset - Offset from which to start reading characters
        length - Number of characters to be written
        Throws:
        IOException - If an I/O error occurs.
      • write

        public void write​(String string,
                          int offset,
                          int length)
                   throws IOException
        Writes a portion of a string.
        Overrides:
        write in class FilterWriter
        Parameters:
        string - String to be written
        offset - Offset from which to start reading characters
        length - Number of characters to be written
        Throws:
        IOException - If an I/O error occurs.