Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/io/FileSystem.java
38829 views
/*1* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.io;2627import java.lang.annotation.Native;2829/**30* Package-private abstract class for the local filesystem abstraction.31*/3233abstract class FileSystem {3435/* -- Normalization and construction -- */3637/**38* Return the local filesystem's name-separator character.39*/40public abstract char getSeparator();4142/**43* Return the local filesystem's path-separator character.44*/45public abstract char getPathSeparator();4647/**48* Convert the given pathname string to normal form. If the string is49* already in normal form then it is simply returned.50*/51public abstract String normalize(String path);5253/**54* Compute the length of this pathname string's prefix. The pathname55* string must be in normal form.56*/57public abstract int prefixLength(String path);5859/**60* Resolve the child pathname string against the parent.61* Both strings must be in normal form, and the result62* will be in normal form.63*/64public abstract String resolve(String parent, String child);6566/**67* Return the parent pathname string to be used when the parent-directory68* argument in one of the two-argument File constructors is the empty69* pathname.70*/71public abstract String getDefaultParent();7273/**74* Post-process the given URI path string if necessary. This is used on75* win32, e.g., to transform "/c:/foo" into "c:/foo". The path string76* still has slash separators; code in the File class will translate them77* after this method returns.78*/79public abstract String fromURIPath(String path);808182/* -- Path operations -- */8384/**85* Tell whether or not the given abstract pathname is absolute.86*/87public abstract boolean isAbsolute(File f);8889/**90* Resolve the given abstract pathname into absolute form. Invoked by the91* getAbsolutePath and getCanonicalPath methods in the File class.92*/93public abstract String resolve(File f);9495public abstract String canonicalize(String path) throws IOException;969798/* -- Attribute accessors -- */99100/* Constants for simple boolean attributes */101@Native public static final int BA_EXISTS = 0x01;102@Native public static final int BA_REGULAR = 0x02;103@Native public static final int BA_DIRECTORY = 0x04;104@Native public static final int BA_HIDDEN = 0x08;105106/**107* Return the simple boolean attributes for the file or directory denoted108* by the given abstract pathname, or zero if it does not exist or some109* other I/O error occurs.110*/111public abstract int getBooleanAttributes(File f);112113@Native public static final int ACCESS_READ = 0x04;114@Native public static final int ACCESS_WRITE = 0x02;115@Native public static final int ACCESS_EXECUTE = 0x01;116117/**118* Check whether the file or directory denoted by the given abstract119* pathname may be accessed by this process. The second argument specifies120* which access, ACCESS_READ, ACCESS_WRITE or ACCESS_EXECUTE, to check.121* Return false if access is denied or an I/O error occurs122*/123public abstract boolean checkAccess(File f, int access);124/**125* Set on or off the access permission (to owner only or to all) to the file126* or directory denoted by the given abstract pathname, based on the parameters127* enable, access and oweronly.128*/129public abstract boolean setPermission(File f, int access, boolean enable, boolean owneronly);130131/**132* Return the time at which the file or directory denoted by the given133* abstract pathname was last modified, or zero if it does not exist or134* some other I/O error occurs.135*/136public abstract long getLastModifiedTime(File f);137138/**139* Return the length in bytes of the file denoted by the given abstract140* pathname, or zero if it does not exist, is a directory, or some other141* I/O error occurs.142*/143public abstract long getLength(File f);144145146/* -- File operations -- */147148/**149* Create a new empty file with the given pathname. Return150* <code>true</code> if the file was created and <code>false</code> if a151* file or directory with the given pathname already exists. Throw an152* IOException if an I/O error occurs.153*/154public abstract boolean createFileExclusively(String pathname)155throws IOException;156157/**158* Delete the file or directory denoted by the given abstract pathname,159* returning <code>true</code> if and only if the operation succeeds.160*/161public abstract boolean delete(File f);162163/**164* List the elements of the directory denoted by the given abstract165* pathname. Return an array of strings naming the elements of the166* directory if successful; otherwise, return <code>null</code>.167*/168public abstract String[] list(File f);169170/**171* Create a new directory denoted by the given abstract pathname,172* returning <code>true</code> if and only if the operation succeeds.173*/174public abstract boolean createDirectory(File f);175176/**177* Rename the file or directory denoted by the first abstract pathname to178* the second abstract pathname, returning <code>true</code> if and only if179* the operation succeeds.180*/181public abstract boolean rename(File f1, File f2);182183/**184* Set the last-modified time of the file or directory denoted by the185* given abstract pathname, returning <code>true</code> if and only if the186* operation succeeds.187*/188public abstract boolean setLastModifiedTime(File f, long time);189190/**191* Mark the file or directory denoted by the given abstract pathname as192* read-only, returning <code>true</code> if and only if the operation193* succeeds.194*/195public abstract boolean setReadOnly(File f);196197198/* -- Filesystem interface -- */199200/**201* List the available filesystem roots.202*/203public abstract File[] listRoots();204205/* -- Disk usage -- */206@Native public static final int SPACE_TOTAL = 0;207@Native public static final int SPACE_FREE = 1;208@Native public static final int SPACE_USABLE = 2;209210public abstract long getSpace(File f, int t);211212/* -- Basic infrastructure -- */213214/**215* Compare two abstract pathnames lexicographically.216*/217public abstract int compare(File f1, File f2);218219/**220* Compute the hash code of an abstract pathname.221*/222public abstract int hashCode(File f);223224// Flags for enabling/disabling performance optimizations for file225// name canonicalization226static boolean useCanonCaches = true;227static boolean useCanonPrefixCache = true;228229private static boolean getBooleanProperty(String prop, boolean defaultVal) {230String val = System.getProperty(prop);231if (val == null) return defaultVal;232if (val.equalsIgnoreCase("true")) {233return true;234} else {235return false;236}237}238239static {240useCanonCaches = getBooleanProperty("sun.io.useCanonCaches",241useCanonCaches);242useCanonPrefixCache = getBooleanProperty("sun.io.useCanonPrefixCache",243useCanonPrefixCache);244}245}246247248