本文整理汇总了Java中eu.medsea.mimeutil.MimeException类的典型用法代码示例。如果您正苦于以下问题:Java MimeException类的具体用法?Java MimeException怎么用?Java MimeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MimeException类属于eu.medsea.mimeutil包,在下文中一共展示了MimeException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getMimeType
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private MimeType getMimeType(Set<MimeType> mimeTypes, String path) {
try {
mimeTypes.addAll(mimeUtil.getMimeTypes(path));
} catch (MimeException e) {
log.warn("Unable to determine MIME type from path", e);
}
if (isUnknownType(mimeTypes)) {
return MimeUtil2.UNKNOWN_MIME_TYPE;
}
final List<MimeType> types = new ArrayList<>(mimeTypes);
Collections.sort(
types,
new Comparator<MimeType>() {
@Override
public int compare(MimeType a, MimeType b) {
return getCorrectedMimeSpecificity(b) - getCorrectedMimeSpecificity(a);
}
});
return types.get(0);
}
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:MimeUtilFileTypeRegistry.java
示例2: getFileMimeType
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
private ContentType getFileMimeType(File file){
try {
Collection<MimeType> types = MimeUtil.getMimeTypes(file);
MimeType target = null;
for (MimeType mimeType : types){
if (mimeType.equals(MimeUtil2.UNKNOWN_MIME_TYPE)){
continue;
}
target = mimeType;
}
if (target != null){
return ContentType.create(target.toString());
}
return null;
} catch (MimeException e) {
logger.error(e.getMessage(), e);
return null;
}
}
开发者ID:yamingd,项目名称:argo,代码行数:21,代码来源:RestAPITestRunner.java
示例3: getMimeTypesURL
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
/**
* Defer this call to the InputStream method
*/
public Collection getMimeTypesURL(final URL url) throws UnsupportedOperationException {
InputStream in = null;
try {
return getMimeTypesInputStream(in = new BufferedInputStream(MimeUtil.getInputStreamForURL(url)));
}catch(Exception e) {
throw new MimeException(e);
}finally {
closeStream(in);
}
}
开发者ID:Fivium,项目名称:FOXopen,代码行数:14,代码来源:MagicMimeMimeDetectorFixedFile.java
示例4: getMimeTypesURL
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
/**
* Defer this call to the InputStream method
*/
public Collection<MimeType> getMimeTypesURL(final URL url) throws UnsupportedOperationException {
InputStream in = null;
try {
return getMimeTypesInputStream(in = new BufferedInputStream(MimeUtil.getInputStreamForURL(url)));
}catch(Exception e) {
throw new MimeException(e);
}finally {
closeStream(in);
}
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:14,代码来源:MagicMimeMimeDetector.java
示例5: lookupMimeTypesForMagicData
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
private Collection lookupMimeTypesForMagicData(InputStream in) {
int offset = 0;
int len = getMaxExtents();
byte[] data = new byte[len];
// Mark the input stream
in.mark(len);
try {
// Since an InputStream might return only some data (not all
// requested), we have to read in a loop until
// either EOF is reached or the desired number of bytes have been
// read.
int restBytesToRead = len;
while (restBytesToRead > 0) {
int bytesRead = in.read(data, offset, restBytesToRead);
if (bytesRead < 0)
break; // EOF
offset += bytesRead;
restBytesToRead -= bytesRead;
}
} catch (IOException ioe) {
throw new MimeException(ioe);
} finally {
try {
// Reset the input stream to where it was marked.
in.reset();
} catch (Exception e) {
throw new MimeException(e);
}
}
return lookupMagicData(data);
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:35,代码来源:OpendesktopMimeDetector.java
示例6: getInputStream
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
private InputStream getInputStream(URL url) {
try {
return MimeUtil.getInputStreamForURL(url);
} catch (Exception e) {
throw new MimeException("Error getting InputStream for URL ["
+ url.getPath() + "]", e);
}
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:9,代码来源:OpendesktopMimeDetector.java
示例7: getMimeTypesFile
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
public Collection getMimeTypesFile(File file)
throws UnsupportedOperationException {
try {
return getMimeTypesURL(file.toURI().toURL());
}catch(Exception e) {
throw new MimeException(e);
}
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:9,代码来源:WindowsRegistryMimeDetector.java
示例8: MimeType
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
/**
* Construct a mime type from a String such as <code>text/plain</code>.
* It tries to ensure that the mime type pattern passed in is correctly
* formatted.
*
* @param mimeType
* @throws MimeException
*/
public MimeType(final String mimeType) throws MimeException {
if(mimeType == null || mimeType.trim().length() == 0){
throw new MimeException("Invalid MimeType [" + mimeType + "]");
}
String [] parts = mimeSplitter.split(mimeType.trim());
if(parts.length > 0) {
// Treat as the mediaType
mediaType = getValidMediaType(parts[0]);
} if(parts.length > 1) {
subType = getValidSubType(parts[1]);
}
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:22,代码来源:MimeType.java
示例9: MimeType
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
/**
* Construct a mime type from a String such as <code>text/plain</code>.
* It tries to ensure that the mime type pattern passed in is correctly
* formatted.
*
* @param mimeType
* @throws MimeException
*/
public MimeType(final String mimeType) throws MimeException {
if(mimeType == null || mimeType.trim().length() == 0){
throw new MimeException("Invalid MimeType [" + mimeType + "]");
}
String [] parts = mimeSplitter.split(mimeType.trim());
if(parts.length > 0) {
// Treat as the mediaType
mediaType = getValidMediaType(parts[0]);
} if(parts.length > 1) {
subType = getValidSubType(parts[1]);
}
}
开发者ID:yamingd,项目名称:argo,代码行数:22,代码来源:MimeType.java
示例10: FileExtensionMimeType
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
FileExtensionMimeType(String mimeType) throws MimeException {
super(mimeType);
}
开发者ID:gerrit-review,项目名称:gerrit,代码行数:4,代码来源:DefaultFileExtensionRegistry.java
示例11: _getMimeTypes
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
private Collection _getMimeTypes(Collection mimeTypes, InputStream in) {
try {
if (mimeTypes.isEmpty() || mimeTypes.size() > 1) {
Collection _mimeTypes = getMimeTypesInputStream(in = new BufferedInputStream(
in));
if (!_mimeTypes.isEmpty()) {
if (!mimeTypes.isEmpty()) {
// more than one glob matched
// Check for same mime type
for (Iterator it = mimeTypes.iterator(); it.hasNext();) {
String mimeType = (String) it.next();
if (_mimeTypes.contains(mimeType)) {
// mimeTypes = new ArrayList();
mimeTypes.add(mimeType);
// return mimeTypes;
}
// Check for mime type subtype
for (Iterator _it = _mimeTypes.iterator(); _it
.hasNext();) {
String _mimeType = (String) _it.next();
if (isMimeTypeSubclass(mimeType, _mimeType)) {
// mimeTypes = new ArrayList();
mimeTypes.add(mimeType);
// return mimeTypes;
}
}
}
} else {
// No globs matched but we have magic matches
return _mimeTypes;
}
}
}
} catch (Exception e) {
throw new MimeException(e);
} finally {
closeStream(in);
}
return mimeTypes;
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:45,代码来源:OpendesktopMimeDetector.java
示例12: getMimeTypesFile
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
/**
* Get the mime type of a file using extension mappings. The file path
* can be a relative or absolute path or can refer to a completely non-existent file as
* only the extension is important here.
*
* @param file points to a file or directory. May not actually exist
* @return collection of the matched mime types.
* @throws MimeException if errors occur.
*/
public Collection getMimeTypesFile(final File file) throws MimeException {
return getMimeTypesFileName(file.getName());
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:13,代码来源:ExtensionMimeDetector.java
示例13: getMimeTypesURL
import eu.medsea.mimeutil.MimeException; //导入依赖的package包/类
/**
* Get the mime type of a URL using extension mappings. Only the extension is important here.
*
* @param url is a valid URL
* @return collection of the matched mime types.
* @throws MimeException if errors occur.
*/
public Collection getMimeTypesURL(final URL url) throws MimeException {
return getMimeTypesFileName(url.getPath());
}
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:11,代码来源:ExtensionMimeDetector.java
注:本文中的eu.medsea.mimeutil.MimeException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论