1 package org
.spearce
.jgit
.lib
;
4 import java
.io
.FileOutputStream
;
5 import java
.io
.IOException
;
6 import java
.io
.InputStream
;
7 import java
.util
.Iterator
;
9 public class FileCopier
{
10 public void copyOut(final Tree src
, final File dest
) throws IOException
{
12 copyOut(src
, dest
, new byte[8192]);
15 protected void copyOut(final Tree src
, final File dest
,
16 final byte[] copyBuffer
) throws IOException
{
19 i
= src
.getTreeEntries().iterator();
21 final Tree
.Entry e
= (Tree
.Entry
) i
.next();
22 final File f
= new File(dest
, e
.getName());
26 copyOut(e
.getTree(), f
, copyBuffer
);
27 } else if (e
.isSymlink()) {
28 // TODO: We don't handle symlinks right now.
30 final ObjectReader or
= e
.openBlob();
33 throw new CorruptObjectException("Missing blob "
36 is
= or
.getInputStream();
38 final FileOutputStream fos
= new FileOutputStream(f
);
41 while ((r
= is
.read(copyBuffer
)) > 0) {
42 fos
.write(copyBuffer
, 0, r
);