001package co.codewizards.cloudstore.core.oio; 002 003import java.io.FileNotFoundException; 004import java.io.FilenameFilter; 005import java.io.IOException; 006import java.io.RandomAccessFile; 007import java.io.Serializable; 008import java.net.URI; 009 010import co.codewizards.cloudstore.core.io.IInputStream; 011import co.codewizards.cloudstore.core.io.IOutputStream; 012 013 014/** 015 * Substitute for java.io.File. Also there are many methods as known from 016 * java.nio.file.Files and java.nio.file.Paths. 017 * 018 * @author Sebastian Schefczyk 019 */ 020public interface File extends Serializable { 021 022 String[] list(); 023 String[] list(FilenameFilter filenameFilter); 024 File[] listFiles(); 025 File[] listFiles(java.io.FileFilter fileFilter); 026 File[] listFiles(FileFilter fileFilter); 027 File[] listFiles(FilenameFilter fileFilter); 028 029 /** 030 * Create a child-{@code File}. 031 * <p> 032 * This method appends sub-path-elements. It is synonymous to 033 * {@link OioFileFactory#createFile(File, String...) createFile(thisFile, children)} 034 * and more intuitive. 035 * @param children the children to be appended. May be <code>null</code> or empty. 036 * @return the new {@link File}. Never <code>null</code>. 037 */ 038 File createFile(String ... children); 039 040 File getAbsoluteFile(); 041 File getParentFile(); 042 043 boolean isSymbolicLink(); 044 045 boolean canWrite(); 046 boolean canRead(); 047 boolean canExecute(); 048 boolean setExecutable(boolean executable); 049 boolean setReadable(boolean readable); 050 boolean setReadable(boolean readable, boolean ownerOnly); 051 boolean setWritable(boolean writable); 052 boolean setWritable(boolean writable, boolean ownerOnly); 053 054 /** Convenience method for the often called chain: 055 * <p/> 056 * java.io.File --> java.nio.Path --> Files.readSymbolicLink --> IOUtil.toPathString 057 * <p/>Without symlinks, this method would not be needed. 058 */ 059 String readSymbolicLinkToPathString() throws IOException; 060 boolean exists(); 061 boolean existsNoFollow(); 062 boolean createNewFile() throws IOException; 063 int compareTo(File otherFile); 064 boolean delete(); 065 void deleteOnExit(); 066 void deleteRecursively(); 067 long getFreeSpace(); 068 String getCanonicalPath() throws IOException; 069 File getCanonicalFile() throws IOException; 070 String getAbsolutePath(); 071 boolean isRegularFileFollowLinks(); 072 boolean isRegularFileNoFollowLinks(); 073 boolean mkdir(); 074 boolean isDirectory(); 075 boolean isDirectoryNoFollowSymLinks(); 076 boolean isDirectoryFollowSymLinks(); 077 long getUsableSpace(); 078 long length(); 079 /** This is platform dependent (e.g. might fail at renaming between different partitions). Plz see {@link java.io.File#renameTo(java.io.File)}. */ 080 boolean renameTo(File newFileName); 081 boolean setLastModified(long lastModified); 082 IOutputStream createOutputStream() throws FileNotFoundException; 083 IOutputStream createOutputStream(boolean append) throws FileNotFoundException; 084 IInputStream createInputStream() throws FileNotFoundException; 085 String getName(); 086 void createSymbolicLink(String targetPath) throws IOException; 087 088 long lastModified(); 089 long getLastModifiedNoFollow(); 090 boolean isAbsolute(); 091 String getPath(); 092 boolean mkdirs(); 093 /** Copies a file, a symlink (depends on environment/implementation) or a directory (non-recursive). */ 094 void copyToCopyAttributes(File toFile) throws IOException; 095 /** This is platform independent, in contrast to {@link #renameTo(File)} respectively {@link java.io.File#renameTo(java.io.File)}. */ 096 void move(File toFile) throws IOException; 097 URI toURI(); 098 RandomAccessFile createRandomAccessFile(String mode) throws FileNotFoundException; 099 boolean isFile(); 100 boolean setLastModifiedNoFollow(long time); 101 String relativize(File target) throws IOException; 102 103 boolean setExecutable(boolean executable, boolean ownerOnly); 104 /** <b>Caution:</b> <i>Only use this when forced by 3rd party interface!</i> */ 105 java.io.File getIoFile(); 106 107}