com.Ostermiller.util Java Utilities


com.Ostermiller.util
Class LineEnds

java.lang.Object
  extended by 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 http://ostermiller.org/contact.pl?regarding=Java+Utilities

Field Summary
static int STYLE_DOS
          The Windows and DOS line ending ("\r\n")
static int STYLE_JAVA
          The UNIX and Java line ending ("\n")
static int STYLE_MAC
          The Macintosh line ending ("\r")
static int STYLE_N
          The UNIX and Java line ending ("\n")
static int STYLE_R
          The Macintosh line ending ("\r")
static int STYLE_RN
          The Windows and DOS line ending ("\r\n")
static int STYLE_SYSTEM
          The system line ending as determined by System.getProperty("line.separator")
static int STYLE_UNIX
          The UNIX and Java line ending ("\n")
static int STYLE_WINDOWS
          The Windows and DOS line ending ("\r\n")
static String version
          Version number of this program
 
Constructor Summary
LineEnds()
           
 
Method Summary
static boolean convert(File f)
          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 convert(InputStream in, OutputStream out)
          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 Detail

version

public static final String version
Version number of this program

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

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:
Constant Field Values

STYLE_WINDOWS

public static final int STYLE_WINDOWS
The Windows and DOS line ending ("\r\n")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_DOS

public static final int STYLE_DOS
The Windows and DOS line ending ("\r\n")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_RN

public static final int STYLE_RN
The Windows and DOS line ending ("\r\n")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_UNIX

public static final int STYLE_UNIX
The UNIX and Java line ending ("\n")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_N

public static final int STYLE_N
The UNIX and Java line ending ("\n")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_JAVA

public static final int STYLE_JAVA
The UNIX and Java line ending ("\n")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_MAC

public static final int STYLE_MAC
The Macintosh line ending ("\r")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

STYLE_R

public static final int STYLE_R
The Macintosh line ending ("\r")

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values
Constructor Detail

LineEnds

public LineEnds()
Method Detail

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

com.Ostermiller.util Java Utilities


Copyright © 2001-2012 by Stephen Ostermiller