org.eclipse.jgit.diff
Class RawText

java.lang.Object
  extended by org.eclipse.jgit.diff.RawText
All Implemented Interfaces:
Sequence

public class RawText
extends java.lang.Object
implements Sequence

A Sequence supporting UNIX formatted text in byte[] format.

Elements of the sequence are the lines of the file, as delimited by the UNIX newline character ('\n'). The file content is treated as 8 bit binary text, with no assumptions or requirements on character encoding.

Note that the first line of the file is element 0, as defined by the Sequence interface API. Traditionally in a text editor a patch file the first line is line number 1. Callers may need to subtract 1 prior to invoking methods if they are converting from "line number" to "element index".


Field Summary
protected  byte[] content
          The file content for this sequence.
protected  IntList hashes
          Hash code for each line, for fast equality elimination.
protected  IntList lines
          Map of line number to starting position within content.
 
Constructor Summary
RawText(byte[] input)
          Create a new sequence from an existing content byte array.
 
Method Summary
 boolean equals(int i, Sequence other, int j)
          Determine if the i-th member is equal to the j-th member.
protected  int hashLine(byte[] raw, int ptr, int end)
          Compute a hash code for a single line.
 boolean isMissingNewlineAtEnd()
          Determine if the file ends with a LF ('\n').
 int size()
           
 void writeLine(java.io.OutputStream out, int i)
          Write a specific line to the output stream, without its trailing LF.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

content

protected final byte[] content
The file content for this sequence.


lines

protected final IntList lines
Map of line number to starting position within content.


hashes

protected final IntList hashes
Hash code for each line, for fast equality elimination.

Constructor Detail

RawText

public RawText(byte[] input)
Create a new sequence from an existing content byte array.

The entire array (indexes 0 through length-1) is used as the content.

Parameters:
input - the content array. The array is never modified, so passing through cached arrays is safe.
Method Detail

size

public int size()
Specified by:
size in interface Sequence
Returns:
total number of items in the sequence.

equals

public boolean equals(int i,
                      Sequence other,
                      int j)
Description copied from interface: Sequence
Determine if the i-th member is equal to the j-th member.

Implementations must ensure equals(thisIdx,other,otherIdx) returns the same as other.equals(otherIdx,this,thisIdx).

Specified by:
equals in interface Sequence
Parameters:
i - index within this sequence; must be in the range [ 0, this.size() ).
other - another sequence; must be the same implementation class, that is this.getClass() == other.getClass().
j - index within other sequence; must be in the range [ 0, other.size() ).
Returns:
true if the elements are equal; false if they are not equal.

writeLine

public void writeLine(java.io.OutputStream out,
                      int i)
               throws java.io.IOException
Write a specific line to the output stream, without its trailing LF.

The specified line is copied as-is, with no character encoding translation performed.

If the specified line ends with an LF ('\n'), the LF is not copied. It is up to the caller to write the LF, if desired, between output lines.

Parameters:
out - stream to copy the line data onto.
i - index of the line to extract. Note this is 0-based, so line number 1 is actually index 0.
Throws:
java.io.IOException - the stream write operation failed.

isMissingNewlineAtEnd

public boolean isMissingNewlineAtEnd()
Determine if the file ends with a LF ('\n').

Returns:
true if the last line has an LF; false otherwise.

hashLine

protected int hashLine(byte[] raw,
                       int ptr,
                       int end)
Compute a hash code for a single line.

Parameters:
raw - the raw file content.
ptr - first byte of the content line to hash.
end - 1 past the last byte of the content line.
Returns:
hash code for the region [ptr, end) of raw.