package org.eclipse.jgit.diff;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
hashes = computeHashes();
}
+ /**
+ * Create a new sequence from a file.
+ * <p>
+ * The entire file contents are used.
+ *
+ * @param file
+ * the text file.
+ */
+ public RawText(File file) throws IOException {
+ this(readFile(file));
+ }
+
public int size() {
// The line map is always 2 entries larger than the number of lines in
// the file. Index 0 is padded out/unused. The last index is the total
hash = (hash << 5) ^ (raw[ptr] & 0xff);
return hash;
}
-}
\ No newline at end of file
+
+ private static byte[] readFile(File file) throws IOException {
+ byte[] result = new byte[(int)file.length()];
+ FileInputStream in = new FileInputStream(file);
+ for (int off = 0; off < result.length; ) {
+ int read = in.read(result, off, result.length - off);
+ if (read < 0)
+ throw new IOException("Early EOF");
+ off += read;
+ }
+ return result;
+ }
+}