Source Home >> Java Source 1.6.0 >> java.io. V 0.09
  • 001/*
  • 002 * @(#)FileSystem.java 1.18 05/12/01
  • 003 *
  • 004 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  • 005 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  • 006 */
  • 007
  • 008package java.io;
  • 009
  • 010
  • 011/**
  • 012 * Package-private abstract class for the local filesystem abstraction.
  • 013 */
  • 014
  • 015abstract class FileSystem {
  • 016
  • 017 /**
  • 018 * Return the FileSystem object representing this platform's local
  • 019 * filesystem.
  • 020 */
  • 021 public static native FileSystem getFileSystem();
  • 022
  • 023
  • 024 /* -- Normalization and construction -- */
  • 025
  • 026 /**
  • 027 * Return the local filesystem's name-separator character.
  • 028 */
  • 029 public abstract char getSeparator();
  • 030
  • 031 /**
  • 032 * Return the local filesystem's path-separator character.
  • 033 */
  • 034 public abstract char getPathSeparator();
  • 035
  • 036 /**
  • 037 * Convert the given pathname string to normal form. If the string is
  • 038 * already in normal form then it is simply returned.
  • 039 */
  • 040 public abstract String normalize(String path);
  • 041
  • 042 /**
  • 043 * Compute the length of this pathname string's prefix. The pathname
  • 044 * string must be in normal form.
  • 045 */
  • 046 public abstract int prefixLength(String path);
  • 047
  • 048 /**
  • 049 * Resolve the child pathname string against the parent.
  • 050 * Both strings must be in normal form, and the result
  • 051 * will be in normal form.
  • 052 */
  • 053 public abstract String resolve(String parent, String child);
  • 054
  • 055 /**
  • 056 * Return the parent pathname string to be used when the parent-directory
  • 057 * argument in one of the two-argument File constructors is the empty
  • 058 * pathname.
  • 059 */
  • 060 public abstract String getDefaultParent();
  • 061
  • 062 /**
  • 063 * Post-process the given URI path string if necessary. This is used on
  • 064 * win32, e.g., to transform "/c:/foo" into "c:/foo". The path string
  • 065 * still has slash separators; code in the File class will translate them
  • 066 * after this method returns.
  • 067 */
  • 068 public abstract String fromURIPath(String path);
  • 069
  • 070
  • 071 /* -- Path operations -- */
  • 072
  • 073 /**
  • 074 * Tell whether or not the given abstract pathname is absolute.
  • 075 */
  • 076 public abstract boolean isAbsolute(File f);
  • 077
  • 078 /**
  • 079 * Resolve the given abstract pathname into absolute form. Invoked by the
  • 080 * getAbsolutePath and getCanonicalPath methods in the File class.
  • 081 */
  • 082 public abstract String resolve(File f);
  • 083
  • 084 public abstract String canonicalize(String path) throws IOException;
  • 085
  • 086
  • 087 /* -- Attribute accessors -- */
  • 088
  • 089 /* Constants for simple boolean attributes */
  • 090 public static final int BA_EXISTS = 0x01;
  • 091 public static final int BA_REGULAR = 0x02;
  • 092 public static final int BA_DIRECTORY = 0x04;
  • 093 public static final int BA_HIDDEN = 0x08;
  • 094
  • 095 /**
  • 096 * Return the simple boolean attributes for the file or directory denoted
  • 097 * by the given abstract pathname, or zero if it does not exist or some
  • 098 * other I/O error occurs.
  • 099 */
  • 100 public abstract int getBooleanAttributes(File f);
  • 101
  • 102 public static final int ACCESS_READ = 0x04;
  • 103 public static final int ACCESS_WRITE = 0x02;
  • 104 public static final int ACCESS_EXECUTE = 0x01;
  • 105
  • 106 /**
  • 107 * Check whether the file or directory denoted by the given abstract
  • 108 * pathname may be accessed by this process. The second argument specifies
  • 109 * which access, ACCESS_READ, ACCESS_WRITE or ACCESS_EXECUTE, to check.
  • 110 * Return false if access is denied or an I/O error occurs
  • 111 */
  • 112 public abstract boolean checkAccess(File f, int access);
  • 113 /**
  • 114 * Set on or off the access permission (to owner only or to all) to the file
  • 115 * or directory denoted by the given abstract pathname, based on the parameters
  • 116 * enable, access and oweronly.
  • 117 */
  • 118 public abstract boolean setPermission(File f, int access, boolean enable, boolean owneronly);
  • 119
  • 120 /**
  • 121 * Return the time at which the file or directory denoted by the given
  • 122 * abstract pathname was last modified, or zero if it does not exist or
  • 123 * some other I/O error occurs.
  • 124 */
  • 125 public abstract long getLastModifiedTime(File f);
  • 126
  • 127 /**
  • 128 * Return the length in bytes of the file denoted by the given abstract
  • 129 * pathname, or zero if it does not exist, is a directory, or some other
  • 130 * I/O error occurs.
  • 131 */
  • 132 public abstract long getLength(File f);
  • 133
  • 134
  • 135 /* -- File operations -- */
  • 136
  • 137 /**
  • 138 * Create a new empty file with the given pathname. Return
  • 139 * <code>true</code> if the file was created and <code>false</code> if a
  • 140 * file or directory with the given pathname already exists. Throw an
  • 141 * IOException if an I/O error occurs.
  • 142 */
  • 143 public abstract boolean createFileExclusively(String pathname)
  • 144 throws IOException;
  • 145
  • 146 /**
  • 147 * Delete the file or directory denoted by the given abstract pathname,
  • 148 * returning <code>true</code> if and only if the operation succeeds.
  • 149 */
  • 150 public abstract boolean delete(File f);
  • 151
  • 152 /**
  • 153 * List the elements of the directory denoted by the given abstract
  • 154 * pathname. Return an array of strings naming the elements of the
  • 155 * directory if successful; otherwise, return <code>null</code>.
  • 156 */
  • 157 public abstract String[] list(File f);
  • 158
  • 159 /**
  • 160 * Create a new directory denoted by the given abstract pathname,
  • 161 * returning <code>true</code> if and only if the operation succeeds.
  • 162 */
  • 163 public abstract boolean createDirectory(File f);
  • 164
  • 165 /**
  • 166 * Rename the file or directory denoted by the first abstract pathname to
  • 167 * the second abstract pathname, returning <code>true</code> if and only if
  • 168 * the operation succeeds.
  • 169 */
  • 170 public abstract boolean rename(File f1, File f2);
  • 171
  • 172 /**
  • 173 * Set the last-modified time of the file or directory denoted by the
  • 174 * given abstract pathname, returning <code>true</code> if and only if the
  • 175 * operation succeeds.
  • 176 */
  • 177 public abstract boolean setLastModifiedTime(File f, long time);
  • 178
  • 179 /**
  • 180 * Mark the file or directory denoted by the given abstract pathname as
  • 181 * read-only, returning <code>true</code> if and only if the operation
  • 182 * succeeds.
  • 183 */
  • 184 public abstract boolean setReadOnly(File f);
  • 185
  • 186
  • 187 /* -- Filesystem interface -- */
  • 188
  • 189 /**
  • 190 * List the available filesystem roots.
  • 191 */
  • 192 public abstract File[] listRoots();
  • 193
  • 194 /* -- Disk usage -- */
  • 195 public static final int SPACE_TOTAL = 0;
  • 196 public static final int SPACE_FREE = 1;
  • 197 public static final int SPACE_USABLE = 2;
  • 198
  • 199 public abstract long getSpace(File f, int t);
  • 200
  • 201 /* -- Basic infrastructure -- */
  • 202
  • 203 /**
  • 204 * Compare two abstract pathnames lexicographically.
  • 205 */
  • 206 public abstract int compare(File f1, File f2);
  • 207
  • 208 /**
  • 209 * Compute the hash code of an abstract pathname.
  • 210 */
  • 211 public abstract int hashCode(File f);
  • 212
  • 213 // Flags for enabling/disabling performance optimizations for file
  • 214 // name canonicalization
  • 215 static boolean useCanonCaches = true;
  • 216 static boolean useCanonPrefixCache = true;
  • 217
  • 218 private static boolean getBooleanProperty(String prop, boolean defaultVal) {
  • 219 String val = System.getProperty(prop);
  • 220 if (val == null) return defaultVal;
  • 221 if (val.equalsIgnoreCase("true")) {
  • 222 return true;
  • 223 } else {
  • 224 return false;
  • 225 }
  • 226 }
  • 227
  • 228 static {
  • 229 useCanonCaches = getBooleanProperty("sun.io.useCanonCaches",
  • 230 useCanonCaches);
  • 231 useCanonPrefixCache = getBooleanProperty("sun.io.useCanonPrefixCache",
  • 232 useCanonPrefixCache);
  • 233 }
  • 234}

文件:FileSystem.java
包名:java.io
类名:
继承:
接口: