当前位置: 首页>>代码示例>>Java>>正文


Java MimeType类代码示例

本文整理汇总了Java中eu.medsea.mimeutil.MimeType的典型用法代码示例。如果您正苦于以下问题:Java MimeType类的具体用法?Java MimeType怎么用?Java MimeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MimeType类属于eu.medsea.mimeutil包,在下文中一共展示了MimeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMimeTypesFileName

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
@Override
protected Collection<MimeType> getMimeTypesFileName(String name) {
  int s = name.lastIndexOf('/');
  if (s >= 0) {
    name = name.substring(s + 1);
  }

  MimeType type = TYPES.get(name);
  if (type != null) {
    return Collections.singletonList(type);
  }

  int d = name.lastIndexOf('.');
  if (0 < d) {
    type = TYPES.get(name.substring(d + 1));
    if (type != null) {
      return Collections.singletonList(type);
    }
  }

  return Collections.emptyList();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:DefaultFileExtensionRegistry.java

示例2: getCorrectedMimeSpecificity

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
/**
 * Get specificity of mime types with generic types forced to low values
 *
 * <p>"application/octet-stream" is forced to -1. "text/plain" is forced to 0. All other mime
 * types return the specificity reported by mimeType itself.
 *
 * @param mimeType The mimeType to get the corrected specificity for.
 * @return The corrected specificity.
 */
private int getCorrectedMimeSpecificity(MimeType mimeType) {
  // Although the documentation of MimeType's getSpecificity claims that for
  // example "application/octet-stream" always has a specificity of 0, it
  // effectively returns 1 for us. This causes problems when trying to get
  // the correct mime type via sorting. For example in
  // [application/octet-stream, image/x-icon] both mime types come with
  // specificity 1 for us. Hence, getMimeType below may end up using
  // application/octet-stream instead of the more specific image/x-icon.
  // Therefore, we have to force the specificity of generic types below the
  // default of 1.
  //
  final String mimeTypeStr = mimeType.toString();
  if (mimeTypeStr.equals("application/octet-stream")) {
    return -1;
  }
  if (mimeTypeStr.equals("text/plain")) {
    return 0;
  }
  return mimeType.getSpecificity();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:30,代码来源:MimeUtilFileTypeRegistry.java

示例3: getMimeType

import eu.medsea.mimeutil.MimeType; //导入依赖的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

示例4: getMimeTypesByteArray

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
/**
 * Get the mime types that may be contained in the data array.
 *
 * @param data. The byte array that contains data we want to detect mime types from.
 * @return the mime types.
 * @throws MimeException if for instance we try to match beyond the end of the data.
 */
public Collection<MimeType> getMimeTypesByteArray(final byte[] data)
		throws UnsupportedOperationException {
	Collection<MimeType> mimeTypes = new LinkedHashSet<MimeType>();
	int len = mMagicMimeEntries.size();
	try {
		for (int i = 0; i < len; i++) {
			MagicMimeEntry me = (MagicMimeEntry) mMagicMimeEntries.get(i);
			MagicMimeEntry matchingMagicMimeEntry = me.getMatch(data);
			if (matchingMagicMimeEntry != null) {
				mimeTypes.add(matchingMagicMimeEntry.getMimeType());
			}
		}
	} catch (Exception e) {
		AppState.log(TAG, e.getMessage());
	}
	return mimeTypes;
}
 
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:25,代码来源:MagicMimeMimeDetector.java

示例5: getMimeTypesInputStream

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
/**
 * Get the mime types of the data in the specified {@link InputStream}.
 * Therefore, the <code>InputStream</code> must support mark and reset (see
 * {@link InputStream#markSupported()}). If it does not support mark and
 * reset, an {@link MimeException} is thrown.
 *
 * @param in
 *            the stream from which to read the data.
 * @return the mime types.
 * @throws MimeException
 *             if the specified <code>InputStream</code> does not support
 *             mark and reset (see {@link InputStream#markSupported()}).
 */
public Collection<MimeType> getMimeTypesInputStream(final InputStream in)
		throws UnsupportedOperationException {
	AppState.logX(TAG, String.format("getMimeTypesInputStream: mMagicMimeEntries.size = %d",
		mMagicMimeEntries));

	Collection<MimeType> mimeTypes = new LinkedHashSet<MimeType>();
	int len = mMagicMimeEntries.size();
	try {
		for (int i = 0; i < len; i++) {
			MagicMimeEntry me = (MagicMimeEntry) mMagicMimeEntries.get(i);
			MagicMimeEntry matchingMagicMimeEntry = me.getMatch(in);
			if (matchingMagicMimeEntry != null) {
				mimeTypes.add(matchingMagicMimeEntry.getMimeType());
			}
		}
	} catch (Exception e) {
		AppState.log(TAG, e.getMessage());
	}
	return mimeTypes;
}
 
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:34,代码来源:MagicMimeMimeDetector.java

示例6: getFileMimeType

import eu.medsea.mimeutil.MimeType; //导入依赖的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

示例7: isSafeInline

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
@Override
public boolean isSafeInline(MimeType type) {
  if (MimeUtil2.UNKNOWN_MIME_TYPE.equals(type)) {
    // Most browsers perform content type sniffing when they get told
    // a generic content type. This is bad, so assume we cannot send
    // the file inline.
    //
    return false;
  }

  final boolean any = isSafe(cfg, "*/*", false);
  final boolean genericMedia = isSafe(cfg, type.getMediaType() + "/*", any);
  return isSafe(cfg, type.toString(), genericMedia);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:15,代码来源:MimeUtilFileTypeRegistry.java

示例8: wrapBlob

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
private BinaryResult wrapBlob(
    String path,
    final ObjectLoader obj,
    byte[] raw,
    MimeType contentType,
    @Nullable String suffix) {
  return asBinaryResult(raw, obj)
      .setContentType(contentType.toString())
      .setAttachmentName(safeFileName(path, suffix));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:11,代码来源:FileContentUtil.java

示例9: getMimeTypesURL

import eu.medsea.mimeutil.MimeType; //导入依赖的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

示例10: getMimeTypesURL

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
public Collection getMimeTypesURL(URL url)
		throws UnsupportedOperationException {
	Collection mimeTypes = new ArrayList();
	if(!isWindows) {
		return mimeTypes;
	}

	String contentType = getContentType(MimeUtil.getExtension(url.getPath()));
	if(contentType != null && contentType.length() > 0) {
		mimeTypes.add(new MimeType(contentType));
	}
	return mimeTypes;
}
 
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:14,代码来源:WindowsRegistryMimeDetector.java

示例11: getMatch

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
MagicMimeEntry getMatch(byte[] content) throws IOException {
	ByteBuffer buf = readBuffer(content);
	if (buf == null)
		return null;

	buf.position(0);
	boolean matches = match(buf);
	if (matches) {
		int subLen = subEntries.size();
		MimeType mimeType = getMimeType();
		if (subLen > 0) {
			for (int k = 0; k < subLen; k++) {
				MagicMimeEntry me = (MagicMimeEntry) subEntries.get(k);
				MagicMimeEntry matchingEntry = me.getMatch(content);
				if (matchingEntry != null) {
					return matchingEntry;
				}
			}
			if (mimeType != null) {
				return this;
			}
		} else {
			if (mimeType != null)
				return this;
		}
	}

	return null;
}
 
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:30,代码来源:MagicMimeEntry.java

示例12: mimeTypeGet2

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
public static String mimeTypeGet2(Context context, String filename) {
	AppState.logX(TAG, String.format("mimeTypeGet2: filename = %s", filename));

	MimeType mimeType = UNKNOWN_MIME_TYPE;
	AppState.logX(TAG, "mimeTypeGet2: 1");
	File file = new File(filename);
	AppState.logX(TAG, "mimeTypeGet2: 2");
	if (file.isDirectory()) {
		AppState.logX(TAG, "mimeTypeGet2: 3");
		mimeType = MimeUtil2.DIRECTORY_MIME_TYPE;
		AppState.logX(TAG, "mimeTypeGet2: 4");
	} else {
		AppState.logX(TAG, "mimeTypeGet2: 5");
		MagicMimeMimeDetector detector = new MagicMimeMimeDetector(context);
		AppState.logX(TAG, "mimeTypeGet2: 6");
		Collection<MimeType> mimeTypes = new ArrayList<MimeType>();
		AppState.logX(TAG, "mimeTypeGet2: 7");
		mimeTypes.addAll(detector.getMimeTypesFileName(filename));
		AppState.logX(TAG, String.format("mimeTypeGet2: 8: mimeType.size = %d", mimeTypes.size()));
		mimeTypes.remove(UNKNOWN_MIME_TYPE);
		AppState.logX(TAG, "mimeTypeGet2: 9");
		mimeType = MimeUtil2.getMostSpecificMimeType(mimeTypes);
		AppState.logX(TAG, "mimeTypeGet2: 10");
	}

	AppState.logX(TAG, String.format("mimeTypeGet2: mimeType = %s", mimeType != null ? mimeType.toString() :
		"null"));

	return mimeType != null ? mimeType.toString() : context.getString(R.string.mime_file_text);
}
 
开发者ID:nfsclient-speedops,项目名称:NfsClient,代码行数:31,代码来源:Utils.java

示例13: validateContent

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
/**
 * Validates the content of a File Upload against this definition. Content length and type is determined and validated.
 * The UploadInfo object is updated with the determined Content Type.
 * @param pUploadInfo File Upload to be validated
 * @param pFirstPacket Variable length byte array containing the first n bytes of the file. This is used for magic MIME detection/
 * @throws ExUploadValidation If validation fails. The thrown exception will contain a more detailed reason for the
 * validation failure.
 */
public void validateContent(UploadInfo pUploadInfo, byte[] pFirstPacket)
throws ExUploadValidation {

  //Size Validation
  validateSize(pUploadInfo.getHttpContentLength());

  //Content type validation
  String lExtension = pUploadInfo.getFilename().indexOf('.') != -1 ? pUploadInfo.getFilename().substring(pUploadInfo.getFilename().lastIndexOf('.')+1) : "";
  /*
   * Magic MIME type check
   *
   * The first UploadWorkItem.BYTE_READ_QUANTITY bytes of an upload are passed to
   * the mimeutil MIME type detector (See http://sourceforge.net/projects/mime-util)
   * The magic.mime file syntax specifies fixed addresses of bytes in the file to
   * inspect, so we know that we have passed  enough of the file for the detection
   * to work. Note the custom implementation of the MagicMimeDetector - this overloads
   * the behaviour of the supplied class, which looks at various filesystem/environment
   * variable locations to find magic.mime files.
   *
   */
  Collection lMimeTypes = new MimeUtil().getMimeTypes(pFirstPacket);

  Set<String> lMimeTypeStrings = new HashSet<>();

  //log MIME type data
  for(Iterator it = lMimeTypes.iterator(); it.hasNext();){
    MimeType lMimeType = (MimeType) it.next();
    if(lMimeType != null) {
      pUploadInfo.addMagicContentType(lMimeType.toString());
      lMimeTypeStrings.add(lMimeType.toString());
    }
  }

  try {
    String lMime = getAndValidateMimeType(lExtension, pUploadInfo.getBrowserContentType(), lMimeTypeStrings);
    pUploadInfo.setTrueContentType(lMime);
  }
  catch (ExUploadValidation ex) {
    pUploadInfo.setTrueContentType(ex.getMimeType());
    throw ex;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:51,代码来源:FileUploadType.java

示例14: getMimeTypesFile

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
@Override
protected Collection<MimeType> getMimeTypesFile(File file) {
  return getMimeTypesFileName(file.getName());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:5,代码来源:DefaultFileExtensionRegistry.java

示例15: getMimeTypesURL

import eu.medsea.mimeutil.MimeType; //导入依赖的package包/类
@Override
protected Collection<MimeType> getMimeTypesURL(URL url) {
  return getMimeTypesFileName(url.getPath());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:5,代码来源:DefaultFileExtensionRegistry.java


注:本文中的eu.medsea.mimeutil.MimeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。