public MediaType detect(InputStream input, Metadata metadata) throws IOException { // Check if we have access to the document if (input == null) { return MediaType.OCTET_STREAM; } TemporaryResources tmp = new TemporaryResources(); try { TikaInputStream tis = TikaInputStream.get(input, tmp); byte[] prefix = new byte[1024]; // enough for all known formats int length = tis.peek(prefix); MediaType type = detectArchiveFormat(prefix, length); if (type == TIFF) { return TIFF; } else if (PackageParser.isZipArchive(type) && TikaInputStream.isTikaInputStream(input)) { return detectZipFormat(tis); } else if (!type.equals(MediaType.OCTET_STREAM)) { return type; } else { return detectCompressorFormat(prefix, length); } } finally { try { tmp.dispose(); } catch (TikaException e) { // ignore } } }
public MediaType detect(InputStream input, Metadata metadata) throws IOException { // Check if we have access to the document if (input == null) { return MediaType.OCTET_STREAM; } TemporaryResources tmp = new TemporaryResources(); try { TikaInputStream tis = TikaInputStream.get(input, tmp); byte[] prefix = new byte[1024]; // enough for all known formats int length = tis.peek(prefix); MediaType type = detectArchiveFormat(prefix, length); if (type == TIFF) { return TIFF; } else if (PackageParser.isZipArchive(type) && TikaInputStream.isTikaInputStream(input)) { return detectZipFormat(tis); } else if (!type.equals(MediaType.OCTET_STREAM)) { return type; } else { return detectCompressorFormat(prefix, length); } } finally { try { tmp.dispose(); } catch (TikaException e) { // ignore } } }
public MediaType detect(InputStream input, Metadata metadata) throws IOException { // Check if we have access to the document if (input == null) { return MediaType.OCTET_STREAM; } TemporaryResources tmp = new TemporaryResources(); try { TikaInputStream tis = TikaInputStream.get(input, tmp); byte[] prefix = new byte[1024]; // enough for all known formats int length = tis.peek(prefix); MediaType type = detectArchiveFormat(prefix, length); if (PackageParser.isZipArchive(type) && TikaInputStream.isTikaInputStream(input)) { return detectZipFormat(tis); } else if (!type.equals(MediaType.OCTET_STREAM)) { return type; } else { return detectCompressorFormat(prefix, length); } } finally { try { tmp.dispose(); } catch (TikaException e) { // ignore } } }