1. /*
  2. * @(#)FileSystem.java 1.13 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.io;
  8. /**
  9. * Package-private abstract class for the local filesystem abstraction.
  10. */
  11. abstract class FileSystem {
  12. /**
  13. * Return the FileSystem object representing this platform's local
  14. * filesystem.
  15. */
  16. public static native FileSystem getFileSystem();
  17. /* -- Normalization and construction -- */
  18. /**
  19. * Return the local filesystem's name-separator character.
  20. */
  21. public abstract char getSeparator();
  22. /**
  23. * Return the local filesystem's path-separator character.
  24. */
  25. public abstract char getPathSeparator();
  26. /**
  27. * Convert the given pathname string to normal form. If the string is
  28. * already in normal form then it is simply returned.
  29. */
  30. public abstract String normalize(String path);
  31. /**
  32. * Compute the length of this pathname string's prefix. The pathname
  33. * string must be in normal form.
  34. */
  35. public abstract int prefixLength(String path);
  36. /**
  37. * Resolve the child pathname string against the parent.
  38. * Both strings must be in normal form, and the result
  39. * will be in normal form.
  40. */
  41. public abstract String resolve(String parent, String child);
  42. /**
  43. * Return the parent pathname string to be used when the parent-directory
  44. * argument in one of the two-argument File constructors is the empty
  45. * pathname.
  46. */
  47. public abstract String getDefaultParent();
  48. /**
  49. * Post-process the given URI path string if necessary. This is used on
  50. * win32, e.g., to transform "/c:/foo" into "c:/foo". The path string
  51. * still has slash separators; code in the File class will translate them
  52. * after this method returns.
  53. */
  54. public abstract String fromURIPath(String path);
  55. /* -- Path operations -- */
  56. /**
  57. * Tell whether or not the given abstract pathname is absolute.
  58. */
  59. public abstract boolean isAbsolute(File f);
  60. /**
  61. * Resolve the given abstract pathname into absolute form. Invoked by the
  62. * getAbsolutePath and getCanonicalPath methods in the File class.
  63. */
  64. public abstract String resolve(File f);
  65. public abstract String canonicalize(String path) throws IOException;
  66. /* -- Attribute accessors -- */
  67. /* Constants for simple boolean attributes */
  68. public static final int BA_EXISTS = 0x01;
  69. public static final int BA_REGULAR = 0x02;
  70. public static final int BA_DIRECTORY = 0x04;
  71. public static final int BA_HIDDEN = 0x08;
  72. /**
  73. * Return the simple boolean attributes for the file or directory denoted
  74. * by the given abstract pathname, or zero if it does not exist or some
  75. * other I/O error occurs.
  76. */
  77. public abstract int getBooleanAttributes(File f);
  78. /**
  79. * Check whether the file or directory denoted by the given abstract
  80. * pathname may be accessed by this process. If the second argument is
  81. * <code>false</code>, then a check for read access is made; if the second
  82. * argument is <code>true</code>, then a check for write (not read-write)
  83. * access is made. Return false if access is denied or an I/O error
  84. * occurs.
  85. */
  86. public abstract boolean checkAccess(File f, boolean write);
  87. /**
  88. * Return the time at which the file or directory denoted by the given
  89. * abstract pathname was last modified, or zero if it does not exist or
  90. * some other I/O error occurs.
  91. */
  92. public abstract long getLastModifiedTime(File f);
  93. /**
  94. * Return the length in bytes of the file denoted by the given abstract
  95. * pathname, or zero if it does not exist, is a directory, or some other
  96. * I/O error occurs.
  97. */
  98. public abstract long getLength(File f);
  99. /* -- File operations -- */
  100. /**
  101. * Create a new empty file with the given pathname. Return
  102. * <code>true</code> if the file was created and <code>false</code> if a
  103. * file or directory with the given pathname already exists. Throw an
  104. * IOException if an I/O error occurs.
  105. */
  106. public abstract boolean createFileExclusively(String pathname)
  107. throws IOException;
  108. /**
  109. * Delete the file or directory denoted by the given abstract pathname,
  110. * returning <code>true</code> if and only if the operation succeeds.
  111. */
  112. public abstract boolean delete(File f);
  113. /**
  114. * Arrange for the file or directory denoted by the given abstract
  115. * pathname to be deleted when the VM exits, returning <code>true</code> if
  116. * and only if the operation succeeds.
  117. */
  118. public abstract boolean deleteOnExit(File f);
  119. /**
  120. * List the elements of the directory denoted by the given abstract
  121. * pathname. Return an array of strings naming the elements of the
  122. * directory if successful; otherwise, return <code>null</code>.
  123. */
  124. public abstract String[] list(File f);
  125. /**
  126. * Create a new directory denoted by the given abstract pathname,
  127. * returning <code>true</code> if and only if the operation succeeds.
  128. */
  129. public abstract boolean createDirectory(File f);
  130. /**
  131. * Rename the file or directory denoted by the first abstract pathname to
  132. * the second abstract pathname, returning <code>true</code> if and only if
  133. * the operation succeeds.
  134. */
  135. public abstract boolean rename(File f1, File f2);
  136. /**
  137. * Set the last-modified time of the file or directory denoted by the
  138. * given abstract pathname, returning <code>true</code> if and only if the
  139. * operation succeeds.
  140. */
  141. public abstract boolean setLastModifiedTime(File f, long time);
  142. /**
  143. * Mark the file or directory denoted by the given abstract pathname as
  144. * read-only, returning <code>true</code> if and only if the operation
  145. * succeeds.
  146. */
  147. public abstract boolean setReadOnly(File f);
  148. /* -- Filesystem interface -- */
  149. /**
  150. * List the available filesystem roots.
  151. */
  152. public abstract File[] listRoots();
  153. /* -- Basic infrastructure -- */
  154. /**
  155. * Compare two abstract pathnames lexicographically.
  156. */
  157. public abstract int compare(File f1, File f2);
  158. /**
  159. * Compute the hash code of an abstract pathname.
  160. */
  161. public abstract int hashCode(File f);
  162. // Flags for enabling/disabling performance optimizations for file
  163. // name canonicalization
  164. static boolean useCanonCaches = true;
  165. static boolean useCanonPrefixCache = true;
  166. private static boolean getBooleanProperty(String prop, boolean defaultVal) {
  167. String val = System.getProperty(prop);
  168. if (val == null) return defaultVal;
  169. if (val.equalsIgnoreCase("true")) {
  170. return true;
  171. } else {
  172. return false;
  173. }
  174. }
  175. static {
  176. useCanonCaches = getBooleanProperty("sun.io.useCanonCaches",
  177. useCanonCaches);
  178. useCanonPrefixCache = getBooleanProperty("sun.io.useCanonPrefixCache",
  179. useCanonPrefixCache);
  180. }
  181. }