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