2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import gov.nasa.jpf.annotation.FilterField;
23 import java.net.URISyntaxException;
28 * MJI model class for java.io.File
30 * NOTE - a number of methods are only stubbed out here to make Eclipse compile
31 * JPF code that uses java.io.File (there is no way to tell Eclipse to exclude the
32 * model classes from ths build-path)
34 * @author Owen O'Malley
38 public static final String separator = System.getProperty("file.separator");
39 public static final char separatorChar = separator.charAt(0);
40 public static final String pathSeparator = System.getProperty("path.separator");
41 public static final char pathSeparatorChar = pathSeparator.charAt(0);
43 @FilterField int id; // link to the real File object
44 private String filename;
46 public File(String filename) {
47 if (filename == null){
48 throw new NullPointerException();
51 this.filename = filename;
54 public File (String parent, String child) {
55 filename = parent + separator + child;
58 public File (File parent, String child) {
59 filename = parent.filename + separator + child;
62 public File(java.net.URI uri) { throw new UnsupportedOperationException(); }
64 public String getName() {
65 int idx = filename.lastIndexOf(separatorChar);
67 return filename.substring(idx+1);
73 public String getParent() {
74 int idx = filename.lastIndexOf(separatorChar);
76 return filename.substring(0,idx);
82 public int compareTo(File that) {
83 return this.filename.compareTo(that.filename);
87 public boolean equals(Object o) {
88 if (o instanceof File){
89 File otherFile = (File) o;
90 return filename.equals(otherFile.filename);
97 public int hashCode() {
98 return filename.hashCode();
102 public String toString() {
107 //--- native peer intercepted (hopefully)
109 int getPrefixLength() { return 0; }
110 public native File getParentFile();
112 public String getPath() {
116 public native boolean isAbsolute();
117 public native String getAbsolutePath();
118 public native File getAbsoluteFile();
119 public native String getCanonicalPath() throws java.io.IOException;
121 public native File getCanonicalFile() throws java.io.IOException;
123 private native String getURLSpec();
124 public java.net.URL toURL() throws java.net.MalformedURLException {
125 return new URL(getURLSpec());
128 private native String getURISpec();
129 public java.net.URI toURI() {
131 return new URI(getURISpec());
132 } catch (URISyntaxException x){
137 public native boolean canRead();
138 public native boolean canWrite();
139 public native boolean exists();
140 public boolean isDirectory() { return false; }
141 public boolean isFile() { return false; }
142 public boolean isHidden() { return false; }
143 public long lastModified() { return -1L; }
144 public long length() { return -1; }
145 public native boolean createNewFile() throws java.io.IOException;
146 public boolean delete() { return false; }
147 public void deleteOnExit() {}
148 public String[] list() { return null; }
149 public String[] list(FilenameFilter fnf) { return null; }
150 public File[] listFiles() { return null; }
151 public File[] listFiles(FilenameFilter fnf) { return null; }
152 public File[] listFiles(FileFilter ff) { return null; }
153 public boolean mkdir() { return false; }
154 public boolean mkdirs() { return false; }
155 public boolean renameTo(File f) { return false; }
156 public boolean setLastModified(long t) { return false; }
157 public boolean setReadOnly() { return false; }
159 public static native File[] listRoots();
161 public static File createTempFile(String prefix, String suffix, File dir) throws IOException {
163 throw new NullPointerException();
168 tmpDir = System.getProperty("java.io.tmpdir");
172 if (tmpDir.charAt(tmpDir.length()-1) != separatorChar){
173 tmpDir += separatorChar;
180 tmpDir = dir.getPath();
183 return new File(tmpDir + prefix + suffix);
186 public static File createTempFile(String prefix, String suffix) throws IOException {
187 return createTempFile(prefix, suffix, null);