Adapt to stricter Eclipse error checking
[egit.git] / org.spearce.jgit / src / org / spearce / jgit / lib / CheckoutTree.java
blob21003795819ddcf09da9a3acc4bee8e906fc7ee3
1 /*
2 * Copyright (C) 2006 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org.spearce.jgit.lib;
19 import java.io.File;
20 import java.io.FileOutputStream;
21 import java.io.IOException;
23 import org.spearce.jgit.errors.IncorrectObjectTypeException;
24 import org.spearce.jgit.errors.MissingObjectException;
26 public class CheckoutTree extends TreeVisitorWithCurrentDirectory {
27 private static final String TYPE_BLOB = Constants.TYPE_BLOB;
29 public CheckoutTree(final File root) {
30 super(root);
33 public void visitFile(final FileTreeEntry fte) throws IOException {
34 final File destFile = new File(getCurrentDirectory(), fte.getName());
35 final ObjectLoader loader = fte.openReader();
36 if (loader == null)
37 throw new MissingObjectException(fte.getId(), TYPE_BLOB);
38 final byte[] data = loader.getBytes();
39 if (!TYPE_BLOB.equals(loader.getType()))
40 throw new IncorrectObjectTypeException(fte.getId(), TYPE_BLOB);
41 final FileOutputStream fos = new FileOutputStream(destFile);
42 try {
43 fos.write(data);
44 } finally {
45 fos.close();
49 public void visitSymlink(final SymlinkTreeEntry s) throws IOException {
50 // TODO: handle symlinks. Only problem is that JGit is indepent of Eclipse
51 // and Pure Java does not know what to do about symbolic links.
54 public void startVisitTree(final Tree t) throws IOException {
55 super.startVisitTree(t);
56 getCurrentDirectory().mkdirs();