Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Schindelin2009-09-03 10:47:01 +0000
committerShawn O. Pearce2009-10-06 14:43:25 +0000
commite34865b88b02bb5937f8ac815fe065ebe8e9d47b (patch)
tree52478690949e032707e90814f7d0a7d96ccec64f /org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
parent1a03c864a6c82ed76ebfe9504d983f5741d75032 (diff)
downloadjgit-e34865b88b02bb5937f8ac815fe065ebe8e9d47b.tar.gz
jgit-e34865b88b02bb5937f8ac815fe065ebe8e9d47b.tar.xz
jgit-e34865b88b02bb5937f8ac815fe065ebe8e9d47b.zip
Prepare RawText for diff-index and diff-files
Bug: 291083 Eclipse-CQ: 3559 Change-Id: Ia02f346a96b5f1e24f8bc9676bd428b968a41222 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
index 61a3ef41cd..0bbbb1991a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java
@@ -44,6 +44,8 @@
package org.eclipse.jgit.diff;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -87,6 +89,18 @@ public class RawText implements Sequence {
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
@@ -187,4 +201,16 @@ public class RawText implements Sequence {
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;
+ }
+}

Back to the top