]> source.dussan.org Git - jgit.git/commitdiff
Use copyTo during checkout of files to working tree 25/1025/1
authorShawn O. Pearce <spearce@spearce.org>
Thu, 1 Jul 2010 01:56:20 +0000 (18:56 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Thu, 1 Jul 2010 01:56:20 +0000 (18:56 -0700)
This way we can stream a large file through memory, rather than
loading the entire thing into a single contiguous byte array.

Change-Id: I3ada2856af2bf518f072edec242667a486fb0df1
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java

index 0495d38a110ef823cb45a0a6211cf4ee863f1e1b..1df25ca708c53ccfbfd0f4df4e3542f497dd3c7d 100644 (file)
@@ -874,16 +874,15 @@ public class GitIndex {
         */
        public void checkoutEntry(File wd, Entry e) throws IOException {
                ObjectLoader ol = db.open(e.sha1, Constants.OBJ_BLOB);
-               byte[] bytes = ol.getBytes();
                File file = new File(wd, e.getName());
                file.delete();
                file.getParentFile().mkdirs();
-               FileChannel channel = new FileOutputStream(file).getChannel();
-               ByteBuffer buffer = ByteBuffer.wrap(bytes);
-               int j = channel.write(buffer);
-               if (j != bytes.length)
-                       throw new IOException(MessageFormat.format(JGitText.get().couldNotWriteFile, file));
-               channel.close();
+               FileOutputStream dst = new FileOutputStream(file);
+               try {
+                       ol.copyTo(dst);
+               } finally {
+                       dst.close();
+               }
                if (config_filemode() && File_hasExecute()) {
                        if (FileMode.EXECUTABLE_FILE.equals(e.mode)) {
                                if (!File_canExecute(file))