Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / vm / reference / java / io / VMFile.java
blob2931044c85376a337bfe06d720000a4bfe0ebc8b
1 /* VMFile.java -- Class for methods natively accessing files
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.io;
41 import gnu.classpath.Configuration;
42 import gnu.java.io.PlatformHelper;
45 /**
46 * @author Michael Koch (konqueror@gmx.de)
48 final class VMFile
50 // FIXME: We support only case sensitive filesystems currently.
51 static final boolean IS_CASE_SENSITIVE = true;
52 static final boolean IS_DOS_8_3 = false;
54 static
56 if (Configuration.INIT_LOAD_LIBRARY)
58 System.loadLibrary("javaio");
63 * This native method does the actual work of getting the last file
64 * modification time. It also does the existence check to avoid the
65 * overhead of a call to exists()
67 static native long lastModified(String path);
70 * This native method sets the permissions to make the file read only.
72 static native boolean setReadOnly(String path);
74 /**
75 * This method is used to create a temporary file
77 static native boolean create(String path) throws IOException;
80 * This native function actually produces the list of file in this
81 * directory
83 static native String[] list(String dirpath);
86 * This native method actually performs the rename.
88 static native boolean renameTo(String targetpath, String destpath);
91 * This native method actually determines the length of the file and
92 * handles the existence check
94 static native long length(String path);
97 * This native method does the actual checking of file existence.
99 static native boolean exists(String path);
102 * This native method handles the actual deleting of the file
104 static native boolean delete(String path);
107 * This method does the actual setting of the modification time.
109 static native boolean setLastModified(String path, long time);
112 * This native method actually creates the directory
114 static native boolean mkdir(String dirpath);
117 * This native method does the actual check of whether or not a file
118 * is a plain file or not. It also handles the existence check to
119 * eliminate the overhead of a call to exists()
121 static native boolean isFile(String path);
124 * This native method checks file permissions for writing
126 static synchronized native boolean canWrite(String path);
129 * This methods checks if a directory can be written to.
131 static boolean canWriteDirectory(File dir)
135 String filename = IS_DOS_8_3 ? "tst" : "test-dir-write";
136 File test = File.createTempFile(filename, null, dir);
137 return (test != null && test.delete());
139 catch (IOException ioe)
141 return false;
146 * This native method checks file permissions for reading
148 static synchronized native boolean canRead(String path);
151 * This method does the actual check of whether or not a file is a
152 * directory or not. It also handle the existence check to eliminate
153 * the overhead of a call to exists()
155 static native boolean isDirectory(String dirpath);
158 * This method returns an array of filesystem roots. Some operating systems
159 * have volume oriented filesystem. This method provides a mechanism for
160 * determining which volumes exist. GNU systems use a single hierarchical
161 * filesystem, so will have only one "/" filesystem root.
163 * @return An array of <code>File</code> objects for each filesystem root
164 * available.
166 * @since 1.2
168 static File[] listRoots()
170 File[] roots = new File[1];
171 roots[0] = new File("/");
172 return roots;
176 * This method tests whether or not this file represents a "hidden" file.
177 * On GNU systems, a file is hidden if its name begins with a "."
178 * character. Files with these names are traditionally not shown with
179 * directory listing tools.
181 * @return <code>true</code> if the file is hidden, <code>false</code>
182 * otherwise.
184 * @since 1.2
186 static boolean isHidden(String path)
188 // FIXME: this only works on UNIX
189 return getName(path).startsWith(".");
193 * This method returns the name of the file. This is everything in the
194 * complete path of the file after the last instance of the separator
195 * string.
197 * @return The file name
199 static String getName(String path)
201 int pos = PlatformHelper.lastIndexOfSeparator(path);
202 if (pos == -1)
203 return path;
205 if (PlatformHelper.endWithSeparator(path))
206 return "";
208 return path.substring(pos + File.separator.length());
212 * This method returns a canonical representation of the pathname of
213 * the given path. The actual form of the canonical representation is
214 * different. On the GNU system, the canonical form differs from the
215 * absolute form in that all relative file references to "." and ".."
216 * are resolved and removed.
217 * <p>
218 * Note that this method, unlike the other methods which return path
219 * names, can throw an IOException. This is because native method
220 * might be required in order to resolve the canonical path
222 * @exception IOException If an error occurs
224 public static String toCanonicalForm(String path) throws IOException
226 // FIXME: this only works on UNIX
227 return PlatformHelper.toCanonicalForm(path);