From 16330bd2d0ceff3a023c7d7d9f25d8d125db06b9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 20 Apr 2009 18:21:05 -0700 Subject: [PATCH] Replace hand-coded read fully loop with NB.readFully This code predates the NB utility class. I'd prefer to reuse the code over keeping this duplicate copy of the logic. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../src/org/spearce/jgit/lib/UnpackedObjectLoader.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java index f2cae87f..b086821f 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/UnpackedObjectLoader.java @@ -46,6 +46,7 @@ import java.util.zip.Inflater; import org.spearce.jgit.errors.CorruptObjectException; import org.spearce.jgit.util.MutableInteger; +import org.spearce.jgit.util.NB; import org.spearce.jgit.util.RawParseUtils; /** @@ -74,17 +75,14 @@ public class UnpackedObjectLoader extends ObjectLoader { private static byte[] readCompressed(final Repository db, final AnyObjectId id) throws FileNotFoundException, IOException { - final FileInputStream objStream = new FileInputStream(db.toFile(id)); - final byte[] compressed; + final FileInputStream in = new FileInputStream(db.toFile(id)); try { - compressed = new byte[objStream.available()]; - int off = 0; - while (off < compressed.length) - off += objStream.read(compressed, off, compressed.length - off); + final byte[] compressed = new byte[(int) in.getChannel().size()]; + NB.readFully(in, compressed, 0, compressed.length); + return compressed; } finally { - objStream.close(); + in.close(); } - return compressed; } /** -- 2.11.4.GIT