private static void benchmark(File file) throws Exception { if (file.isHidden()) { // ignore } else if (file.isFile()) { try (InputStream input = new FileInputStream(file)) { byte[] content = IOUtils.toByteArray(input); String type = tika.detect(new ByteArrayInputStream(content)); long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { tika.detect(new ByteArrayInputStream(content)); } System.out.printf( Locale.ROOT, "%6dns per Tika.detect(%s) = %s%n", System.currentTimeMillis() - start, file, type); } } else if (file.isDirectory()) { for (File child : file.listFiles()) { benchmark(child); } } }
@Test public void testDetectApplicationEnviHdr() throws Exception { InputStream iStream = MagicDetectorTest.class.getResourceAsStream( "/test-documents/ang20150420t182050_corr_v1e_img.hdr"); byte[] data = IOUtils.toByteArray(iStream); MediaType testMT = new MediaType("application", "envi.hdr"); Detector detector = new MagicDetector(testMT, data, null, false, 0, 0); // Deliberately prevent InputStream.read(...) from reading the entire // buffer in one go InputStream stream = new RestrictiveInputStream(data); assertEquals(testMT, detector.detect(stream, new Metadata())); }
@Override public byte[] getResponseBodyAsBytes() throws IOException { if (bodyBytes == null) { bodyBytes = IOUtils.toByteArray(bodyStream); bodyStream.close(); // Build a new stream version in case they also want that bodyStream = new ByteArrayInputStream(bodyBytes); } return bodyBytes; }
@Override public byte[] getResponseBodyAsBytes() throws IOException { if (bodyBytes == null) { bodyBytes = IOUtils.toByteArray(bodyStream); bodyStream.close(); // Build a new stream version in case they also want that bodyStream = new ByteArrayInputStream(bodyBytes); } return bodyBytes; }
private static Optional<String> readResource(final ClassLoader classLoader, final String resourceName) { try (InputStream is = classLoader.getResourceAsStream(resourceName)) { if (Objects.isNull(is)) { return Optional.empty(); } final byte[] bytes = IOUtils.toByteArray(is); return Optional.of(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { LOGGER.warn("Unable to process description resource file", e); } return Optional.empty(); }
/** * @see org.opencms.search.I_CmsSearchDocument#getContentBlob() */ public byte[] getContentBlob() { IndexableField fieldContentBlob = m_doc.getField(CmsSearchField.FIELD_CONTENT_BLOB); if (fieldContentBlob != null) { try { if (fieldContentBlob.readerValue() != null) { return IOUtils.toByteArray(fieldContentBlob.readerValue()); } } catch (IOException e) { // TODO: } } return null; }
byte[] content = IOUtils.toByteArray(fis); long stopTime = System.currentTimeMillis(); long totalReadTime = Math.max(1, stopTime - startTime);