public interface Line extends CharSequence
getContent()
method returns the line without line ending characters;
getLineEnding()
returns the only the line ending.
Note that line ending characters are not necessarily line separator
characters for the current operating system as defined by the
"line.separator"
system property
. The
concrete encoding of line endings depends on the source of the line, which
could for instance be an existing Windows or Unix file.
It is illegal for the content
part of a line to contain
any character of the line ending
part. A line source
must ensure that this constraint is fulfilled. Algorithms and programs may
return undefined results or behave unpredictably for lines not following this
rule.
Modifier and Type | Field and Description |
---|---|
static char |
CR
The carriage return (CR) character
'\r' used to encode line
endings in WINDOWS together with LF . |
static Line |
EMPTY_LINE
Line with empty content string and a default operating system dependent
line ending as defined by
LINE_ENDING . |
static char |
LF
The line feed (LF) character
'\n' used to encode line endings in
UNIX. |
static String |
LINE_ENDING
Operating system dependent line ending taken from the system property
"line.separator" . |
static char |
ZERO
The zero character
'\0' used to encode line endings for special
purpose use, such as find --print0 | xargs --delimiter0 . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares
this line with obj and returns true if
obj is a Line (any subclass) and both lines are
identical. |
String |
getContent()
Returns the contents making up this line, but without the line ending
characters.
|
int |
getContentLength()
Returns the length of the content string returned by
getContent() , which is zero for a line without content and
positive otherwise. |
String |
getLineEnding()
Returns the line ending characters, usually one or two characters such as
"\n" or "\r\n" . |
int |
getLineEndingLength()
Returns the length of the line ending string returned by
getLineEnding() , which is usually one or two and sometimes zero
the last line in a file is not terminated with a new line character. |
int |
hashCode()
The hash code for this line, based on the complete line with line ending.
|
String |
toString()
Returns this line including the line ending characters as a string.
|
charAt, chars, codePoints, length, subSequence
static final String LINE_ENDING
"line.separator"
. This is usually "\n"
on UNIX systems
and "\r\n"
on WINDOWS.static final Line EMPTY_LINE
LINE_ENDING
.static final char LF
'\n'
used to encode line endings in
UNIX.static final char CR
'\r'
used to encode line
endings in WINDOWS together with LF
.static final char ZERO
'\0'
used to encode line endings for special
purpose use, such as find --print0 | xargs --delimiter0
.String getContent()
int getContentLength()
getContent()
, which is zero for a line without content and
positive otherwise.getContent()
String getLineEnding()
"\n"
or "\r\n"
. If the last line in a file is not
terminated with a new line character, the returned string can have zero
length.
The encoding of line endings depends on the source of this line object.
It is a single line feed character (LF="\n"
) if the source
is a Unix type file, and carriage return followed by line
feed (CR+LF= "\r\n"
) for lines from a Windows file.
int getLineEndingLength()
getLineEnding()
, which is usually one or two and sometimes zero
the last line in a file is not terminated with a new line character.String toString()
toString
in interface CharSequence
toString
in class Object
boolean equals(Object obj)
this
line with obj
and returns true if
obj
is a Line
(any subclass) and both lines are
identical. The line comparison considers both the content
and the line ending
.Copyright © 2024. All rights reserved.