Apache Nutch is an extensible and scalable web crawler
Change parameters passed to Hadoop's FileSystem from (now-deprecated) java.io.File to (new) org.apache.hadoop.fs.Path.
Douglass Cuttinga7e2e13c1dcf
diff --git a/CHANGES.txt b/CHANGES.txtindex e11673f8d..7c72b1d1e 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -7,6 +7,9 @@ Release 0.82. NUTCH-108 - Log hosts that exceed generate.max.per.host.(Rod Taylor via cutting)+ 3. Switch from using java.io.File to org.apache.hadoop.fs.Path.+ (cutting)+Release 0.7 - 2005-08-17diff --git a/src/java/org/apache/nutch/crawl/Crawl.java b/src/java/org/apache/nutch/crawl/Crawl.javaindex 47abd5a4b..c252f3451 100644--- a/src/java/org/apache/nutch/crawl/Crawl.java+++ b/src/java/org/apache/nutch/crawl/Crawl.java@@ -55,15 +55,15 @@ public class Crawl {conf.addDefaultResource("crawl-tool.xml");JobConf job = new NutchJob(conf);- File rootUrlDir = null;- File dir = new File("crawl-" + getDate());+ Path rootUrlDir = null;+ Path dir = new Path("crawl-" + getDate());int threads = job.getInt("fetcher.threads.fetch", 10);int depth = 5;int topN = Integer.MAX_VALUE;for (int i = 0; i < args.length; i++) {if ("-dir".equals(args[i])) {- dir = new File(args[i+1]);+ dir = new Path(args[i+1]);i++;} else if ("-threads".equals(args[i])) {threads = Integer.parseInt(args[i+1]);@@ -75,7 +75,7 @@ public class Crawl {topN = Integer.parseInt(args[i+1]);i++;} else if (args[i] != null) {- rootUrlDir = new File(args[i]);+ rootUrlDir = new Path(args[i]);}}@@ -92,19 +92,19 @@ public class Crawl {if (topN != Integer.MAX_VALUE)LOG.info("topN = " + topN);- File crawlDb = new File(dir + "/crawldb");- File linkDb = new File(dir + "/linkdb");- File segments = new File(dir + "/segments");- File indexes = new File(dir + "/indexes");- File index = new File(dir + "/index");+ Path crawlDb = new Path(dir + "/crawldb");+ Path linkDb = new Path(dir + "/linkdb");+ Path segments = new Path(dir + "/segments");+ Path indexes = new Path(dir + "/indexes");+ Path index = new Path(dir + "/index");- File tmpDir = job.getLocalFile("crawl", getDate());+ Path tmpDir = job.getLocalPath("crawl"+Path.SEPARATOR+getDate());// initialize crawlDbnew Injector(job).inject(crawlDb, rootUrlDir);for (int i = 0; i < depth; i++) { // generate new segment- File segment =+ Path segment =new Generator(job).generate(crawlDb, segments, -1,topN, System.currentTimeMillis());new Fetcher(job).fetch(segment, threads, Fetcher.isParsing(job)); // fetch it@@ -117,9 +117,9 @@ public class Crawl {new LinkDb(job).invert(linkDb, segments); // invert links// index, dedup & merge- new Indexer(job).index(indexes, crawlDb, linkDb, fs.listFiles(segments));- new DeleteDuplicates(job).dedup(new File[] { indexes });- new IndexMerger(fs, fs.listFiles(indexes), index, tmpDir, job).merge();+ new Indexer(job).index(indexes, crawlDb, linkDb, fs.listPaths(segments));+ new DeleteDuplicates(job).dedup(new Path[] { indexes });+ new IndexMerger(fs, fs.listPaths(indexes), index, tmpDir, job).merge();LOG.info("crawl finished: " + dir);}diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.javaindex 613e8cdb8..cd4867151 100644--- a/src/java/org/apache/nutch/crawl/CrawlDb.java+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java@@ -41,14 +41,14 @@ public class CrawlDb extends Configured {super(conf);}- public void update(File crawlDb, File segment) throws IOException {+ public void update(Path crawlDb, Path segment) throws IOException {LOG.info("CrawlDb update: starting");LOG.info("CrawlDb update: db: " + crawlDb);LOG.info("CrawlDb update: segment: " + segment);JobConf job = CrawlDb.createJob(getConf(), crawlDb);- job.addInputDir(new File(segment, CrawlDatum.FETCH_DIR_NAME));- job.addInputDir(new File(segment, CrawlDatum.PARSE_DIR_NAME));+ job.addInputPath(new Path(segment, CrawlDatum.FETCH_DIR_NAME));+ job.addInputPath(new Path(segment, CrawlDatum.PARSE_DIR_NAME));LOG.info("CrawlDb update: Merging segment data into db.");JobClient.runJob(job);@@ -57,22 +57,22 @@ public class CrawlDb extends Configured {LOG.info("CrawlDb update: done");}- public static JobConf createJob(Configuration config, File crawlDb) {- File newCrawlDb =- new File(crawlDb,+ public static JobConf createJob(Configuration config, Path crawlDb) {+ Path newCrawlDb =+ new Path(crawlDb,Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));JobConf job = new NutchJob(config);job.setJobName("crawldb " + crawlDb);- job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));+ job.addInputPath(new Path(crawlDb, CrawlDatum.DB_DIR_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(CrawlDatum.class);job.setReducerClass(CrawlDbReducer.class);- job.setOutputDir(newCrawlDb);+ job.setOutputPath(newCrawlDb);job.setOutputFormat(MapFileOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(CrawlDatum.class);@@ -80,11 +80,11 @@ public class CrawlDb extends Configured {return job;}- public static void install(JobConf job, File crawlDb) throws IOException {- File newCrawlDb = job.getOutputDir();+ public static void install(JobConf job, Path crawlDb) throws IOException {+ Path newCrawlDb = job.getOutputPath();FileSystem fs = new JobClient(job).getFs();- File old = new File(crawlDb, "old");- File current = new File(crawlDb, CrawlDatum.DB_DIR_NAME);+ Path old = new Path(crawlDb, "old");+ Path current = new Path(crawlDb, CrawlDatum.DB_DIR_NAME);fs.delete(old);fs.rename(current, old);fs.rename(newCrawlDb, current);@@ -99,7 +99,7 @@ public class CrawlDb extends Configured {return;}- crawlDb.update(new File(args[0]), new File(args[1]));+ crawlDb.update(new Path(args[0]), new Path(args[1]));}diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReader.java b/src/java/org/apache/nutch/crawl/CrawlDbReader.javaindex c18e48fb8..ac42872e2 100644--- a/src/java/org/apache/nutch/crawl/CrawlDbReader.java+++ b/src/java/org/apache/nutch/crawl/CrawlDbReader.java@@ -16,7 +16,6 @@package org.apache.nutch.crawl;-import java.io.File;import java.io.IOException;import java.util.Iterator;import java.util.Random;@@ -25,6 +24,7 @@ import java.util.logging.Logger;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.Closeable;import org.apache.hadoop.io.FloatWritable;import org.apache.hadoop.io.LongWritable;@@ -65,7 +65,7 @@ public class CrawlDbReader implements Closeable {private void openReaders(String crawlDb, Configuration config) throws IOException {if (readers != null) return;FileSystem fs = FileSystem.get(config);- readers = MapFileOutputFormat.getReaders(fs, new File(crawlDb, CrawlDatum.DB_DIR_NAME), config);+ readers = MapFileOutputFormat.getReaders(fs, new Path(crawlDb, CrawlDatum.DB_DIR_NAME), config);}private void closeReaders() {@@ -204,12 +204,12 @@ public class CrawlDbReader implements Closeable {public void processStatJob(String crawlDb, Configuration config) throws IOException {LOG.info("CrawlDb statistics start: " + crawlDb);- File tmpFolder = new File(crawlDb, "stat_tmp" + System.currentTimeMillis());+ Path tmpFolder = new Path(crawlDb, "stat_tmp" + System.currentTimeMillis());JobConf job = new NutchJob(config);job.setJobName("stats " + crawlDb);- job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));+ job.addInputPath(new Path(crawlDb, CrawlDatum.DB_DIR_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(CrawlDatum.class);@@ -217,7 +217,7 @@ public class CrawlDbReader implements Closeable {job.setMapperClass(CrawlDbStatMapper.class);job.setReducerClass(CrawlDbStatReducer.class);- job.setOutputDir(tmpFolder);+ job.setOutputPath(tmpFolder);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(LongWritable.class);@@ -296,17 +296,17 @@ public class CrawlDbReader implements Closeable {LOG.info("CrawlDb dump: starting");LOG.info("CrawlDb db: " + crawlDb);- File outFolder = new File(output);+ Path outFolder = new Path(output);JobConf job = new NutchJob(config);job.setJobName("dump " + crawlDb);- job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));+ job.addInputPath(new Path(crawlDb, CrawlDatum.DB_DIR_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(CrawlDatum.class);- job.setOutputDir(outFolder);+ job.setOutputPath(outFolder);job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(CrawlDatum.class);@@ -318,21 +318,21 @@ public class CrawlDbReader implements Closeable {public void processTopNJob(String crawlDb, long topN, float min, String output, Configuration config) throws IOException {LOG.info("CrawlDb topN: starting (topN=" + topN + ", min=" + min + ")");LOG.info("CrawlDb db: " + crawlDb);- File outFolder = new File(output);- File tempDir =- new File(config.get("mapred.temp.dir", ".") ++ Path outFolder = new Path(output);+ Path tempDir =+ new Path(config.get("mapred.temp.dir", ".") +"/readdb-topN-temp-"+Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));JobConf job = new NutchJob(config);- job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));+ job.addInputPath(new Path(crawlDb, CrawlDatum.DB_DIR_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(CrawlDatum.class);job.setMapperClass(CrawlDbTopNMapper.class);job.setReducerClass(IdentityReducer.class);- job.setOutputDir(tempDir);+ job.setOutputPath(tempDir);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(FloatWritable.class);job.setOutputValueClass(UTF8.class);@@ -345,14 +345,14 @@ public class CrawlDbReader implements Closeable {job = new NutchJob(config);job.setLong("CrawlDbReader.topN", topN);- job.addInputDir(tempDir);+ job.addInputPath(tempDir);job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(FloatWritable.class);job.setInputValueClass(UTF8.class);job.setMapperClass(IdentityMapper.class);job.setReducerClass(CrawlDbTopNReducer.class);- job.setOutputDir(outFolder);+ job.setOutputPath(outFolder);job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(FloatWritable.class);job.setOutputValueClass(UTF8.class);diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.javaindex bd86142af..342da226e 100644--- a/src/java/org/apache/nutch/crawl/Generator.java+++ b/src/java/org/apache/nutch/crawl/Generator.java@@ -27,6 +27,7 @@ import org.apache.hadoop.conf.*;import org.apache.hadoop.util.LogFormatter;import org.apache.hadoop.mapred.*;import org.apache.hadoop.mapred.lib.*;+import org.apache.hadoop.fs.Path;import org.apache.nutch.net.URLFilterException;import org.apache.nutch.net.URLFilters;@@ -205,24 +206,24 @@ public class Generator extends Configured {}/** Generate fetchlists in a segment. */- public File generate(File dbDir, File segments)+ public Path generate(Path dbDir, Path segments)throws IOException {return generate(dbDir, segments,-1, Long.MAX_VALUE, System.currentTimeMillis());}/** Generate fetchlists in a segment. */- public File generate(File dbDir, File segments,+ public Path generate(Path dbDir, Path segments,int numLists, long topN, long curTime)throws IOException {- File tempDir =- new File(getConf().get("mapred.temp.dir", ".") ++ Path tempDir =+ new Path(getConf().get("mapred.temp.dir", ".") +"/generate-temp-"+Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));- File segment = new File(segments, getDate());- File output = new File(segment, CrawlDatum.GENERATE_DIR_NAME);+ Path segment = new Path(segments, getDate());+ Path output = new Path(segment, CrawlDatum.GENERATE_DIR_NAME);LOG.info("Generator: starting");LOG.info("Generator: segment: " + segment);@@ -239,7 +240,7 @@ public class Generator extends Configured {job.setLong("crawl.gen.curTime", curTime);job.setLong("crawl.topN", topN);- job.setInputDir(new File(dbDir, CrawlDatum.DB_DIR_NAME));+ job.setInputPath(new Path(dbDir, CrawlDatum.DB_DIR_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(CrawlDatum.class);@@ -248,7 +249,7 @@ public class Generator extends Configured {job.setPartitionerClass(Selector.class);job.setReducerClass(Selector.class);- job.setOutputDir(tempDir);+ job.setOutputPath(tempDir);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(FloatWritable.class);job.setOutputValueClass(SelectorEntry.class);@@ -261,7 +262,7 @@ public class Generator extends Configured {job.setInt("partition.url.by.host.seed", new Random().nextInt());- job.setInputDir(tempDir);+ job.setInputPath(tempDir);job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(FloatWritable.class);job.setInputValueClass(SelectorEntry.class);@@ -270,7 +271,7 @@ public class Generator extends Configured {job.setPartitionerClass(PartitionUrlByHost.class);job.setNumReduceTasks(numLists);- job.setOutputDir(output);+ job.setOutputPath(output);job.setOutputFormat(SequenceFileOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(CrawlDatum.class);@@ -298,8 +299,8 @@ public class Generator extends Configured {return;}- File dbDir = new File(args[0]);- File segmentsDir = new File(args[1]);+ Path dbDir = new Path(args[0]);+ Path segmentsDir = new Path(args[1]);long curTime = System.currentTimeMillis();long topN = Long.MAX_VALUE;int numFetchers = -1;diff --git a/src/java/org/apache/nutch/crawl/Injector.java b/src/java/org/apache/nutch/crawl/Injector.javaindex f0b283180..d59c7065f 100644--- a/src/java/org/apache/nutch/crawl/Injector.java+++ b/src/java/org/apache/nutch/crawl/Injector.java@@ -90,13 +90,13 @@ public class Injector extends Configured {super(conf);}- public void inject(File crawlDb, File urlDir) throws IOException {+ public void inject(Path crawlDb, Path urlDir) throws IOException {LOG.info("Injector: starting");LOG.info("Injector: crawlDb: " + crawlDb);LOG.info("Injector: urlDir: " + urlDir);- File tempDir =- new File(getConf().get("mapred.temp.dir", ".") ++ Path tempDir =+ new Path(getConf().get("mapred.temp.dir", ".") +"/inject-temp-"+Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));@@ -104,11 +104,11 @@ public class Injector extends Configured {LOG.info("Injector: Converting injected urls to crawl db entries.");JobConf sortJob = new NutchJob(getConf());sortJob.setJobName("inject " + urlDir);- sortJob.setInputDir(urlDir);+ sortJob.setInputPath(urlDir);sortJob.setMapperClass(InjectMapper.class);sortJob.setReducerClass(InjectReducer.class);- sortJob.setOutputDir(tempDir);+ sortJob.setOutputPath(tempDir);sortJob.setOutputFormat(SequenceFileOutputFormat.class);sortJob.setOutputKeyClass(UTF8.class);sortJob.setOutputValueClass(CrawlDatum.class);@@ -117,7 +117,7 @@ public class Injector extends Configured {// merge with existing crawl dbLOG.info("Injector: Merging injected urls into crawl db.");JobConf mergeJob = CrawlDb.createJob(getConf(), crawlDb);- mergeJob.addInputDir(tempDir);+ mergeJob.addInputPath(tempDir);JobClient.runJob(mergeJob);CrawlDb.install(mergeJob, crawlDb);@@ -136,7 +136,7 @@ public class Injector extends Configured {return;}- injector.inject(new File(args[0]), new File(args[1]));+ injector.inject(new Path(args[0]), new Path(args[1]));}}diff --git a/src/java/org/apache/nutch/crawl/LinkDb.java b/src/java/org/apache/nutch/crawl/LinkDb.javaindex d811c3b6f..ace3848ad 100644--- a/src/java/org/apache/nutch/crawl/LinkDb.java+++ b/src/java/org/apache/nutch/crawl/LinkDb.java@@ -178,10 +178,10 @@ public class LinkDb extends Configured implements Mapper, Reducer {output.collect(key, result);}- public void invert(File linkDb, final File segmentsDir) throws IOException {+ public void invert(Path linkDb, final Path segmentsDir) throws IOException {final FileSystem fs = FileSystem.get(getConf());- File[] files = fs.listFiles(segmentsDir, new FileFilter() {- public boolean accept(File f) {+ Path[] files = fs.listPaths(segmentsDir, new PathFilter() {+ public boolean accept(Path f) {try {if (fs.isDirectory(f)) return true;} catch (IOException ioe) {};@@ -191,23 +191,23 @@ public class LinkDb extends Configured implements Mapper, Reducer {invert(linkDb, files);}- public void invert(File linkDb, File[] segments) throws IOException {+ public void invert(Path linkDb, Path[] segments) throws IOException {LOG.info("LinkDb: starting");LOG.info("LinkDb: linkdb: " + linkDb);JobConf job = LinkDb.createJob(getConf(), linkDb);for (int i = 0; i < segments.length; i++) {LOG.info("LinkDb: adding segment: " + segments[i]);- job.addInputDir(new File(segments[i], ParseData.DIR_NAME));+ job.addInputPath(new Path(segments[i], ParseData.DIR_NAME));}JobClient.runJob(job);FileSystem fs = FileSystem.get(getConf());if (fs.exists(linkDb)) {LOG.info("LinkDb: merging with existing linkdb: " + linkDb);// try to merge- File newLinkDb = job.getOutputDir();+ Path newLinkDb = job.getOutputPath();job = LinkDb.createMergeJob(getConf(), linkDb);- job.addInputDir(new File(linkDb, CURRENT_NAME));- job.addInputDir(newLinkDb);+ job.addInputPath(new Path(linkDb, CURRENT_NAME));+ job.addInputPath(newLinkDb);JobClient.runJob(job);fs.delete(newLinkDb);}@@ -215,9 +215,9 @@ public class LinkDb extends Configured implements Mapper, Reducer {LOG.info("LinkDb: done");}- private static JobConf createJob(Configuration config, File linkDb) {- File newLinkDb =- new File("linkdb-" ++ private static JobConf createJob(Configuration config, Path linkDb) {+ Path newLinkDb =+ new Path("linkdb-" +Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));JobConf job = new NutchJob(config);@@ -230,7 +230,7 @@ public class LinkDb extends Configured implements Mapper, Reducer {job.setMapperClass(LinkDb.class);job.setReducerClass(LinkDb.class);- job.setOutputDir(newLinkDb);+ job.setOutputPath(newLinkDb);job.setOutputFormat(MapFileOutputFormat.class);job.setBoolean("mapred.output.compress", true);job.setOutputKeyClass(UTF8.class);@@ -239,9 +239,9 @@ public class LinkDb extends Configured implements Mapper, Reducer {return job;}- public static JobConf createMergeJob(Configuration config, File linkDb) {- File newLinkDb =- new File("linkdb-merge-" ++ public static JobConf createMergeJob(Configuration config, Path linkDb) {+ Path newLinkDb =+ new Path("linkdb-merge-" +Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));JobConf job = new NutchJob(config);@@ -253,7 +253,7 @@ public class LinkDb extends Configured implements Mapper, Reducer {job.setReducerClass(Merger.class);- job.setOutputDir(newLinkDb);+ job.setOutputPath(newLinkDb);job.setOutputFormat(MapFileOutputFormat.class);job.setBoolean("mapred.output.compress", true);job.setOutputKeyClass(UTF8.class);@@ -262,11 +262,11 @@ public class LinkDb extends Configured implements Mapper, Reducer {return job;}- public static void install(JobConf job, File linkDb) throws IOException {- File newLinkDb = job.getOutputDir();+ public static void install(JobConf job, Path linkDb) throws IOException {+ Path newLinkDb = job.getOutputPath();FileSystem fs = new JobClient(job).getFs();- File old = new File(linkDb, "old");- File current = new File(linkDb, CURRENT_NAME);+ Path old = new Path(linkDb, "old");+ Path current = new Path(linkDb, CURRENT_NAME);fs.delete(old);fs.rename(current, old);fs.rename(newLinkDb, current);@@ -281,15 +281,15 @@ public class LinkDb extends Configured implements Mapper, Reducer {System.err.println("Usage: <linkdb> (-dir segmentsDir | segment1 segment2 ...)");return;}- File segDir = null;+ Path segDir = null;final FileSystem fs = FileSystem.get(conf);- File db = new File(args[0]);+ Path db = new Path(args[0]);ArrayList segs = new ArrayList();for (int i = 1; i < args.length; i++) {if (args[i].equals("-dir")) {- segDir = new File(args[++i]);- File[] files = fs.listFiles(segDir, new FileFilter() {- public boolean accept(File f) {+ segDir = new Path(args[++i]);+ Path[] files = fs.listPaths(segDir, new PathFilter() {+ public boolean accept(Path f) {try {if (fs.isDirectory(f)) return true;} catch (IOException ioe) {};@@ -298,9 +298,9 @@ public class LinkDb extends Configured implements Mapper, Reducer {});if (files != null) segs.addAll(Arrays.asList(files));break;- } else segs.add(new File(args[i]));+ } else segs.add(new Path(args[i]));}- linkDb.invert(db, (File[])segs.toArray(new File[segs.size()]));+ linkDb.invert(db, (Path[])segs.toArray(new Path[segs.size()]));}diff --git a/src/java/org/apache/nutch/crawl/LinkDbMerger.java b/src/java/org/apache/nutch/crawl/LinkDbMerger.javaindex f5340091d..e6740fb13 100644--- a/src/java/org/apache/nutch/crawl/LinkDbMerger.java+++ b/src/java/org/apache/nutch/crawl/LinkDbMerger.java@@ -15,12 +15,12 @@*/package org.apache.nutch.crawl;-import java.io.File;import java.util.ArrayList;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;import org.apache.hadoop.mapred.JobClient;import org.apache.hadoop.mapred.JobConf;import org.apache.nutch.util.NutchConfiguration;@@ -49,16 +49,16 @@ public class LinkDbMerger extends Configured {super(conf);}- public void merge(File output, File[] dbs, boolean filter) throws Exception {+ public void merge(Path output, Path[] dbs, boolean filter) throws Exception {JobConf job = LinkDb.createMergeJob(getConf(), output);job.setBoolean("linkdb.merger.urlfilters", filter);for (int i = 0; i < dbs.length; i++) {- job.addInputDir(new File(dbs[i], LinkDb.CURRENT_NAME));+ job.addInputPath(new Path(dbs[i], LinkDb.CURRENT_NAME));}JobClient.runJob(job);FileSystem fs = FileSystem.get(getConf());fs.mkdirs(output);- fs.rename(job.getOutputDir(), new File(output, LinkDb.CURRENT_NAME));+ fs.rename(job.getOutputPath(), new Path(output, LinkDb.CURRENT_NAME));}/*** @param args@@ -72,7 +72,7 @@ public class LinkDbMerger extends Configured {return;}Configuration conf = NutchConfiguration.create();- File output = new File(args[0]);+ Path output = new Path(args[0]);ArrayList dbs = new ArrayList();boolean filter = false;for (int i = 1; i < args.length; i++) {@@ -80,10 +80,10 @@ public class LinkDbMerger extends Configured {filter = true;continue;}- dbs.add(new File(args[i]));+ dbs.add(new Path(args[i]));}LinkDbMerger merger = new LinkDbMerger(conf);- merger.merge(output, (File[])dbs.toArray(new File[dbs.size()]), filter);+ merger.merge(output, (Path[])dbs.toArray(new Path[dbs.size()]), filter);}}diff --git a/src/java/org/apache/nutch/crawl/LinkDbReader.java b/src/java/org/apache/nutch/crawl/LinkDbReader.javaindex 1d5903326..bad45e9fa 100644--- a/src/java/org/apache/nutch/crawl/LinkDbReader.java+++ b/src/java/org/apache/nutch/crawl/LinkDbReader.java@@ -17,7 +17,6 @@package org.apache.nutch.crawl;import java.io.IOException;-import java.io.File;import org.apache.hadoop.io.*;import org.apache.hadoop.fs.*;@@ -39,11 +38,11 @@ public class LinkDbReader implements Closeable {private static final Partitioner PARTITIONER = new HashPartitioner();private FileSystem fs;- private File directory;+ private Path directory;private MapFile.Reader[] readers;private Configuration conf;- public LinkDbReader(FileSystem fs, File directory, Configuration conf) {+ public LinkDbReader(FileSystem fs, Path directory, Configuration conf) {this.fs = fs;this.directory = directory;this.conf = conf;@@ -61,7 +60,7 @@ public class LinkDbReader implements Closeable {synchronized (this) {if (readers == null) {readers = MapFileOutputFormat.getReaders- (fs, new File(directory, LinkDb.CURRENT_NAME), this.conf);+ (fs, new Path(directory, LinkDb.CURRENT_NAME), this.conf);}}@@ -80,17 +79,17 @@ public class LinkDbReader implements Closeable {public static void processDumpJob(String linkdb, String output, Configuration config) throws IOException {LOG.info("LinkDb dump: starting");LOG.info("LinkDb db: " + linkdb);- File outFolder = new File(output);+ Path outFolder = new Path(output);JobConf job = new NutchJob(config);job.setJobName("read " + linkdb);- job.addInputDir(new File(linkdb, LinkDb.CURRENT_NAME));+ job.addInputPath(new Path(linkdb, LinkDb.CURRENT_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(Inlinks.class);- job.setOutputDir(outFolder);+ job.setOutputPath(outFolder);job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(Inlinks.class);@@ -109,7 +108,7 @@ public class LinkDbReader implements Closeable {if (args[1].equals("-dump")) {LinkDbReader.processDumpJob(args[0], args[2], conf);} else if (args[1].equals("-url")) {- LinkDbReader dbr = new LinkDbReader(FileSystem.get(NutchConfiguration.create()), new File(args[0]), conf);+ LinkDbReader dbr = new LinkDbReader(FileSystem.get(NutchConfiguration.create()), new Path(args[0]), conf);Inlinks links = dbr.getInlinks(new UTF8(args[2]));if (links == null) {System.out.println(" - no link information.");diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.javaindex 32303149d..b8ea42cdd 100644--- a/src/java/org/apache/nutch/fetcher/Fetcher.java+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java@@ -17,7 +17,6 @@package org.apache.nutch.fetcher;import java.io.IOException;-import java.io.File;import org.apache.hadoop.io.*;import org.apache.hadoop.fs.*;@@ -49,7 +48,7 @@ public class Fetcher extends Configured implements MapRunnable {/** Don't split inputs, to keep things polite. */public FileSplit[] getSplits(FileSystem fs, JobConf job, int nSplits)throws IOException {- File[] files = listFiles(fs, job);+ Path[] files = listPaths(fs, job);FileSplit[] splits = new FileSplit[files.length];for (int i = 0; i < files.length; i++) {splits[i] = new FileSplit(files[i], 0, fs.getLength(files[i]));@@ -360,7 +359,7 @@ public class Fetcher extends Configured implements MapRunnable {}- public void fetch(File segment, int threads, boolean parsing)+ public void fetch(Path segment, int threads, boolean parsing)throws IOException {LOG.info("Fetcher: starting");@@ -376,14 +375,14 @@ public class Fetcher extends Configured implements MapRunnable {// for politeness, don't permit parallel execution of a single taskjob.setBoolean("mapred.speculative.execution", false);- job.setInputDir(new File(segment, CrawlDatum.GENERATE_DIR_NAME));+ job.setInputPath(new Path(segment, CrawlDatum.GENERATE_DIR_NAME));job.setInputFormat(InputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(CrawlDatum.class);job.setMapRunnerClass(Fetcher.class);- job.setOutputDir(segment);+ job.setOutputPath(segment);job.setOutputFormat(FetcherOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(FetcherOutput.class);@@ -403,7 +402,7 @@ public class Fetcher extends Configured implements MapRunnable {System.exit(-1);}- File segment = new File(args[0]);+ Path segment = new Path(args[0]);Configuration conf = NutchConfiguration.create();diff --git a/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java b/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.javaindex d110a611e..4bf239bda 100644--- a/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java+++ b/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java@@ -17,10 +17,10 @@package org.apache.nutch.fetcher;import java.io.IOException;-import java.io.File;import org.apache.nutch.crawl.CrawlDatum;import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.WritableComparable;@@ -39,7 +39,7 @@ import org.apache.nutch.protocol.Content;public class FetcherOutputFormat implements OutputFormat {public void checkOutputSpecs(FileSystem fs, JobConf job) throws IOException {- if (fs.exists(new File(job.getOutputDir(), CrawlDatum.FETCH_DIR_NAME)))+ if (fs.exists(new Path(job.getOutputPath(), CrawlDatum.FETCH_DIR_NAME)))throw new IOException("Segment already fetched!");}@@ -47,10 +47,10 @@ public class FetcherOutputFormat implements OutputFormat {final JobConf job,final String name) throws IOException {- final File fetch =- new File(new File(job.getOutputDir(), CrawlDatum.FETCH_DIR_NAME), name);- final File content =- new File(new File(job.getOutputDir(), Content.DIR_NAME), name);+ final Path fetch =+ new Path(new Path(job.getOutputPath(), CrawlDatum.FETCH_DIR_NAME), name);+ final Path content =+ new Path(new Path(job.getOutputPath(), Content.DIR_NAME), name);final MapFile.Writer fetchOut =new MapFile.Writer(fs, fetch.toString(), UTF8.class, CrawlDatum.class);diff --git a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java b/src/java/org/apache/nutch/indexer/DeleteDuplicates.javaindex c0484756d..bf35ecd5d 100644--- a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java+++ b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java@@ -134,7 +134,7 @@ public class DeleteDuplicates extends Configuredpublic FileSplit[] getSplits(FileSystem fs, JobConf job,int numSplits)throws IOException {- File[] files = listFiles(fs, job);+ Path[] files = listPaths(fs, job);FileSplit[] splits = new FileSplit[files.length];for (int i = 0; i < files.length; i++) {splits[i] = new FileSplit(files[i], 0, INDEX_LENGTH);@@ -147,12 +147,12 @@ public class DeleteDuplicates extends Configuredfinal FileSplit split,final JobConf job,Reporter reporter) throws IOException {- final UTF8 index = new UTF8(split.getFile().toString());+ final UTF8 index = new UTF8(split.getPath().toString());reporter.setStatus(index.toString());return new RecordReader() {private IndexReader indexReader =- IndexReader.open(new FsDirectory(fs, split.getFile(), false, job));+ IndexReader.open(new FsDirectory(fs, split.getPath(), false, job));{ indexReader.undeleteAll(); }@@ -264,7 +264,7 @@ public class DeleteDuplicates extends Configuredpublic void reduce(WritableComparable key, Iterator values,OutputCollector output, Reporter reporter)throws IOException {- File index = new File(key.toString());+ Path index = new Path(key.toString());IndexReader reader = IndexReader.open(new FsDirectory(fs, index, false, getConf()));try {while (values.hasNext()) {@@ -290,20 +290,20 @@ public class DeleteDuplicates extends Configuredpublic void checkOutputSpecs(FileSystem fs, JobConf job) {}- public void dedup(File[] indexDirs)+ public void dedup(Path[] indexDirs)throws IOException {LOG.info("Dedup: starting");- File hashDir =- new File("dedup-hash-"++ Path hashDir =+ new Path("dedup-hash-"+Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));JobConf job = new NutchJob(getConf());for (int i = 0; i < indexDirs.length; i++) {LOG.info("Dedup: adding indexes in: " + indexDirs[i]);- job.addInputDir(indexDirs[i]);+ job.addInputPath(indexDirs[i]);}job.setJobName("dedup phase 1");@@ -315,7 +315,7 @@ public class DeleteDuplicates extends Configuredjob.setPartitionerClass(HashPartitioner.class);job.setReducerClass(HashReducer.class);- job.setOutputDir(hashDir);+ job.setOutputPath(hashDir);job.setOutputKeyClass(HashScore.class);job.setOutputValueClass(IndexDoc.class);@@ -326,7 +326,7 @@ public class DeleteDuplicates extends Configuredjob = new NutchJob(getConf());job.setJobName("dedup phase 2");- job.addInputDir(hashDir);+ job.addInputPath(hashDir);job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(HashScore.class);@@ -355,9 +355,9 @@ public class DeleteDuplicates extends Configuredreturn;}- File[] indexes = new File[args.length];+ Path[] indexes = new Path[args.length];for (int i = 0; i < args.length; i++) {- indexes[i] = new File(args[i]);+ indexes[i] = new Path(args[i]);}dedup.dedup(indexes);diff --git a/src/java/org/apache/nutch/indexer/FsDirectory.java b/src/java/org/apache/nutch/indexer/FsDirectory.javaindex 82a6c5950..08250e283 100644--- a/src/java/org/apache/nutch/indexer/FsDirectory.java+++ b/src/java/org/apache/nutch/indexer/FsDirectory.java@@ -25,10 +25,10 @@ import org.apache.hadoop.conf.Configuration;public class FsDirectory extends Directory {private FileSystem fs;- private File directory;+ private Path directory;private int ioFileBufferSize;- public FsDirectory(FileSystem fs, File directory, boolean create, Configuration conf)+ public FsDirectory(FileSystem fs, Path directory, boolean create, Configuration conf)throws IOException {this.fs = fs;@@ -52,15 +52,15 @@ public class FsDirectory extends Directory {throw new IOException(directory + " not a directory");// clear old files- File[] files = fs.listFiles(directory);+ Path[] files = fs.listPaths(directory);for (int i = 0; i < files.length; i++) {- if (!files[i].delete())+ if (!fs.delete(files[i]))throw new IOException("Cannot delete " + files[i]);}}public String[] list() throws IOException {- File[] files = fs.listFiles(directory);+ Path[] files = fs.listPaths(directory);if (files == null) return null;String[] result = new String[files.length];@@ -71,7 +71,7 @@ public class FsDirectory extends Directory {}public boolean fileExists(String name) throws IOException {- return fs.exists(new File(directory, name));+ return fs.exists(new Path(directory, name));}public long fileModified(String name) {@@ -83,26 +83,26 @@ public class FsDirectory extends Directory {}public long fileLength(String name) throws IOException {- return fs.getLength(new File(directory, name));+ return fs.getLength(new Path(directory, name));}public void deleteFile(String name) throws IOException {- if (!fs.delete(new File(directory, name)))+ if (!fs.delete(new Path(directory, name)))throw new IOException("Cannot delete " + name);}public void renameFile(String from, String to) throws IOException {// DFS is currently broken when target already exists,// so we explicitly delete the target first.- File target = new File(directory, to);+ Path target = new Path(directory, to);if (fs.exists(target)) {fs.delete(target);}- fs.rename(new File(directory, from), target);+ fs.rename(new Path(directory, from), target);}public IndexOutput createOutput(String name) throws IOException {- File file = new File(directory, name);+ Path file = new Path(directory, name);if (fs.exists(file) && !fs.delete(file)) // delete existing, if anythrow new IOException("Cannot overwrite: " + file);@@ -111,14 +111,14 @@ public class FsDirectory extends Directory {public IndexInput openInput(String name) throws IOException {- return new DfsIndexInput(new File(directory, name), this.ioFileBufferSize);+ return new DfsIndexInput(new Path(directory, name), this.ioFileBufferSize);}public Lock makeLock(final String name) {return new Lock() {public boolean obtain() {try {- fs.lock(new File(directory, name), false);+ fs.lock(new Path(directory, name), false);return true;} catch (IOException e) {return false;@@ -126,7 +126,7 @@ public class FsDirectory extends Directory {}public void release() {try {- fs.release(new File(directory, name));+ fs.release(new Path(directory, name));} catch (IOException e) {throw new RuntimeException(e);}@@ -135,7 +135,7 @@ public class FsDirectory extends Directory {throw new UnsupportedOperationException();}public String toString() {- return "Lock@" + new File(directory, name);+ return "Lock@" + new Path(directory, name);}};}@@ -155,7 +155,7 @@ public class FsDirectory extends Directory {private class Descriptor {public FSDataInputStream in;public long position; // cache of in.getPos()- public Descriptor(File file, int ioFileBufferSize) throws IOException {+ public Descriptor(Path file, int ioFileBufferSize) throws IOException {this.in = fs.open(file);}}@@ -164,7 +164,7 @@ public class FsDirectory extends Directory {private final long length;private boolean isClone;- public DfsIndexInput(File path, int ioFileBufferSize) throws IOException {+ public DfsIndexInput(Path path, int ioFileBufferSize) throws IOException {descriptor = new Descriptor(path,ioFileBufferSize);length = fs.getLength(path);}@@ -214,7 +214,7 @@ public class FsDirectory extends Directory {private class DfsIndexOutput extends BufferedIndexOutput {private FSDataOutputStream out;- public DfsIndexOutput(File path, int ioFileBufferSize) throws IOException {+ public DfsIndexOutput(Path path, int ioFileBufferSize) throws IOException {out = fs.create(path);}diff --git a/src/java/org/apache/nutch/indexer/IndexMerger.java b/src/java/org/apache/nutch/indexer/IndexMerger.javaindex c7cd2b823..fce32d812 100644--- a/src/java/org/apache/nutch/indexer/IndexMerger.java+++ b/src/java/org/apache/nutch/indexer/IndexMerger.java@@ -43,15 +43,15 @@ public class IndexMerger {public static final String DONE_NAME = "merge.done";private FileSystem fs;- private File outputIndex;- private File localWorkingDir;- private File[] indexes;+ private Path outputIndex;+ private Path localWorkingDir;+ private Path[] indexes;private Configuration conf;/*** Merge all of the indexes given*/- public IndexMerger(FileSystem fs, File[] indexes, File outputIndex, File localWorkingDir, Configuration conf) throws IOException {+ public IndexMerger(FileSystem fs, Path[] indexes, Path outputIndex, Path localWorkingDir, Configuration conf) throws IOException {this.fs = fs;this.indexes = indexes;this.outputIndex = outputIndex;@@ -69,8 +69,8 @@ public class IndexMerger {// Get local output target//- File tmpLocalOutput = new File(localWorkingDir, "merge-output");- File localOutput = fs.startLocalOutput(outputIndex, tmpLocalOutput);+ Path tmpLocalOutput = new Path(localWorkingDir, "merge-output");+ Path localOutput = fs.startLocalOutput(outputIndex, tmpLocalOutput);Directory[] dirs = new Directory[indexes.length];for (int i = 0; i < indexes.length; i++) {@@ -83,7 +83,7 @@ public class IndexMerger {//// Merge indices//- IndexWriter writer = new IndexWriter(localOutput, null, true);+ IndexWriter writer = new IndexWriter(localOutput.toString(), null, true);writer.setMergeFactor(conf.getInt("indexer.mergeFactor", IndexWriter.DEFAULT_MERGE_FACTOR));writer.setMaxBufferedDocs(conf.getInt("indexer.minMergeDocs", IndexWriter.DEFAULT_MAX_BUFFERED_DOCS));writer.setMaxMergeDocs(conf.getInt("indexer.maxMergeDocs", IndexWriter.DEFAULT_MAX_MERGE_DOCS));@@ -99,7 +99,7 @@ public class IndexMerger {//fs.completeLocalOutput(outputIndex, tmpLocalOutput);- localWorkingDir.delete();+ FileSystem.getNamed("local", conf).delete(localWorkingDir);}/**@@ -117,20 +117,19 @@ public class IndexMerger {//Configuration conf = NutchConfiguration.create();FileSystem fs = FileSystem.get(conf);- File workDir = new File(new File("").getCanonicalPath());+ Path workDir = new Path("indexmerger");List indexDirs = new ArrayList();int i = 0;if ("-workingdir".equals(args[i])) {i++;- workDir = new File(new File(args[i++]).getCanonicalPath());+ workDir = new Path(args[i++]);}- workDir = new File(workDir, "indexmerger-workingdir");- File outputIndex = new File(args[i++]);+ Path outputIndex = new Path(args[i++]);for (; i < args.length; i++) {- indexDirs.addAll(Arrays.asList(fs.listFiles(new File(args[i]))));+ indexDirs.addAll(Arrays.asList(fs.listPaths(new Path(args[i]))));}//@@ -138,15 +137,17 @@ public class IndexMerger {//LOG.info("merging indexes to: " + outputIndex);- File[] indexFiles = (File[])indexDirs.toArray(new File[indexDirs.size()]);+ Path[] indexFiles = (Path[])indexDirs.toArray(new Path[indexDirs.size()]);- if (workDir.exists()) {- FileUtil.fullyDelete(workDir, conf);+ FileSystem localFs = FileSystem.getNamed("local", conf);+ if (localFs.exists(workDir)) {+ localFs.delete(workDir);}- workDir.mkdirs();- IndexMerger merger = new IndexMerger(fs,indexFiles,outputIndex,workDir, conf);+ localFs.mkdirs(workDir);+ IndexMerger merger =+ new IndexMerger(fs, indexFiles, outputIndex, workDir, conf);merger.merge();LOG.info("done merging");- FileUtil.fullyDelete(workDir, conf);+ localFs.delete(workDir);}}diff --git a/src/java/org/apache/nutch/indexer/Indexer.java b/src/java/org/apache/nutch/indexer/Indexer.javaindex dded70cc6..2cda313c9 100644--- a/src/java/org/apache/nutch/indexer/Indexer.java+++ b/src/java/org/apache/nutch/indexer/Indexer.java@@ -78,15 +78,15 @@ public class Indexer extends Configured implements Reducer {extends org.apache.hadoop.mapred.OutputFormatBase {public RecordWriter getRecordWriter(final FileSystem fs, JobConf job,String name) throws IOException {- final File perm = new File(job.getOutputDir(), name);- final File temp =- job.getLocalFile("index","_"+Integer.toString(new Random().nextInt()));+ final Path perm = new Path(job.getOutputPath(), name);+ final Path temp =+ job.getLocalPath("index/_"+Integer.toString(new Random().nextInt()));fs.delete(perm); // delete old, if anyfinal AnalyzerFactory factory = new AnalyzerFactory(job);final IndexWriter writer = // build locally first- new IndexWriter(fs.startLocalOutput(perm, temp),+ new IndexWriter(fs.startLocalOutput(perm, temp).toString(),new NutchDocumentAnalyzer(job), true);writer.setMergeFactor(job.getInt("indexer.mergeFactor", 10));@@ -132,7 +132,7 @@ public class Indexer extends Configured implements Reducer {writer.optimize();writer.close();fs.completeLocalOutput(perm, temp); // copy to dfs- fs.createNewFile(new File(perm, DONE_NAME));+ fs.createNewFile(new Path(perm, DONE_NAME));} finally {closed = true;}@@ -242,7 +242,7 @@ public class Indexer extends Configured implements Reducer {output.collect(key, new ObjectWritable(doc));}- public void index(File indexDir, File crawlDb, File linkDb, File[] segments)+ public void index(Path indexDir, Path crawlDb, Path linkDb, Path[] segments)throws IOException {LOG.info("Indexer: starting");@@ -253,13 +253,13 @@ public class Indexer extends Configured implements Reducer {for (int i = 0; i < segments.length; i++) {LOG.info("Indexer: adding segment: " + segments[i]);- job.addInputDir(new File(segments[i], CrawlDatum.FETCH_DIR_NAME));- job.addInputDir(new File(segments[i], ParseData.DIR_NAME));- job.addInputDir(new File(segments[i], ParseText.DIR_NAME));+ job.addInputPath(new Path(segments[i], CrawlDatum.FETCH_DIR_NAME));+ job.addInputPath(new Path(segments[i], ParseData.DIR_NAME));+ job.addInputPath(new Path(segments[i], ParseText.DIR_NAME));}- job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));- job.addInputDir(new File(linkDb, LinkDb.CURRENT_NAME));+ job.addInputPath(new Path(crawlDb, CrawlDatum.DB_DIR_NAME));+ job.addInputPath(new Path(linkDb, LinkDb.CURRENT_NAME));job.setInputFormat(InputFormat.class);job.setInputKeyClass(UTF8.class);@@ -268,7 +268,7 @@ public class Indexer extends Configured implements Reducer {//job.setCombinerClass(Indexer.class);job.setReducerClass(Indexer.class);- job.setOutputDir(indexDir);+ job.setOutputPath(indexDir);job.setOutputFormat(OutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(ObjectWritable.class);@@ -285,12 +285,12 @@ public class Indexer extends Configured implements Reducer {return;}- File[] segments = new File[args.length-3];+ Path[] segments = new Path[args.length-3];for (int i = 3; i < args.length; i++) {- segments[i-3] = new File(args[i]);+ segments[i-3] = new Path(args[i]);}- indexer.index(new File(args[0]), new File(args[1]), new File(args[2]),+ indexer.index(new Path(args[0]), new Path(args[1]), new Path(args[2]),segments);}diff --git a/src/java/org/apache/nutch/parse/ParseData.java b/src/java/org/apache/nutch/parse/ParseData.javaindex 719e7481d..a15071339 100644--- a/src/java/org/apache/nutch/parse/ParseData.java+++ b/src/java/org/apache/nutch/parse/ParseData.java@@ -219,7 +219,7 @@ public final class ParseData extends VersionedWritable implements Configurable {int recno = Integer.parseInt(argv[0]);String segment = argv[1];- File file = new File(segment, DIR_NAME);+ Path file = new Path(segment, DIR_NAME);System.out.println("Reading from file: " + file);ArrayFile.Reader parses = new ArrayFile.Reader(fs, file.toString(), conf);diff --git a/src/java/org/apache/nutch/parse/ParseOutputFormat.java b/src/java/org/apache/nutch/parse/ParseOutputFormat.javaindex 965413e6c..cfaa353ad 100644--- a/src/java/org/apache/nutch/parse/ParseOutputFormat.java+++ b/src/java/org/apache/nutch/parse/ParseOutputFormat.java@@ -35,7 +35,7 @@ public class ParseOutputFormat implements OutputFormat {private URLFilters filters;public void checkOutputSpecs(FileSystem fs, JobConf job) throws IOException {- if (fs.exists(new File(job.getOutputDir(), CrawlDatum.PARSE_DIR_NAME)))+ if (fs.exists(new Path(job.getOutputPath(), CrawlDatum.PARSE_DIR_NAME)))throw new IOException("Segment already parsed!");}@@ -49,12 +49,12 @@ public class ParseOutputFormat implements OutputFormat {final float extscore = job.getFloat("db.score.link.external", 1.0f);final boolean countFiltered = job.getBoolean("db.score.count.filtered", false);- File text =- new File(new File(job.getOutputDir(), ParseText.DIR_NAME), name);- File data =- new File(new File(job.getOutputDir(), ParseData.DIR_NAME), name);- File crawl =- new File(new File(job.getOutputDir(), CrawlDatum.PARSE_DIR_NAME), name);+ Path text =+ new Path(new Path(job.getOutputPath(), ParseText.DIR_NAME), name);+ Path data =+ new Path(new Path(job.getOutputPath(), ParseData.DIR_NAME), name);+ Path crawl =+ new Path(new Path(job.getOutputPath(), CrawlDatum.PARSE_DIR_NAME), name);final MapFile.Writer textOut =new MapFile.Writer(fs, text.toString(), UTF8.class, ParseText.class);@@ -63,8 +63,7 @@ public class ParseOutputFormat implements OutputFormat {new MapFile.Writer(fs, data.toString(), UTF8.class,ParseData.class,true);final SequenceFile.Writer crawlOut =- new SequenceFile.Writer(fs, crawl.toString(),- UTF8.class, CrawlDatum.class);+ new SequenceFile.Writer(fs, crawl, UTF8.class, CrawlDatum.class);return new RecordWriter() {diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.javaindex 0d2a6939d..909a282b1 100644--- a/src/java/org/apache/nutch/parse/ParseSegment.java+++ b/src/java/org/apache/nutch/parse/ParseSegment.java@@ -25,6 +25,7 @@ import org.apache.hadoop.util.LogFormatter;import org.apache.nutch.protocol.*;import org.apache.nutch.metadata.Metadata;import org.apache.nutch.util.*;+import org.apache.hadoop.fs.Path;import java.io.*;import java.util.*;@@ -81,21 +82,21 @@ public class ParseSegment extends Configured implements Mapper, Reducer {output.collect(key, (Writable)values.next()); // collect first value}- public void parse(File segment) throws IOException {+ public void parse(Path segment) throws IOException {LOG.info("Parse: starting");LOG.info("Parse: segment: " + segment);JobConf job = new NutchJob(getConf());job.setJobName("parse " + segment);- job.setInputDir(new File(segment, Content.DIR_NAME));+ job.setInputPath(new Path(segment, Content.DIR_NAME));job.setInputFormat(SequenceFileInputFormat.class);job.setInputKeyClass(UTF8.class);job.setInputValueClass(Content.class);job.setMapperClass(ParseSegment.class);job.setReducerClass(ParseSegment.class);- job.setOutputDir(segment);+ job.setOutputPath(segment);job.setOutputFormat(ParseOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(ParseImpl.class);@@ -106,7 +107,7 @@ public class ParseSegment extends Configured implements Mapper, Reducer {public static void main(String[] args) throws Exception {- File segment;+ Path segment;String usage = "Usage: ParseSegment segment";@@ -115,7 +116,7 @@ public class ParseSegment extends Configured implements Mapper, Reducer {System.exit(-1);}- segment = new File(args[0]);+ segment = new Path(args[0]);ParseSegment parseSegment = new ParseSegment(NutchConfiguration.create());parseSegment.parse(segment);diff --git a/src/java/org/apache/nutch/parse/ParseText.java b/src/java/org/apache/nutch/parse/ParseText.javaindex dd6880dbb..bbff6d090 100644--- a/src/java/org/apache/nutch/parse/ParseText.java+++ b/src/java/org/apache/nutch/parse/ParseText.java@@ -86,7 +86,7 @@ public final class ParseText extends VersionedWritable {try {int recno = Integer.parseInt(argv[0]);String segment = argv[1];- String filename = new File(segment, ParseText.DIR_NAME).getPath();+ String filename = new Path(segment, ParseText.DIR_NAME).toString();ParseText parseText = new ParseText();ArrayFile.Reader parseTexts = new ArrayFile.Reader(fs, filename, conf);diff --git a/src/java/org/apache/nutch/protocol/Content.java b/src/java/org/apache/nutch/protocol/Content.javaindex 0924d452c..e74caf8a0 100755--- a/src/java/org/apache/nutch/protocol/Content.java+++ b/src/java/org/apache/nutch/protocol/Content.java@@ -196,7 +196,7 @@ public final class Content extends CompressedWritable {int recno = Integer.parseInt(argv[0]);String segment = argv[1];- File file = new File(segment, DIR_NAME);+ Path file = new Path(segment, DIR_NAME);System.out.println("Reading from file: " + file);ArrayFile.Reader contents = new ArrayFile.Reader(fs, file.toString(), conf);diff --git a/src/java/org/apache/nutch/searcher/DistributedSearch.java b/src/java/org/apache/nutch/searcher/DistributedSearch.javaindex 839943f0f..9ffa3273a 100644--- a/src/java/org/apache/nutch/searcher/DistributedSearch.java+++ b/src/java/org/apache/nutch/searcher/DistributedSearch.java@@ -29,6 +29,8 @@ import org.apache.nutch.crawl.Inlinks;import org.apache.hadoop.util.LogFormatter;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.ipc.RPC;+import org.apache.hadoop.fs.Path;+import org.apache.hadoop.fs.FileSystem;import org.apache.nutch.util.NutchConfiguration;@@ -62,7 +64,7 @@ public class DistributedSearch {}int port = Integer.parseInt(args[0]);- File directory = new File(args[1]);+ Path directory = new Path(args[1]);Configuration conf = NutchConfiguration.create();NutchBean bean = new NutchBean(conf, directory);@@ -90,29 +92,34 @@ public class DistributedSearch {* Each line in the file lists a server hostname and port, separated by* whitespace.*/-- public Client(File file, Configuration conf) throws IOException {- this(readConfig(file), conf);+ public Client(Path file, Configuration conf) throws IOException {+ this(readConfig(file, conf), conf);}- private static InetSocketAddress[] readConfig(File config)+ private static InetSocketAddress[] readConfig(Path path, Configuration conf)throws IOException {- BufferedReader reader = new BufferedReader(new FileReader(config));- ArrayList addrs = new ArrayList();- String line;- while ((line = reader.readLine()) != null) {- StringTokenizer tokens = new StringTokenizer(line);- if (tokens.hasMoreTokens()) {- String host = tokens.nextToken();+ FileSystem fs = FileSystem.get(conf);+ BufferedReader reader =+ new BufferedReader(new InputStreamReader(fs.open(path)));+ try {+ ArrayList addrs = new ArrayList();+ String line;+ while ((line = reader.readLine()) != null) {+ StringTokenizer tokens = new StringTokenizer(line);if (tokens.hasMoreTokens()) {- String port = tokens.nextToken();- addrs.add(new InetSocketAddress(host, Integer.parseInt(port)));- LOG.info("Client adding server " + host + ":" + port);+ String host = tokens.nextToken();+ if (tokens.hasMoreTokens()) {+ String port = tokens.nextToken();+ addrs.add(new InetSocketAddress(host, Integer.parseInt(port)));+ LOG.info("Client adding server " + host + ":" + port);+ }}}+ return (InetSocketAddress[])+ addrs.toArray(new InetSocketAddress[addrs.size()]);+ } finally {+ reader.close();}- return (InetSocketAddress[])- addrs.toArray(new InetSocketAddress[addrs.size()]);}/** Construct a client talking to the named servers. */diff --git a/src/java/org/apache/nutch/searcher/FetchedSegments.java b/src/java/org/apache/nutch/searcher/FetchedSegments.javaindex e23a7ad9c..2f0bd24c1 100644--- a/src/java/org/apache/nutch/searcher/FetchedSegments.java+++ b/src/java/org/apache/nutch/searcher/FetchedSegments.java@@ -17,7 +17,6 @@package org.apache.nutch.searcher;import java.io.IOException;-import java.io.File;import java.util.HashMap;import java.util.Iterator;@@ -39,7 +38,7 @@ public class FetchedSegments implements HitSummarizer, HitContent {private static final Partitioner PARTITIONER = new HashPartitioner();private FileSystem fs;- private File segmentDir;+ private Path segmentDir;private MapFile.Reader[] content;private MapFile.Reader[] parseText;@@ -47,7 +46,7 @@ public class FetchedSegments implements HitSummarizer, HitContent {private MapFile.Reader[] crawl;private Configuration conf;- public Segment(FileSystem fs, File segmentDir, Configuration conf) throws IOException {+ public Segment(FileSystem fs, Path segmentDir, Configuration conf) throws IOException {this.fs = fs;this.segmentDir = segmentDir;this.conf = conf;@@ -86,7 +85,7 @@ public class FetchedSegments implements HitSummarizer, HitContent {}private MapFile.Reader[] getReaders(String subDir) throws IOException {- return MapFileOutputFormat.getReaders(fs, new File(segmentDir, subDir), this.conf);+ return MapFileOutputFormat.getReaders(fs, new Path(segmentDir, subDir), this.conf);}private Writable getEntry(MapFile.Reader[] readers, UTF8 url,@@ -114,13 +113,13 @@ public class FetchedSegments implements HitSummarizer, HitContent {/** Construct given a directory containing fetcher output. */public FetchedSegments(FileSystem fs, String segmentsDir, Configuration conf) throws IOException {- File[] segmentDirs = fs.listFiles(new File(segmentsDir));+ Path[] segmentDirs = fs.listPaths(new Path(segmentsDir));this.summarizer = new SummarizerFactory(conf).getSummarizer();if (segmentDirs != null) {for (int i = 0; i < segmentDirs.length; i++) {- File segmentDir = segmentDirs[i];-// File indexdone = new File(segmentDir, IndexSegment.DONE_NAME);+ Path segmentDir = segmentDirs[i];+// Path indexdone = new Path(segmentDir, IndexSegment.DONE_NAME);// if (fs.exists(indexdone) && fs.isFile(indexdone)) {// segments.put(segmentDir.getName(), new Segment(fs, segmentDir));// }diff --git a/src/java/org/apache/nutch/searcher/IndexSearcher.java b/src/java/org/apache/nutch/searcher/IndexSearcher.javaindex 57ddc412a..60237a52c 100644--- a/src/java/org/apache/nutch/searcher/IndexSearcher.java+++ b/src/java/org/apache/nutch/searcher/IndexSearcher.java@@ -17,7 +17,6 @@package org.apache.nutch.searcher;import java.io.IOException;-import java.io.File;import java.util.ArrayList;import java.util.Enumeration;@@ -53,7 +52,7 @@ public class IndexSearcher implements Searcher, HitDetailer {private QueryFilters queryFilters;/** Construct given a number of indexes. */- public IndexSearcher(File[] indexDirs, Configuration conf) throws IOException {+ public IndexSearcher(Path[] indexDirs, Configuration conf) throws IOException {IndexReader[] readers = new IndexReader[indexDirs.length];this.conf = conf;this.fs = FileSystem.get(conf);@@ -64,7 +63,7 @@ public class IndexSearcher implements Searcher, HitDetailer {}/** Construct given a single merged index. */- public IndexSearcher(File index, Configuration conf)+ public IndexSearcher(Path index, Configuration conf)throws IOException {this.conf = conf;this.fs = FileSystem.get(conf);@@ -79,9 +78,9 @@ public class IndexSearcher implements Searcher, HitDetailer {this.queryFilters = new QueryFilters(conf);}- private Directory getDirectory(File file) throws IOException {+ private Directory getDirectory(Path file) throws IOException {if ("local".equals(this.fs.getName())) {- return FSDirectory.getDirectory(file, false);+ return FSDirectory.getDirectory(file.toString(), false);} else {return new FsDirectory(this.fs, file, false, this.conf);}diff --git a/src/java/org/apache/nutch/searcher/LinkDbInlinks.java b/src/java/org/apache/nutch/searcher/LinkDbInlinks.javaindex 2eeacde90..11159a0c7 100644--- a/src/java/org/apache/nutch/searcher/LinkDbInlinks.java+++ b/src/java/org/apache/nutch/searcher/LinkDbInlinks.java@@ -12,14 +12,13 @@ import org.apache.nutch.crawl.LinkDbReader;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.io.UTF8;import org.apache.hadoop.conf.Configuration;--import java.io.File;+import org.apache.hadoop.fs.Path;public class LinkDbInlinks implements HitInlinks {private LinkDbReader linkdb = null;- public LinkDbInlinks(FileSystem fs, File dir, Configuration conf) {+ public LinkDbInlinks(FileSystem fs, Path dir, Configuration conf) {linkdb = new LinkDbReader(fs, dir, conf);}diff --git a/src/java/org/apache/nutch/searcher/NutchBean.java b/src/java/org/apache/nutch/searcher/NutchBean.javaindex 7ecc75a59..b3dac18ff 100644--- a/src/java/org/apache/nutch/searcher/NutchBean.java+++ b/src/java/org/apache/nutch/searcher/NutchBean.java@@ -89,24 +89,24 @@ public class NutchBean* @param dir* @throws IOException*/- public NutchBean(Configuration conf, File dir) throws IOException {+ public NutchBean(Configuration conf, Path dir) throws IOException {this.conf = conf;this.fs = FileSystem.get(this.conf);if (dir == null) {- dir = new File(this.conf.get("searcher.dir", "crawl"));+ dir = new Path(this.conf.get("searcher.dir", "crawl"));}- File servers = new File(dir, "search-servers.txt");+ Path servers = new Path(dir, "search-servers.txt");if (fs.exists(servers)) {- LOG.info("searching servers in " + servers.getCanonicalPath());+ LOG.info("searching servers in " + servers);init(new DistributedSearch.Client(servers, conf));} else {- init(new File(dir, "index"), new File(dir, "indexes"), new File(- dir, "segments"), new File(dir, "linkdb"));+ init(new Path(dir, "index"), new Path(dir, "indexes"), new Path(+ dir, "segments"), new Path(dir, "linkdb"));}}- private void init(File indexDir, File indexesDir, File segmentsDir,- File linkDb)+ private void init(Path indexDir, Path indexesDir, Path segmentsDir,+ Path linkDb)throws IOException {IndexSearcher indexSearcher;if (this.fs.exists(indexDir)) {@@ -116,18 +116,18 @@ public class NutchBeanLOG.info("opening indexes in " + indexesDir);Vector vDirs=new Vector();- File [] directories = fs.listFiles(indexesDir);- for(int i = 0; i < fs.listFiles(indexesDir).length; i++) {- File indexdone = new File(directories[i], Indexer.DONE_NAME);+ Path [] directories = fs.listPaths(indexesDir);+ for(int i = 0; i < fs.listPaths(indexesDir).length; i++) {+ Path indexdone = new Path(directories[i], Indexer.DONE_NAME);if(fs.isFile(indexdone)) {vDirs.add(directories[i]);}}- directories = new File[ vDirs.size() ];+ directories = new Path[ vDirs.size() ];for(int i = 0; vDirs.size()>0; i++) {- directories[i]=(File)vDirs.remove(0);+ directories[i]=(Path)vDirs.remove(0);}indexSearcher = new IndexSearcher(directories, this.conf);diff --git a/src/java/org/apache/nutch/segment/SegmentReader.java b/src/java/org/apache/nutch/segment/SegmentReader.javaindex 3b57ec8c9..365aca1ea 100644--- a/src/java/org/apache/nutch/segment/SegmentReader.java+++ b/src/java/org/apache/nutch/segment/SegmentReader.java@@ -23,7 +23,7 @@ import java.util.logging.Logger;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;-import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.*;import org.apache.hadoop.io.*;import org.apache.hadoop.mapred.*;import org.apache.hadoop.util.LogFormatter;@@ -70,7 +70,7 @@ public class SegmentReader extends Configured implements Reducer {public static class TextOutputFormat extends org.apache.hadoop.mapred.OutputFormatBase {public RecordWriter getRecordWriter(final FileSystem fs, JobConf job, String name) throws IOException {- final File segmentDumpFile = new File(job.getOutputDir(), name);+ final Path segmentDumpFile = new Path(job.getOutputPath(), name);// Get the old copy out of the wayfs.delete(segmentDumpFile);@@ -160,18 +160,18 @@ public class SegmentReader extends Configured implements Reducer {output.collect(key, new ObjectWritable(dump.toString()));}- public void dump(File segment, File output) throws IOException {+ public void dump(Path segment, Path output) throws IOException {LOG.info("SegmentReader: dump segment: " + segment);JobConf job = createJobConf();job.setJobName("read " + segment);- if (ge) job.addInputDir(new File(segment, CrawlDatum.GENERATE_DIR_NAME));- if (fe) job.addInputDir(new File(segment, CrawlDatum.FETCH_DIR_NAME));- if (pa) job.addInputDir(new File(segment, CrawlDatum.PARSE_DIR_NAME));- if (co) job.addInputDir(new File(segment, Content.DIR_NAME));- if (pd) job.addInputDir(new File(segment, ParseData.DIR_NAME));- if (pt) job.addInputDir(new File(segment, ParseText.DIR_NAME));+ if (ge) job.addInputPath(new Path(segment, CrawlDatum.GENERATE_DIR_NAME));+ if (fe) job.addInputPath(new Path(segment, CrawlDatum.FETCH_DIR_NAME));+ if (pa) job.addInputPath(new Path(segment, CrawlDatum.PARSE_DIR_NAME));+ if (co) job.addInputPath(new Path(segment, Content.DIR_NAME));+ if (pd) job.addInputPath(new Path(segment, ParseData.DIR_NAME));+ if (pt) job.addInputPath(new Path(segment, ParseText.DIR_NAME));job.setInputFormat(InputFormat.class);job.setInputKeyClass(UTF8.class);@@ -179,10 +179,10 @@ public class SegmentReader extends Configured implements Reducer {job.setReducerClass(SegmentReader.class);- File tempDir = new File("/tmp/segread-" + new java.util.Random().nextInt());+ Path tempDir = new Path("/tmp/segread-" + new java.util.Random().nextInt());fs.delete(tempDir);- job.setOutputDir(tempDir);+ job.setOutputPath(tempDir);job.setOutputFormat(TextOutputFormat.class);job.setOutputKeyClass(UTF8.class);job.setOutputValueClass(ObjectWritable.class);@@ -190,11 +190,11 @@ public class SegmentReader extends Configured implements Reducer {JobClient.runJob(job);// concatenate the output- File dumpFile = new File(output, job.get("segment.dump.dir", "dump"));+ Path dumpFile = new Path(output, job.get("segment.dump.dir", "dump"));// remove the old filefs.delete(dumpFile);- File[] files = fs.listFiles(tempDir);+ Path[] files = fs.listPaths(tempDir);PrintWriter writer = null;int currentRecordNumber = 0;@@ -202,7 +202,7 @@ public class SegmentReader extends Configured implements Reducer {writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fs.create(dumpFile))));try {for (int i = 0; i < files.length; i++) {- File partFile = (File) files[i];+ Path partFile = (Path) files[i];try {currentRecordNumber = append(fs, job, partFile, writer, currentRecordNumber);} catch (IOException exception) {@@ -219,7 +219,7 @@ public class SegmentReader extends Configured implements Reducer {}/** Appends two files and updates the Recno counter */- private int append(FileSystem fs, Configuration conf, File src, PrintWriter writer, int currentRecordNumber)+ private int append(FileSystem fs, Configuration conf, Path src, PrintWriter writer, int currentRecordNumber)throws IOException {BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(src)));try {@@ -246,14 +246,14 @@ public class SegmentReader extends Configured implements Reducer {{"pt", "ParseText::\n"}};- public void get(final File segment, final UTF8 key, Writer writer,+ public void get(final Path segment, final UTF8 key, Writer writer,final Map results) throws Exception {LOG.info("SegmentReader: get '" + key + "'");ArrayList threads = new ArrayList();if (co) threads.add(new Thread() {public void run() {try {- List res = getMapRecords(new File(segment, Content.DIR_NAME), key);+ List res = getMapRecords(new Path(segment, Content.DIR_NAME), key);results.put("co", res);} catch (Exception e) {e.printStackTrace();@@ -263,7 +263,7 @@ public class SegmentReader extends Configured implements Reducer {if (fe) threads.add(new Thread() {public void run() {try {- List res = getMapRecords(new File(segment, CrawlDatum.FETCH_DIR_NAME), key);+ List res = getMapRecords(new Path(segment, CrawlDatum.FETCH_DIR_NAME), key);results.put("fe", res);} catch (Exception e) {e.printStackTrace();@@ -273,7 +273,7 @@ public class SegmentReader extends Configured implements Reducer {if (ge) threads.add(new Thread() {public void run() {try {- List res = getSeqRecords(new File(segment, CrawlDatum.GENERATE_DIR_NAME), key);+ List res = getSeqRecords(new Path(segment, CrawlDatum.GENERATE_DIR_NAME), key);results.put("ge", res);} catch (Exception e) {e.printStackTrace();@@ -283,7 +283,7 @@ public class SegmentReader extends Configured implements Reducer {if (pa) threads.add(new Thread() {public void run() {try {- List res = getSeqRecords(new File(segment, CrawlDatum.PARSE_DIR_NAME), key);+ List res = getSeqRecords(new Path(segment, CrawlDatum.PARSE_DIR_NAME), key);results.put("pa", res);} catch (Exception e) {e.printStackTrace();@@ -293,7 +293,7 @@ public class SegmentReader extends Configured implements Reducer {if (pd) threads.add(new Thread() {public void run() {try {- List res = getMapRecords(new File(segment, ParseData.DIR_NAME), key);+ List res = getMapRecords(new Path(segment, ParseData.DIR_NAME), key);results.put("pd", res);} catch (Exception e) {e.printStackTrace();@@ -303,7 +303,7 @@ public class SegmentReader extends Configured implements Reducer {if (pt) threads.add(new Thread() {public void run() {try {- List res = getMapRecords(new File(segment, ParseText.DIR_NAME), key);+ List res = getMapRecords(new Path(segment, ParseText.DIR_NAME), key);results.put("pt", res);} catch (Exception e) {e.printStackTrace();@@ -335,7 +335,7 @@ public class SegmentReader extends Configured implements Reducer {}}- private List getMapRecords(File dir, UTF8 key) throws Exception {+ private List getMapRecords(Path dir, UTF8 key) throws Exception {MapFile.Reader[] readers = MapFileOutputFormat.getReaders(fs, dir, getConf());ArrayList res = new ArrayList();Class keyClass = readers[0].getKeyClass();@@ -352,7 +352,7 @@ public class SegmentReader extends Configured implements Reducer {return res;}- private List getSeqRecords(File dir, UTF8 key) throws Exception {+ private List getSeqRecords(Path dir, UTF8 key) throws Exception {SequenceFile.Reader[] readers = SequenceFileOutputFormat.getReaders(getConf(), dir);ArrayList res = new ArrayList();Class keyClass = readers[0].getKeyClass();@@ -386,7 +386,7 @@ public class SegmentReader extends Configured implements Reducer {public void list(List dirs, Writer writer) throws Exception {writer.write("NAME\t\tGENERATED\tFETCHER START\t\tFETCHER END\t\tFETCHED\tPARSED\n");for (int i = 0; i < dirs.size(); i++) {- File dir = (File)dirs.get(i);+ Path dir = (Path)dirs.get(i);SegmentReaderStats stats = new SegmentReaderStats();getStats(dir, stats);writer.write(dir.getName() + "\t");@@ -409,8 +409,8 @@ public class SegmentReader extends Configured implements Reducer {}}- public void getStats(File segment, final SegmentReaderStats stats) throws Exception {- SequenceFile.Reader[] readers = SequenceFileOutputFormat.getReaders(getConf(), new File(segment, CrawlDatum.GENERATE_DIR_NAME));+ public void getStats(Path segment, final SegmentReaderStats stats) throws Exception {+ SequenceFile.Reader[] readers = SequenceFileOutputFormat.getReaders(getConf(), new Path(segment, CrawlDatum.GENERATE_DIR_NAME));long cnt = 0L;UTF8 key = new UTF8();for (int i = 0; i < readers.length; i++) {@@ -418,7 +418,7 @@ public class SegmentReader extends Configured implements Reducer {readers[i].close();}stats.generated = cnt;- File fetchDir = new File(segment, CrawlDatum.FETCH_DIR_NAME);+ Path fetchDir = new Path(segment, CrawlDatum.FETCH_DIR_NAME);if (fs.exists(fetchDir) && fs.isDirectory(fetchDir)) {cnt = 0L;long start = Long.MAX_VALUE;@@ -437,7 +437,7 @@ public class SegmentReader extends Configured implements Reducer {stats.end = end;stats.fetched = cnt;}- File parseDir = new File(segment, ParseData.DIR_NAME);+ Path parseDir = new Path(segment, ParseData.DIR_NAME);if (fs.exists(fetchDir) && fs.isDirectory(fetchDir)) {cnt = 0L;long errors = 0L;@@ -519,16 +519,16 @@ public class SegmentReader extends Configured implements Reducer {usage();return;}- segmentReader.dump(new File(input), new File(output));+ segmentReader.dump(new Path(input), new Path(output));return;case MODE_LIST:ArrayList dirs = new ArrayList();for (int i = 1; i < args.length; i++) {if (args[i] == null) continue;if (args[i].equals("-dir")) {- File dir = new File(args[++i]);- File[] files = fs.listFiles(dir, new FileFilter() {- public boolean accept(File pathname) {+ Path dir = new Path(args[++i]);+ Path[] files = fs.listPaths(dir, new PathFilter() {+ public boolean accept(Path pathname) {try {if (fs.isDirectory(pathname)) return true;} catch (IOException e) {};@@ -538,7 +538,7 @@ public class SegmentReader extends Configured implements Reducer {if (files != null && files.length > 0) {dirs.addAll(Arrays.asList(files));}- } else dirs.add(new File(args[i]));+ } else dirs.add(new Path(args[i]));}segmentReader.list(dirs, new OutputStreamWriter(System.out, "UTF-8"));return;@@ -555,7 +555,7 @@ public class SegmentReader extends Configured implements Reducer {usage();return;}- segmentReader.get(new File(input), new UTF8(key), new OutputStreamWriter(System.out, "UTF-8"), new HashMap());+ segmentReader.get(new Path(input), new UTF8(key), new OutputStreamWriter(System.out, "UTF-8"), new HashMap());return;default:System.err.println("Invalid operation: " + args[0]);diff --git a/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java b/src/test/org/apache/nutch/crawl/TestLinkDbMerger.javaindex dc121abfd..5a5f27bae 100644--- a/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java+++ b/src/test/org/apache/nutch/crawl/TestLinkDbMerger.java@@ -16,7 +16,6 @@package org.apache.nutch.crawl;-import java.io.File;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;@@ -25,6 +24,7 @@ import java.util.logging.Logger;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.UTF8;import org.apache.nutch.util.NutchConfiguration;@@ -71,7 +71,7 @@ public class TestLinkDbMerger extends TestCase {TreeMap init2 = new TreeMap();HashMap expected = new HashMap();Configuration conf;- File testDir;+ Path testDir;FileSystem fs;LinkDbReader reader;@@ -86,7 +86,7 @@ public class TestLinkDbMerger extends TestCase {expected.put(url21, urls21_expected);conf = NutchConfiguration.create();fs = FileSystem.get(conf);- testDir = new File("test-crawldb-" ++ testDir = new Path("test-crawldb-" +new java.util.Random().nextInt());fs.mkdirs(testDir);}@@ -104,17 +104,17 @@ public class TestLinkDbMerger extends TestCase {public void testMerge() throws Exception {Configuration conf = NutchConfiguration.create();FileSystem fs = FileSystem.get(conf);- File testDir = new File("test-linkdb-" ++ Path testDir = new Path("test-linkdb-" +new java.util.Random().nextInt());fs.mkdirs(testDir);- File linkdb1 = new File(testDir, "linkdb1");- File linkdb2 = new File(testDir, "linkdb2");- File output = new File(testDir, "output");+ Path linkdb1 = new Path(testDir, "linkdb1");+ Path linkdb2 = new Path(testDir, "linkdb2");+ Path output = new Path(testDir, "output");createLinkDb(fs, linkdb1, init1);createLinkDb(fs, linkdb2, init2);LinkDbMerger merger = new LinkDbMerger(conf);LOG.fine("* merging linkdbs to " + output);- merger.merge(output, new File[]{linkdb1, linkdb2}, false);+ merger.merge(output, new Path[]{linkdb1, linkdb2}, false);LOG.fine("* reading linkdb: " + output);reader = new LinkDbReader(fs, output, conf);Iterator it = expected.keySet().iterator();@@ -140,10 +140,10 @@ public class TestLinkDbMerger extends TestCase {fs.delete(testDir);}- private void createLinkDb(FileSystem fs, File linkdb, TreeMap init) throws Exception {+ private void createLinkDb(FileSystem fs, Path linkdb, TreeMap init) throws Exception {LOG.fine("* creating linkdb: " + linkdb);- File dir = new File(linkdb, LinkDb.CURRENT_NAME);- MapFile.Writer writer = new MapFile.Writer(fs, new File(dir, "part-00000").toString(), UTF8.class, Inlinks.class);+ Path dir = new Path(linkdb, LinkDb.CURRENT_NAME);+ MapFile.Writer writer = new MapFile.Writer(fs, new Path(dir, "part-00000").toString(), UTF8.class, Inlinks.class);Iterator it = init.keySet().iterator();while (it.hasNext()) {String key = (String)it.next();diff --git a/src/test/org/apache/nutch/crawl/TestMapWritable.java b/src/test/org/apache/nutch/crawl/TestMapWritable.javaindex 402b4b4f8..8aa0b0c41 100644--- a/src/test/org/apache/nutch/crawl/TestMapWritable.java+++ b/src/test/org/apache/nutch/crawl/TestMapWritable.java@@ -15,12 +15,11 @@*/package org.apache.nutch.crawl;-import java.io.File;-import junit.framework.TestCase;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.DataInputBuffer;import org.apache.hadoop.io.DataOutputBuffer;import org.apache.hadoop.io.IntWritable;@@ -103,11 +102,11 @@ public class TestMapWritable extends TestCase {}public void testPerformance() throws Exception {- File file = new File(System.getProperty("java.io.tmpdir"), "mapTestFile");- file.delete();+ FileSystem fs = FileSystem.get(configuration);+ Path file = new Path(System.getProperty("java.io.tmpdir"), "mapTestFile");+ fs.delete(file);org.apache.hadoop.io.SequenceFile.Writer writer = new SequenceFile.Writer(- FileSystem.get(configuration), file.getAbsolutePath(),- IntWritable.class, MapWritable.class);+ fs, file, IntWritable.class, MapWritable.class);// write mapSystem.out.println("start writing map's");long start = System.currentTimeMillis();@@ -127,7 +126,7 @@ public class TestMapWritable extends TestCase {// read maporg.apache.hadoop.io.SequenceFile.Reader reader = new SequenceFile.Reader(- FileSystem.get(configuration), file.getAbsolutePath(), configuration);+ fs, file, configuration);System.out.println("start reading map's");start = System.currentTimeMillis();while (reader.next(key, map)) {@@ -136,12 +135,11 @@ public class TestMapWritable extends TestCase {reader.close();needed = System.currentTimeMillis() - start;System.out.println("needed time for reading map's: " + needed);- file.delete();+ fs.delete(file);// UTF8System.out.println("start writing utf8's");- writer = new SequenceFile.Writer(FileSystem.get(configuration), file- .getAbsolutePath(), IntWritable.class, UTF8.class);+ writer = new SequenceFile.Writer(fs, file, IntWritable.class, UTF8.class);// write mapstart = System.currentTimeMillis();key = new IntWritable();@@ -158,16 +156,14 @@ public class TestMapWritable extends TestCase {// read mapSystem.out.println("start reading utf8's");- reader = new SequenceFile.Reader(FileSystem.get(configuration), file- .getAbsolutePath(), configuration);+ reader = new SequenceFile.Reader(fs, file, configuration);start = System.currentTimeMillis();while (reader.next(key, value)) {}needed = System.currentTimeMillis() - start;System.out.println("needed time for reading utf8: " + needed);- file.delete();-+ fs.delete(file);}/** Utility method for testing writables, from hadoop code */