當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaType.OCTET_STREAM屬性代碼示例

本文整理匯總了Java中org.apache.tika.mime.MediaType.OCTET_STREAM屬性的典型用法代碼示例。如果您正苦於以下問題:Java MediaType.OCTET_STREAM屬性的具體用法?Java MediaType.OCTET_STREAM怎麽用?Java MediaType.OCTET_STREAM使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.tika.mime.MediaType的用法示例。


在下文中一共展示了MediaType.OCTET_STREAM屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMediaType

static MediaType getMediaType(ArchiveInputStream stream) {
    if (stream instanceof JarArchiveInputStream) {
        return JAR;
    } else if (stream instanceof ZipArchiveInputStream) {
        return ZIP;
    } else if (stream instanceof ArArchiveInputStream) {
        return AR;
    } else if (stream instanceof CpioArchiveInputStream) {
        return CPIO;
    } else if (stream instanceof DumpArchiveInputStream) {
        return DUMP;
    } else if (stream instanceof TarArchiveInputStream) {
        return TAR;
    } else {
        return MediaType.OCTET_STREAM;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:17,代碼來源:PackageParser.java

示例2: detectArchiveFormat

private static MediaType detectArchiveFormat(byte[] prefix, int length) {
    try {
        ArchiveStreamFactory factory = new ArchiveStreamFactory();
        ArchiveInputStream ais = factory.createArchiveInputStream(
                new ByteArrayInputStream(prefix, 0, length));
        try {
            if ((ais instanceof TarArchiveInputStream)
                    && !TarArchiveInputStream.matches(prefix, length)) {
                // ArchiveStreamFactory is too relaxed, see COMPRESS-117
                return MediaType.OCTET_STREAM;
            } else {
                return PackageParser.getMediaType(ais);
            }
        } finally {
            IOUtils.closeQuietly(ais);
        }
    } catch (ArchiveException e) {
        return MediaType.OCTET_STREAM;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:20,代碼來源:ZipContainerDetector.java

示例3: getMediaType

static MediaType getMediaType(CompressorInputStream stream) {
    if (stream instanceof BZip2CompressorInputStream) {
        return BZIP2;
    } else if (stream instanceof GzipCompressorInputStream) {
        return GZIP;
    } else if (stream instanceof XZCompressorInputStream) {
        return XZ;
    } else if (stream instanceof Pack200CompressorInputStream) {
        return PACK;
    } else {
        return MediaType.OCTET_STREAM;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:13,代碼來源:CompressorParser.java

示例4: detect

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
        }
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:31,代碼來源:ZipContainerDetector.java

示例5: detectCompressorFormat

private static MediaType detectCompressorFormat(byte[] prefix, int length) {
    try {
        CompressorStreamFactory factory = new CompressorStreamFactory();
        CompressorInputStream cis = factory.createCompressorInputStream(
                new ByteArrayInputStream(prefix, 0, length));
        try {
            return CompressorParser.getMediaType(cis);
        } finally {
            IOUtils.closeQuietly(cis);
        }
    } catch (CompressorException e) {
        return MediaType.OCTET_STREAM;
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:14,代碼來源:ZipContainerDetector.java

示例6: getMimeType

/**
 * Get the Mime type of an Asset based on its type. If the Asset already has the "content-type" property set, we
 * return that. Otherwise the Apache Tika library is used to do file type detection.
 *
 * @return A string representation of the content type suitable for use in an HTTP header. Eg. "image/jpeg" for a
 * jpeg
 *         image.
 */
public <T> String getMimeType( Entity entity, T type ) {

    Map<String, Object> fileMetadata = AssetUtils.getFileMetadata( entity );
    if ( fileMetadata.get( AssetUtils.CONTENT_TYPE ) != null ) {
        return ( String ) fileMetadata.get( AssetUtils.CONTENT_TYPE );
    }

    Metadata metadata = new Metadata();
    MediaType mediaType = MediaType.OCTET_STREAM;
    try {
        if ( type instanceof byte[] ) {

            ByteArrayInputStream bais = new ByteArrayInputStream( ( byte[] ) type );
            mediaType = detector.detect( bais, metadata );
        }
        else if ( type instanceof File ) {

            InputStream fis = new BufferedInputStream( new FileInputStream( ( File ) type ) );
            try {
                mediaType = detector.detect( fis, metadata );
            }
            finally {
                fis.close();
            }
        }
        else {
            return mediaType.toString();
        }

        fileMetadata.put( AssetUtils.CONTENT_TYPE, mediaType.toString() );
    }
    catch ( IOException e ) {
        logger.error( "error detecting mime type", e );
    }

    return mediaType.toString();
}
 
開發者ID:apache,項目名稱:usergrid,代碼行數:45,代碼來源:AssetMimeHandler.java

示例7: detect

public MediaType detect(InputStream input, Metadata metadata)
         throws IOException {
    // Check if we have access to the document
    if (input == null) {
        return MediaType.OCTET_STREAM;
    }

    // If this is a TikaInputStream wrapping an already
    // parsed NPOIFileSystem/DirectoryNode, just get the
    // names from the root:
    TikaInputStream tis = TikaInputStream.cast(input);
    Set<String> names = null;
    if (tis != null) {
        Object container = tis.getOpenContainer();
        if (container instanceof NPOIFSFileSystem) {
            names = getTopLevelNames(((NPOIFSFileSystem) container).getRoot());
        } else if (container instanceof DirectoryNode) {
            names = getTopLevelNames((DirectoryNode) container);
        }
    }

    if (names == null) {
        // Check if the document starts with the OLE header
        input.mark(8);
        try {
            if (input.read() != 0xd0 || input.read() != 0xcf
                || input.read() != 0x11 || input.read() != 0xe0
                || input.read() != 0xa1 || input.read() != 0xb1
                || input.read() != 0x1a || input.read() != 0xe1) {
                return MediaType.OCTET_STREAM;
            }
        } finally {
            input.reset();
        }
    }

    // We can only detect the exact type when given a TikaInputStream
    if (names == null && tis != null) {
        // Look for known top level entry names to detect the document type
        names = getTopLevelNames(tis);
    }
    
    // Detect based on the names (as available)
    if (tis != null && 
        tis.getOpenContainer() != null && 
        tis.getOpenContainer() instanceof NPOIFSFileSystem) {
        return detect(names, ((NPOIFSFileSystem)tis.getOpenContainer()).getRoot());
    } else {
        return detect(names, null);
    }
}
 
開發者ID:kolbasa,項目名稱:OCRaptor,代碼行數:51,代碼來源:POIFSContainerDetector.java


注:本文中的org.apache.tika.mime.MediaType.OCTET_STREAM屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。