我在Linux中安装了CIFS共享。我正在抓取文件的元数据并阅读内容,如下面的代码示例所示。在抓取大约十万个文件后,它开始抛出异常:java.io.IOException: Host is down
1.if (Files.isReadable(p)) {
2. //checks here if the file is readable so the metadata can be populated without throwing exceptions.
3. BasicFileAttributes attr = Files.readAttributes(p, BasicFileAttributes.class);
4. metadata.setCreated(new DateTime(attr.creationTime().toString()));
5. metadata.setOriginalSize(attr.size());
6. metadata.setLastModified(new DateTime(attr.lastModifiedTime().toString()));
7. metadata.setMimeType(MimeTypeUtil.getContentType(p));
8. if(Files.getOwner(p) != null) {
9. metadata.setOwner(Files.getOwner(p).getName());
10 }
11.}
当我们尝试在上面的代码中获取行号:7的mime-type时,它会抛出异常。
public class MimeTypeUtil {
private static final Tika tika = new Tika();
public static String getContentType(Path path) {
try {
return tika.detect(path.toFile());
} catch (IOException e) {
throw e;
}
}
}
例外:
! java.io.IOException: Host is down
! at java.io.FileInputStream.readBytes(Native Method) ~[na:1.7.0_65]
! at java.io.FileInputStream.read(FileInputStream.java:272) ~[na:1.7.0_65]
! at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) ~[na:1.7.0_65]
! at java.io.BufferedInputStream.read(BufferedInputStream.java:254) ~[na:1.7.0_65]
! at org.apache.tika.io.ProxyInputStream.read(ProxyInputStream.java:59) ~[tika-core-1.5.jar:na]
! Causing: org.apache.tika.io.TaggedIOException: Host is down
! at org.apache.tika.io.TaggedInputStream.handleIOException(TaggedInputStream.java:133) ~[tika-core-1.5.jar:na]
! at org.apache.tika.io.ProxyInputStream.read(ProxyInputStream.java:63) ~[tika-core-1.5.jar:na]
! at org.gagravarr.tika.OggDetector.detect(OggDetector.java:52) ~[vorbis-java-tika-0.1.jar:na]
! at org.apache.tika.detect.CompositeDetector.detect(CompositeDetector.java:61) ~[tika-core-1.5.jar:na]
! at org.apache.tika.Tika.detect(Tika.java:133) ~[tika-core-1.5.jar:na]
! at org.apache.tika.Tika.detect(Tika.java:267) ~[tika-core-1.5.jar:na]
! at org.apache.tika.Tika.detect(Tika.java:248) ~[tika-core-1.5.jar:na]
! at org.abc.xyz.util.MimeTypeUtil.getContentType(MimeTypeUtil.java:19) ~[abc2-xyz-2.3.0.jar:na]
当我们要从Linux文件系统中挂载的CIFS共享文件中获取输入字节时,我也遇到了同样的异常。请帮我确定异常的原因。