001/*
002 * Copyright 2011-2012 Stephen Connolly.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.jszip.pseudo.io;
018
019import java.io.IOException;
020import java.io.InputStream;
021import java.io.OutputStream;
022
023public class VirtualDirectoryPseudoFile extends PseudoFile {
024    private final String name;
025    private final long lastModified;
026
027    public VirtualDirectoryPseudoFile(PseudoFile parent, String name) {
028        super(parent);
029        this.name = name;
030        this.lastModified = System.currentTimeMillis();
031    }
032
033    /**
034     * {@inheritDoc}
035     */
036    public boolean canRead() {
037        return true;
038    }
039
040    /**
041     * {@inheritDoc}
042     */
043    public boolean canWrite() {
044        return false;
045    }
046
047    /**
048     * {@inheritDoc}
049     */
050    public boolean createNewFile() throws IOException {
051        throw new IOException(getPath() + " is a virtual directory");
052    }
053
054    /**
055     * {@inheritDoc}
056     */
057    public boolean delete() {
058        return false;
059    }
060
061    /**
062     * {@inheritDoc}
063     */
064    public void deleteOnExit() {
065    }
066
067    /**
068     * {@inheritDoc}
069     */
070    public boolean exists() {
071        return true;
072    }
073
074    /**
075     * {@inheritDoc}
076     */
077    public String getName() {
078        return name;
079    }
080
081    /**
082     * {@inheritDoc}
083     */
084    public boolean isDirectory() {
085        return true;
086    }
087
088    /**
089     * {@inheritDoc}
090     */
091    public boolean isFile() {
092        return false;
093    }
094
095    /**
096     * {@inheritDoc}
097     */
098    public boolean isHidden() {
099        return false;
100    }
101
102    /**
103     * {@inheritDoc}
104     */
105    public long lastModified() {
106        return lastModified;
107    }
108
109    /**
110     * {@inheritDoc}
111     */
112    public long length() {
113        return 0;
114    }
115
116    /**
117     * {@inheritDoc}
118     */
119    public boolean mkdir() {
120        return false;
121    }
122
123    /**
124     * {@inheritDoc}
125     */
126    public boolean mkdirs() {
127        return false;
128    }
129
130    /**
131     * {@inheritDoc}
132     */
133    public boolean renameTo(PseudoFile dest) {
134        return false;
135    }
136
137    /**
138     * {@inheritDoc}
139     */
140    public boolean setLastModified(long time) {
141        return false;
142    }
143
144    /**
145     * {@inheritDoc}
146     */
147    InputStream $newInputStream() throws IOException {
148        throw new IOException(getPath() + " is a virtual directory");
149    }
150
151    /**
152     * {@inheritDoc}
153     */
154    OutputStream $newOutputStream() throws IOException {
155        throw new IOException(getPath() + " is a virtual directory");
156    }
157
158    /**
159     * {@inheritDoc}
160     */
161    OutputStream $newOutputStream(boolean append) throws IOException {
162        throw new IOException(getPath() + " is a virtual directory");
163    }
164}