Apache Nutch is an extensible and scalable web crawler
Fix for NUTCH-1954: FilenameTooLong error appears in CommonCrawlDumper.
Chris Mattmann963bd1ee7a0f
diff --git a/CHANGES.txt b/CHANGES.txtindex 4e8dbaf37..e66fb184c 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogNutch Current Development 1.10-SNAPSHOT+* NUTCH-1954 FilenameTooLong error appears in CommonCrawlDumper (mattmann)+* NUTCH-1949 Dump out the Nutch data into the Common Crawl format (Giuseppe Totaro via lewismc)* NUTCH-1950 File name too long (Jiaheng Zhang, Chong Li via mattmann)diff --git a/src/java/org/apache/nutch/tools/CommonCrawlDataDumper.java b/src/java/org/apache/nutch/tools/CommonCrawlDataDumper.javaindex 4e36f00e5..33f0b4b2d 100644--- a/src/java/org/apache/nutch/tools/CommonCrawlDataDumper.java+++ b/src/java/org/apache/nutch/tools/CommonCrawlDataDumper.java@@ -30,6 +30,7 @@ import java.util.Arrays;import java.util.Date;import java.util.HashMap;import java.util.Map;+import java.security.MessageDigest;import org.apache.commons.cli.CommandLine;import org.apache.commons.cli.CommandLineParser;@@ -369,7 +370,22 @@ public class CommonCrawlDataDumper {}else {LOG.info("Writing: [" + outputFullPath + "]");- IOUtils.copy(new ByteArrayInputStream(byteData), new FileOutputStream(outputFile));+ try{+ IOUtils.copy(new ByteArrayInputStream(byteData), new FileOutputStream(outputFile));+ }+ catch (Exception e){+ MessageDigest md = MessageDigest.getInstance("MD5");+ md.update(outputFullPath.getBytes());+ byte[] digest = md.digest();+ StringBuffer sb = new StringBuffer();+ for (byte b : digest) {+ sb.append(String.format("%02x", b & 0xff));+ }+ outputFullPath = outputFullPath.substring(0, 32) + "_" + sb.toString();+ File newOutPutFile = new File(outputFullPath);+ IOUtils.copy(new ByteArrayInputStream(byteData), new FileOutputStream(newOutPutFile));+ LOG.info("File name is too long. Truncated and MD5 appended.");+ }}}else {