1. /*
  2. * @(#)FileSystem.java 1.6 01/11/29
  3. *
  4. * Copyright 2002 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. /* -- Path operations -- */
  49. /**
  50. * Tell whether or not the given abstract pathname is absolute.
  51. */
  52. public abstract boolean isAbsolute(File f);
  53. /**
  54. * Resolve the given abstract pathname into absolute form. Invoked by the
  55. * getAbsolutePath and getCanonicalPath methods in the File class.
  56. */
  57. public abstract String resolve(File f);
  58. public abstract String canonicalize(String path) throws IOException;
  59. /* -- Attribute accessors -- */
  60. /* Constants for simple boolean attributes */
  61. public static final int BA_EXISTS = 0x01;
  62. public static final int BA_REGULAR = 0x02;
  63. public static final int BA_DIRECTORY = 0x04;
  64. public static final int BA_HIDDEN = 0x08;
  65. /**
  66. * Return the simple boolean attributes for the file or directory denoted
  67. * by the given abstract pathname, or zero if it does not exist or some
  68. * other I/O error occurs.
  69. */
  70. public abstract int getBooleanAttributes(File f);
  71. /**
  72. * Check whether the file or directory denoted by the given abstract
  73. * pathname may be accessed by this process. If the second argument is
  74. * <code>false</code>, then a check for read access is made; if the second
  75. * argument is <code>true</code>, then a check for write (not read-write)
  76. * access is made. Return false if access is denied or an I/O error
  77. * occurs.
  78. */
  79. public abstract boolean checkAccess(File f, boolean write);
  80. /**
  81. * Return the time at which the file or directory denoted by the given
  82. * abstract pathname was last modified, or zero if it does not exist or
  83. * some other I/O error occurs.
  84. */
  85. public abstract long getLastModifiedTime(File f);
  86. /**
  87. * Return the length in bytes of the file denoted by the given abstract
  88. * pathname, or zero if it does not exist, is a directory, or some other
  89. * I/O error occurs.
  90. */
  91. public abstract long getLength(File f);
  92. /* -- File operations -- */
  93. /**
  94. * Create a new empty file with the given pathname. Return
  95. * <code>true</code> if the file was created and <code>false</code> if a
  96. * file or directory with the given pathname already exists. Throw an
  97. * IOException if an I/O error occurs.
  98. */
  99. public abstract boolean createFileExclusively(String pathname)
  100. throws IOException;
  101. /**
  102. * Delete the file or directory denoted by the given abstract pathname,
  103. * returning <code>true</code> if and only if the operation succeeds.
  104. */
  105. public abstract boolean delete(File f);
  106. /**
  107. * Arrange for the file or directory denoted by the given abstract
  108. * pathname to be deleted when the VM exits, returning <code>true</code> if
  109. * and only if the operation succeeds.
  110. */
  111. public abstract boolean deleteOnExit(File f);
  112. /**
  113. * List the elements of the directory denoted by the given abstract
  114. * pathname. Return an array of strings naming the elements of the
  115. * directory if successful; otherwise, return <code>null</code>.
  116. */
  117. public abstract String[] list(File f);
  118. /**
  119. * Create a new directory denoted by the given abstract pathname,
  120. * returning <code>true</code> if and only if the operation succeeds.
  121. */
  122. public abstract boolean createDirectory(File f);
  123. /**
  124. * Rename the file or directory denoted by the first abstract pathname to
  125. * the second abstract pathname, returning <code>true</code> if and only if
  126. * the operation succeeds.
  127. */
  128. public abstract boolean rename(File f1, File f2);
  129. /**
  130. * Set the last-modified time of the file or directory denoted by the
  131. * given abstract pathname, returning <code>true</code> if and only if the
  132. * operation succeeds.
  133. */
  134. public abstract boolean setLastModifiedTime(File f, long time);
  135. /**
  136. * Mark the file or directory denoted by the given abstract pathname as
  137. * read-only, returning <code>true</code> if and only if the operation
  138. * succeeds.
  139. */
  140. public abstract boolean setReadOnly(File f);
  141. /* -- Filesystem interface -- */
  142. /**
  143. * List the available filesystem roots.
  144. */
  145. public abstract File[] listRoots();
  146. /* -- Basic infrastructure -- */
  147. /**
  148. * Compare two abstract pathnames lexicographically.
  149. */
  150. public abstract int compare(File f1, File f2);
  151. /**
  152. * Compute the hash code of an abstract pathname.
  153. */
  154. public abstract int hashCode(File f);
  155. }