Sharkysoft home

lava.io
Class LineSeparatorFilter

java.lang.Object
  |
  +--lava.io.LineSeparatorFilter
All Implemented Interfaces:
java.lang.Cloneable

public final class LineSeparatorFilter
extends java.lang.Object
implements java.lang.Cloneable

Filters line-separators from text stream.

Details: LineSeparatorFilter assists in the conversion of text streams between heterogeneous platforms. The main difference between text streams created on different platforms is the code used to separate lines. Windows, Unix, and Macintosh all subscribe to unique formats. This class will take a stream of characters generated on any of these platforms, or even a mixed stream generated from multiple platforms, and produce predictable output that conforms to a single platform.

Author:
Sharky
See Also:
UnixLineReader

Field Summary
static java.lang.String DEFAULT_SEPARATOR
           
static java.lang.String DOS_LINE_SEPARATOR
          The DOS/Windows-style line separator ("\r\n").
static java.lang.String MAC_LINE_SEPARATOR
          The Macintosh-style line separator ("\r").
static java.lang.String UNIX_LINE_SEPARATOR
          The Unix-style line separator ("\n").
 
Constructor Summary
LineSeparatorFilter()
          Initializes a new LineSeparatorFilter to replace all line separators with the system's platform-specific line separator.
LineSeparatorFilter(java.lang.String separator)
          Initializes a new LineSeparatorFilter to replace all line separators with the specified string.
 
Method Summary
 java.lang.Object clone()
          Creates an independent copy of this instance.
 char[] filter(char[] src)
          Returns a new array with the line separators replaced by the preferred line separator declared when this instance was created.
 java.lang.String filter(java.lang.String src)
          Returns a new String with the line separators replaced by the preferred line separator declared when this instance was created.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SEPARATOR

public static final java.lang.String DEFAULT_SEPARATOR

UNIX_LINE_SEPARATOR

public static final java.lang.String UNIX_LINE_SEPARATOR
The Unix-style line separator ("\n").

DOS_LINE_SEPARATOR

public static final java.lang.String DOS_LINE_SEPARATOR
The DOS/Windows-style line separator ("\r\n").

MAC_LINE_SEPARATOR

public static final java.lang.String MAC_LINE_SEPARATOR
The Macintosh-style line separator ("\r").
Constructor Detail

LineSeparatorFilter

public LineSeparatorFilter()
Initializes a new LineSeparatorFilter to replace all line separators with the system's platform-specific line separator.

LineSeparatorFilter

public LineSeparatorFilter(java.lang.String separator)
Initializes a new LineSeparatorFilter to replace all line separators with the specified string.
Parameters:
separator - the line separator that will replace all others
Method Detail

filter

public char[] filter(char[] src)
Returns a new array with the line separators replaced by the preferred line separator declared when this instance was created.
Parameters:
src - the source array
Returns:
a new array with converted line separators

filter

public java.lang.String filter(java.lang.String src)
Returns a new String with the line separators replaced by the preferred line separator declared when this instance was created.
Parameters:
src - the source String
Returns:
a new String with converted line separators

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates an independent copy of this instance. Readers that use this class and support the mark operation may use this method to make a "backup copy" of this instance, in order to preserve its state at mark time.

Note: Although this method is declared to throw a CloneNotSupportedException, rest assured that it will never happen (unless this class is subclassed and the subclass does not support cloning). The rules of Java inheritance required the useless declaration. Sorry. :-(

Overrides:
clone in class java.lang.Object
Returns:
the copy
Throws:
java.lang.CloneNotSupportedException - if this instance cannot be cloned

Sharkysoft home