@Test public void guess_html_format_fail() throws Exception { String fileName = "foo.html"; Format actual = htmlDetector.detect(this.getClass().getResourceAsStream(fileName)); assertNull(actual); }
@Override public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException { if (inputStream == null) { return null; } else { inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE); byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE]; int n = 0; for (int m = inputStream.read(buffer); m != -1 && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) { n += m; } inputStream.reset(); String head = FormatUtils.readFromBuffer(buffer, 0, n); try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) { Charset charset = htmlEncodingDetector.detect(stream, metadata); if (charset != null) { return new Format(htmlFormatFamily, charset.name()); } } return null; } }
HtmlDetector implements Detector { @Override public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException { if (inputStream == null) { return null; } else { inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE); byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE]; int n = 0; for (int m = inputStream.read(buffer); m != -1 && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) { n += m; } inputStream.reset(); String head = FormatUtils.readFromBuffer(buffer, 0, n); try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) { Charset charset = htmlEncodingDetector.detect(stream, metadata); if (charset != null) { return new Format(htmlFormatFamily, charset.name()); } } return null; } } }
HtmlDetector implements Detector { @Override public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException { if (inputStream == null) { return null; } else { inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE); byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE]; int n = 0; for (int m = inputStream.read(buffer); m != -1 && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) { n += m; } inputStream.reset(); String head = FormatUtils.readFromBuffer(buffer, 0, n); try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) { Charset charset = htmlEncodingDetector.detect(stream, metadata); if (charset != null) { return new Format(htmlFormatFamily, charset.name()); } } return null; } }  }
HtmlDetector implements Detector { @Override public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException { if (inputStream == null) { return null; } else { inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE); byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE]; int n = 0; for (int m = inputStream.read(buffer); m != -1 && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) { n += m; } inputStream.reset(); String head = FormatUtils.readFromBuffer(buffer, 0, n); try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) { Charset charset = htmlEncodingDetector.detect(stream, metadata); if (charset != null) { return new Format(htmlFormatFamily, charset.name()); } } return null; } }  @Override Format detect(Metadata metadata, TikaInputStream inputStream); }
HtmlDetector implements Detector { @Override public Format detect(Metadata metadata, TikaInputStream inputStream) throws IOException { if (inputStream == null) { return null; } else { inputStream.mark(FormatUtils.META_TAG_BUFFER_SIZE); byte[] buffer = new byte[FormatUtils.META_TAG_BUFFER_SIZE]; int n = 0; for (int m = inputStream.read(buffer); m != -1 && n < buffer.length; m = inputStream.read(buffer, n, buffer.length - n)) { n += m; } inputStream.reset(); String head = FormatUtils.readFromBuffer(buffer, 0, n); try (InputStream stream = TikaInputStream.get(IOUtils.toInputStream(head))) { Charset charset = htmlEncodingDetector.detect(stream, metadata); if (charset != null) { return new Format(htmlFormatFamily, charset.name()); } } return null; } }  @Override Format detect(Metadata metadata, TikaInputStream inputStream);  }