1 2 3 package net.nutch.fs; 4 5 import java.io.*; 6 import java.net.*; 7 import java.util.*; 8 import java.util.logging.*; 9 10 import net.nutch.ndfs.*; 11 import net.nutch.util.*; 12 13 26 public abstract class NutchFileSystem { 27 public static final Logger LOG = LogFormatter.getLogger("net.nutch.util.NutchFileSystem"); 28 29 34 public static NutchFileSystem parseArgs(String argv[], int i) throws IOException { 35 40 int orig = i; 41 NutchFileSystem nfs = null; 42 String cmd = argv[i]; 43 if ("-ndfs".equals(cmd)) { 44 i++; 45 InetSocketAddress addr = NDFS.createSocketAddr(argv[i++]); 46 nfs = new NDFSFileSystem(addr); 47 } else if ("-local".equals(cmd)) { 48 i++; 49 nfs = new LocalFileSystem(); 50 } else { 51 LOG.info("No NutchFileSystem indicated, so defaulting to local fs."); 52 nfs = new LocalFileSystem(); 53 } 54 System.arraycopy(argv, i, argv, orig, argv.length - i); 55 for (int j = argv.length - i; j < argv.length; j++) { 56 argv[j] = null; 57 } 58 return nfs; 59 } 60 61 66 public NutchFileSystem() { 67 } 68 69 73 public abstract NFSInputStream open(File f) throws IOException; 74 75 79 public abstract NFSOutputStream create(File f) throws IOException; 80 public abstract NFSOutputStream create(File f, boolean overwrite) throws IOException; 81 82 86 public boolean createNewFile(File f) throws IOException { 87 if (exists(f)) { 88 return false; 89 } else { 90 OutputStream out = create(f); 91 try { 92 } finally { 93 out.close(); 94 } 95 return true; 96 } 97 } 98 99 103 public abstract boolean rename(File src, File dst) throws IOException; 104 105 108 public abstract boolean delete(File f) throws IOException; 109 110 113 public abstract boolean exists(File f) throws IOException; 114 115 117 public abstract boolean isDirectory(File f) throws IOException; 118 119 121 public boolean isFile(File f) throws IOException { 122 if (exists(f) && ! isDirectory(f)) { 123 return true; 124 } else { 125 return false; 126 } 127 } 128 129 131 public abstract long getLength(File f) throws IOException; 132 133 135 public abstract File[] listFiles(File f) throws IOException; 136 137 public File[] listFiles(File f, FileFilter filter) throws IOException { 138 Vector results = new Vector(); 139 File listing[] = listFiles(f); 140 for (int i = 0; i < listing.length; i++) { 141 if (filter.accept(listing[i])) { 142 results.add(listing[i]); 143 } 144 } 145 return (File[]) results.toArray(new File[results.size()]); 146 } 147 148 152 public abstract void mkdirs(File f) throws IOException; 153 154 157 public abstract void lock(File f, boolean shared) throws IOException; 158 159 162 public abstract void release(File f) throws IOException; 163 164 168 public abstract void copyFromLocalFile(File src, File dst) throws IOException; 170 171 175 public abstract void moveFromLocalFile(File src, File dst) throws IOException; 176 177 181 public abstract void copyToLocalFile(File src, File dst) throws IOException; 182 183 187 190 196 public abstract File startLocalOutput(File nfsOutputFile, File tmpLocalFile) throws IOException; 197 198 204 public abstract void completeLocalOutput(File nfsOutputFile, File tmpLocalFile) throws IOException; 205 206 212 public abstract File startLocalInput(File nfsInputFile, File tmpLocalFile) throws IOException; 213 214 220 public abstract void completeLocalInput(File localFile) throws IOException; 221 222 226 public abstract File createTempFile(String prefix, String suffix, File directory) throws IOException; 227 228 232 public abstract void close() throws IOException; 233 } 234 | Popular Tags |