本文整理匯總了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;
}
}
示例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;
}
}
示例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;
}
}
示例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
}
}
}
示例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;
}
}
示例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();
}
示例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);
}
}