Merge "Ensure RawText closes the FileInputStream when read is complete"

This commit is contained in:
Robin Rosenberg 2010-02-03 16:42:07 -05:00 committed by Code Review
commit fbadb19543
1 changed files with 2 additions and 14 deletions

View File

@ -45,10 +45,10 @@
package org.eclipse.jgit.diff; package org.eclipse.jgit.diff;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.IntList; import org.eclipse.jgit.util.IntList;
import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.RawParseUtils;
@ -99,7 +99,7 @@ public RawText(final byte[] input) {
* @throws IOException if Exceptions occur while reading the file * @throws IOException if Exceptions occur while reading the file
*/ */
public RawText(File file) throws IOException { public RawText(File file) throws IOException {
this(readFile(file)); this(IO.readFully(file));
} }
public int size() { public int size() {
@ -202,16 +202,4 @@ protected int hashLine(final byte[] raw, int ptr, final int end) {
hash = (hash << 5) ^ (raw[ptr] & 0xff); hash = (hash << 5) ^ (raw[ptr] & 0xff);
return hash; return hash;
} }
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;
}
} }