001    /* Copyright 2000, 2001, Compaq Computer Corporation */
002    
003    package javafe.genericfile;
004    
005    
006    import java.io.IOException;
007    import java.io.InputStream;
008    
009    
010    /**
011     * Instances of UnopenableFile are {@link GenericFile}s that cannot
012     * be opened. <p>
013     *
014     * Their value lies solely in their associated naming, etc., info.<p>
015     *
016     * Example: {@link javafe.util.CorrelatedReader}'s keeps an open
017     * {@link InputStream} and an associated {@link GenericFile}.  In the
018     * case of unreopenable streams like stdin, the associated {@link
019     * GenericFile} is an UnopenableFile with the name "stdin".
020     */
021    
022    public class UnopenableFile implements GenericFile {
023    
024        /***************************************************
025         *                                                 *
026         * Instance variables:                             *
027         *                                                 *
028         **************************************************/
029    
030        //* Our human readable name:
031        /*@ non_null @*/ String humanName;
032    
033        //* Are we a directory?
034        boolean isDir;
035    
036    
037        /***************************************************
038         *                                                 *
039         * Creation:                                       *
040         *                                                 *
041         **************************************************/
042    
043        /**
044         * Create a ordinary (aka, non-directory) UnopenableFile with
045         * human-name name.
046         *
047         * The resulting file has no modification date available and a
048         * local name of "".
049         */
050        public UnopenableFile(/*@ non_null @*/ String name) {
051            this(name, false);
052        }
053    
054    
055        /**
056         * Create an UnopenableFile with human-name name that is a
057         * directory iff isDir.
058         *
059         * The resulting file has no modification date available and a
060         * local name of "".
061         */
062        public UnopenableFile(/*@ non_null @*/ String name, boolean isDir) {
063            humanName = name;
064            this.isDir = isDir;
065        }
066    
067    
068        /***************************************************
069         *                                                 *
070         * GenericFile interface implementation:           *
071         *                                                 *
072         **************************************************/
073    
074        public String getHumanName() { return humanName; }
075    
076        public String getCanonicalID() {
077            return "<javafe.filespace.UnopenableFile>" + humanName;
078        }
079    
080        public String getLocalName() { return ""; }
081    
082        public boolean isDirectory() { return isDir; }
083    
084        public InputStream getInputStream() throws IOException {
085            throw new IOException(
086                "Attempt to open an unopenable genericfile");
087        }
088    
089        public long lastModified() { return 0L; }
090    
091        public GenericFile getSibling(String n) { return null; }
092    }