Class LineEnds

java.lang.Object
com.Ostermiller.util.LineEnds

public class LineEnds extends Object
Stream editor to alter the line separators on text to match that of a given platform. More information about this class is available from ostermiller.org.
Since:
ostermillerutils 1.00.00
Author:
Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The Windows and DOS line ending ("\r\n")
    static final int
    The UNIX and Java line ending ("\n")
    static final int
    The Macintosh line ending ("\r")
    static final int
    The UNIX and Java line ending ("\n")
    static final int
    The Macintosh line ending ("\r")
    static final int
    The Windows and DOS line ending ("\r\n")
    static final int
    The system line ending as determined by System.getProperty("line.separator")
    static final int
    The UNIX and Java line ending ("\n")
    static final int
    The Windows and DOS line ending ("\r\n")
    static final String
    Version number of this program
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Change the line endings on given file.
    static boolean
    convert(File f, boolean binaryException)
    Change the line endings on given file.
    static boolean
    convert(File f, int style)
    Change the line endings on given file.
    static boolean
    convert(File f, int style, boolean binaryException)
    Change the line endings on given file.
    static boolean
    Change the line endings of the text on the input stream and write it to the output stream.
    static boolean
    convert(InputStream in, OutputStream out, boolean binaryException)
    Change the line endings of the text on the input stream and write it to the output stream.
    static boolean
    convert(InputStream in, OutputStream out, int style)
    Change the line endings of the text on the input stream and write it to the output stream.
    static boolean
    convert(InputStream in, OutputStream out, int style, boolean binaryException)
    Change the line endings of the text on the input stream and write it to the output stream.
    static void
    main(String[] args)
    Converts the line ending on files, or standard input.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • version

      public static final String version
      Version number of this program
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_SYSTEM

      public static final int STYLE_SYSTEM
      The system line ending as determined by System.getProperty("line.separator")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_WINDOWS

      public static final int STYLE_WINDOWS
      The Windows and DOS line ending ("\r\n")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_DOS

      public static final int STYLE_DOS
      The Windows and DOS line ending ("\r\n")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_RN

      public static final int STYLE_RN
      The Windows and DOS line ending ("\r\n")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_UNIX

      public static final int STYLE_UNIX
      The UNIX and Java line ending ("\n")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_N

      public static final int STYLE_N
      The UNIX and Java line ending ("\n")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_JAVA

      public static final int STYLE_JAVA
      The UNIX and Java line ending ("\n")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_MAC

      public static final int STYLE_MAC
      The Macintosh line ending ("\r")
      Since:
      ostermillerutils 1.00.00
      See Also:
    • STYLE_R

      public static final int STYLE_R
      The Macintosh line ending ("\r")
      Since:
      ostermillerutils 1.00.00
      See Also:
  • Constructor Details

    • LineEnds

      public LineEnds()
  • Method Details

    • main

      public static void main(String[] args)
      Converts the line ending on files, or standard input. Run with --help argument for more information.
      Parameters:
      args - Command line arguments.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(InputStream in, OutputStream out) throws IOException
      Change the line endings of the text on the input stream and write it to the output stream. The current system's line separator is used.
      Parameters:
      in - stream that contains the text which needs line number conversion.
      out - stream where converted text is written.
      Returns:
      true if the output was modified from the input, false if it is exactly the same
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(InputStream in, OutputStream out, int style) throws IOException
      Change the line endings of the text on the input stream and write it to the output stream.
      Parameters:
      in - stream that contains the text which needs line number conversion.
      out - stream where converted text is written.
      style - line separator style.
      Returns:
      true if the output was modified from the input, false if it is exactly the same
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      IllegalArgumentException - if an unknown style is requested.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(InputStream in, OutputStream out, boolean binaryException) throws IOException
      Change the line endings of the text on the input stream and write it to the output stream. The current system's line separator is used.
      Parameters:
      in - stream that contains the text which needs line number conversion.
      out - stream where converted text is written.
      binaryException - throw an exception and abort the operation if binary data is encountered and binaryExcepion is false.
      Returns:
      true if the output was modified from the input, false if it is exactly the same
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(InputStream in, OutputStream out, int style, boolean binaryException) throws IOException
      Change the line endings of the text on the input stream and write it to the output stream.
      Parameters:
      in - stream that contains the text which needs line number conversion.
      out - stream where converted text is written.
      style - line separator style.
      binaryException - throw an exception and abort the operation if binary data is encountered and binaryExcepion is false.
      Returns:
      true if the output was modified from the input, false if it is exactly the same
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      IllegalArgumentException - if an unknown style is requested.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(File f) throws IOException
      Change the line endings on given file. The current system's line separator is used.
      Parameters:
      f - File to be converted.
      Returns:
      true if the file was modified, false if it was already in the correct format
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(File f, int style) throws IOException
      Change the line endings on given file.
      Parameters:
      f - File to be converted.
      style - line separator style.
      Returns:
      true if the file was modified, false if it was already in the correct format
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      IllegalArgumentException - if an unknown style is requested.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(File f, boolean binaryException) throws IOException
      Change the line endings on given file. The current system's line separator is used.
      Parameters:
      f - File to be converted.
      binaryException - throw an exception and abort the operation if binary data is encountered and binaryExcepion is false.
      Returns:
      true if the file was modified, false if it was already in the correct format
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      Since:
      ostermillerutils 1.00.00
    • convert

      public static boolean convert(File f, int style, boolean binaryException) throws IOException
      Change the line endings on given file.
      Parameters:
      f - File to be converted.
      style - line separator style.
      binaryException - throw an exception and abort the operation if binary data is encountered and binaryExcepion is false.
      Returns:
      true if the file was modified, false if it was already in the correct format
      Throws:
      BinaryDataException - if non-text data is encountered.
      IOException - if an input or output error occurs.
      IllegalArgumentException - if an unknown style is requested.
      Since:
      ostermillerutils 1.00.00