git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 4/5] Prepare RawText for diff-index and diff-files

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 3, 2009, 10:47 UTC
Message-ID
<ba3eaaf6590a49c904ef6f8e139c3201c53a7b11.1251974493u.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1251974493u.git.johannes.schindelin@gmx.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 .../src/org/spearce/jgit/diff/RawText.java         |   28 +++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/diff/RawText.java b/org.spearce.jgit/src/org/spearce/jgit/diff/RawText.java
index 9886d36..15d1c12 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/diff/RawText.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/diff/RawText.java
@@ -38,6 +38,8 @@
 
 package org.spearce.jgit.diff;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -81,6 +83,18 @@ public RawText(final byte[] input) {
 		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
@@ -181,4 +195,16 @@ protected int hashLine(final byte[] raw, int ptr, final int end) {
 			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;
+	}
+}
-- 
1.6.4.297.gcb4cc
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 9 of 28 in “[JGIT] Request for help”
  1. Nasser GrainawiSep 2, 2009
  2. Johannes SchindelinSep 3, 2009
  3. Shawn O. PearceSep 3, 2009
  4. jgit diff, was Re: [JGIT] Request for helpJohannes Schindelin, Sep 3, 2009
  5. 0/5 jgit diffJohannes Schindelin, Sep 3, 2009
  6. 1/5 Add set to IntListJohannes Schindelin, Sep 3, 2009
  7. 2/5 Add Myers' algorithm to generate diff scriptsJohannes Schindelin, Sep 3, 2009
  8. 3/5 Add a test class for Myers' diff algorithmJohannes Schindelin, Sep 3, 2009
  9. 4/5 Prepare RawText for diff-index and diff-filesJohannes Schindelin, Sep 3, 2009
  10. 5/5 Add the "jgit diff" commandJohannes Schindelin, Sep 3, 2009
  11. Johannes SchindelinSep 3, 2009
  12. Shawn O. PearceOct 1, 2009
  13. Johannes SchindelinOct 1, 2009
  14. Christian HalstrickSep 3, 2009
  15. Jonas FonsecaSep 3, 2009
  16. Shawn O. PearceSep 3, 2009
  17. Jonas FonsecaSep 3, 2009
  18. Shawn O. PearceSep 3, 2009
  19. Gabe McArthurSep 4, 2009
  20. Mark StrubergSep 4, 2009
  21. Jonas FonsecaSep 4, 2009
  22. Mark StrubergSep 4, 2009
  23. Jonas FonsecaSep 4, 2009
  24. Mark StrubergSep 4, 2009
  25. Shawn O. PearceSep 3, 2009
  26. Nasser GrainawiSep 3, 2009
  27. Shawn O. PearceSep 3, 2009
  28. Nasser GrainawiSep 3, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.