001package org.kuali.common.util.file;
002
003import java.io.File;
004import java.io.IOException;
005import java.net.URI;
006
007/**
008 * A <code>CanonicalFile</code> is always both absolute and unique.
009 */
010public final class CanonicalFile extends File {
011
012        private static final long serialVersionUID = -8366640724070158688L;
013
014        /**
015         * A <code>CanonicalFile</code> is always both absolute and unique.
016         */
017        public CanonicalFile(File parent, String child) {
018                this(new File(parent, child));
019        }
020
021        /**
022         * A <code>CanonicalFile</code> is always both absolute and unique.
023         */
024        public CanonicalFile(String parent, String child) {
025                this(new File(parent, child));
026        }
027
028        /**
029         * A <code>CanonicalFile</code> is always both absolute and unique.
030         */
031        public CanonicalFile(URI uri) {
032                this(new File(uri));
033        }
034
035        /**
036         * A <code>CanonicalFile</code> is always both absolute and unique.
037         */
038        public CanonicalFile(String path) {
039                this(new File(path));
040        }
041
042        /**
043         * A <code>CanonicalFile</code> is always both absolute and unique.
044         */
045        public CanonicalFile(File file) {
046                super(getCanonicalPath(file));
047        }
048
049        /**
050         * Return the current working directory.
051         */
052        public static final CanonicalFile cwd() {
053                return new CanonicalFile(".");
054        }
055
056        protected static String getCanonicalPath(File file) {
057                try {
058                        return file.getCanonicalPath();
059                } catch (IOException e) {
060                        throw new IllegalStateException("Unexpected IO error", e);
061                }
062        }
063
064}