@ -132,8 +132,8 @@ public class RawText extends Sequence {
* /
* /
public void writeLine ( final OutputStream out , final int i )
public void writeLine ( final OutputStream out , final int i )
throws IOException {
throws IOException {
final int start = lines . get ( i + 1 ) ;
int start = getStar t ( i ) ;
int end = lines . get ( i + 2 ) ;
int end = getEnd ( i ) ;
if ( content [ end - 1 ] = = '\n' )
if ( content [ end - 1 ] = = '\n' )
end - - ;
end - - ;
out . write ( content , start , end - start ) ;
out . write ( content , start , end - start ) ;
@ -151,6 +151,67 @@ public class RawText extends Sequence {
return content [ end - 1 ] ! = '\n' ;
return content [ end - 1 ] ! = '\n' ;
}
}
/ * *
* Get the text for a single line .
*
* @param i
* index of the line to extract . Note this is 0 - based , so line
* number 1 is actually index 0 .
* @return the text for the line , without a trailing LF .
* /
public String getString ( int i ) {
return getString ( i , i + 1 , true ) ;
}
/ * *
* Get the text for a region of lines .
*
* @param begin
* index of the first line to extract . Note this is 0 - based , so
* line number 1 is actually index 0 .
* @param end
* index of one past the last line to extract .
* @param dropLF
* if true the trailing LF ( '\n' ) of the last returned line is
* dropped , if present .
* @return the text for lines { @code [ begin , end ) } .
* /
public String getString ( int begin , int end , boolean dropLF ) {
if ( begin = = end )
return "" ;
int s = getStart ( begin ) ;
int e = getEnd ( end - 1 ) ;
if ( dropLF & & content [ e - 1 ] = = '\n' )
e - - ;
return decode ( s , e ) ;
}
/ * *
* Decode a region of the text into a String .
*
* The default implementation of this method tries to guess the character
* set by considering UTF - 8 , the platform default , and falling back on
* ISO - 8859 - 1 if neither of those can correctly decode the region given .
*
* @param start
* first byte of the content to decode .
* @param end
* one past the last byte of the content to decode .
* @return the region { @code [ start , end ) } decoded as a String .
* /
protected String decode ( int start , int end ) {
return RawParseUtils . decode ( content , start , end ) ;
}
private int getStart ( final int i ) {
return lines . get ( i + 1 ) ;
}
private int getEnd ( final int i ) {
return lines . get ( i + 2 ) ;
}
/ * *
/ * *
* Determine heuristically whether a byte array represents binary ( as
* Determine heuristically whether a byte array represents binary ( as
* opposed to text ) content .
* opposed to text ) content .