001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package se.mog.io;
019:
020: import java.io.IOException;
021:
022: import java.net.URI;
023:
024: /**
025: * @author <a href="mailto:drftpd@mog.se">Morgan Christiansson</a>
026: * @version $Id: File.java 1523 2006-10-19 18:38:08Z tdsoul $
027: */
028: public class File extends java.io.File {
029: private static FileSystem fs = FileSystem.getFileSystem();
030: public static String separator = "/";
031:
032: /**
033: * @param pathname
034: */
035: public File(String pathname) {
036: super (pathname);
037: }
038:
039: public File(java.io.File file) {
040: super (file.getPath());
041: }
042:
043: /**
044: * @param parent
045: * @param child
046: */
047: public File(String parent, String child) {
048: super (parent, child);
049: }
050:
051: /**
052: * @param parent
053: * @param child
054: */
055: public File(java.io.File parent, String child) {
056: super (parent, child);
057: }
058:
059: /**
060: * @param uri
061: */
062: public File(URI uri) {
063: super (uri);
064: }
065:
066: /**
067: * Returns all mounted volumes on the system, this includes file system roots.
068: *
069: * @see java.io.File#listRoots()
070: */
071: public static File[] listMounts() throws IOException {
072: return fs.listMounts();
073: }
074:
075: public long getDiskSpaceAvailable() {
076: return fs.getDiskFreeSpace(this ).freeBytes;
077: }
078:
079: public long getDiskSpaceCapacity() {
080: return fs.getDiskFreeSpace(this ).totalBytes;
081: }
082:
083: public boolean isSymbolicLink() throws IOException {
084: return !getCanonicalPath().equals(getAbsolutePath());
085: }
086:
087: /**
088: * Works exactly like <code>{@link java.io.File#delete()}</code> but has the added funcionality of working recursively.
089: * @see java.io.File#delete()
090: */
091: public boolean deleteRecursive() {
092: if (isDirectory()) {
093: java.io.File[] files = listFiles();
094:
095: for (int i = 0; i < files.length; i++) {
096: File file = new File(files[i]);
097: file.deleteRecursive();
098: }
099: }
100:
101: return super .delete();
102: }
103:
104: public void delete2() throws PermissionDeniedException {
105: if (!super .delete()) {
106: throw new PermissionDeniedException("Failed to delete: "
107: + toString());
108: }
109: }
110:
111: public void mkdirs2() throws PermissionDeniedException {
112: if (!exists()) {
113: if (!mkdirs()) {
114: throw new PermissionDeniedException("mkdirs failed on "
115: + getPath());
116: }
117: }
118: }
119: }
|