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


Java MimetypesFileTypeMap.getDefaultFileTypeMap方法代碼示例

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


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

示例1: parsingClassPath

import javax.activation.MimetypesFileTypeMap; //導入方法依賴的package包/類
/**
 * classPath의 정보를 파싱하여 데이터셋으로 반환
 *
 * @작성자 : KYJ
 * @작성일 : 2015. 10. 26.
 * @param filePathName
 * @return
 * @throws Exception
 */
public static ClassPath parsingClassPath(String filePathName) throws Exception {

	DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
	DocumentBuilder builder = newInstance.newDocumentBuilder();

	{
		FileTypeMap defaultFileTypeMap = MimetypesFileTypeMap.getDefaultFileTypeMap();
		String contentType = defaultFileTypeMap.getContentType(filePathName);
		LOGGER.debug(String.format("File path Name : %s Content type : %s ", filePathName, contentType));
	}

	Reader reader = new InputStreamReader(new FileInputStream(new File(filePathName)), ENCODING);
	InputSource is = new InputSource(reader);

	Document parse = builder.parse(is);

	ClassPath classPath = new ClassPath();
	classPath.setFilePathName(filePathName);
	classPath.setApplyedEncoding(ENCODING);

	NodeList elementsByTagName2 = parse.getElementsByTagName("classpath");
	int length = elementsByTagName2.getLength();
	for (int i = 0; i < length; i++) {
		Node classPathNode = elementsByTagName2.item(i);
		NodeList childNodes = classPathNode.getChildNodes();
		int classEntrySize = childNodes.getLength();
		for (int e = 0; e < classEntrySize; e++) {
			Node classEntryNode = childNodes.item(e);
			NamedNodeMap attributes = classEntryNode.getAttributes();
			if (attributes == null)
				continue;

			// 코드에서 필요로하는 부분만 XML을 파싱해서 데이터셋에 담는다.
			String kind = emptyThan(attributes.getNamedItem("kind"));
			String output = emptyThan(attributes.getNamedItem("output"));
			String path = emptyThan(attributes.getNamedItem("path"));

			ClassPathEntry classPathEntry = new ClassPathEntry(kind, output, path);
			classPath.addEntry(classPathEntry);
		}
	}
	return classPath;
}
 
開發者ID:callakrsos,項目名稱:Gargoyle,代碼行數:53,代碼來源:DynamicClassLoader.java

示例2: getFile

import javax.activation.MimetypesFileTypeMap; //導入方法依賴的package包/類
private void getFile(String auth, String nameOnServer, String filename, String location, boolean download, HttpServletResponse response) {
	try {	
		byte[] bytes = null;
		FileTypeMap fileType = MimetypesFileTypeMap.getDefaultFileTypeMap();
		if (evidenceFiles.containsKey(location) && evidenceFiles.get(location) != null) {
			Set<EvidenceFile> files = evidenceFiles.get(location);
			for (EvidenceFile file:files) {
				if (file.getFilename().equals(nameOnServer)) {
					bytes = new byte[file.getContent().size()];
					for (int i=0; i<file.getContent().size(); i++) {
						bytes[i] = file.getContent().get(i);
					}
				}
			}
		}
		if (bytes == null) {
			location = URLEncoder.encode(location, "UTF-8");
			String filenameEnc = URLEncoder.encode(nameOnServer, "UTF-8");	
			String urlString = fileServiceURL + location + "/" + filenameEnc;
			URL url = new URL(urlString);				
			HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
			httpCon.setDoInput(true);
			httpCon.setDoOutput(true);
			httpCon.setRequestMethod("GET");
			httpCon.setRequestProperty("Content-type", fileType.getContentType(filename));
			httpCon.setRequestProperty("Authorization", "Basic " + auth);				
			httpCon.connect();
			if (httpCon.getResponseCode() != 200) {
				httpCon.disconnect();
				response.sendError(404);
				response.flushBuffer();
				return;
			}
			httpCon.getResponseMessage();
			
			InputStream in = httpCon.getInputStream();
			byte[] b = new byte[512];
			List<Byte> bytesList = new ArrayList<Byte>();
			int read = -1;
			while ((read = in.read(b, 0, 512)) != -1) {
				for (int i=0; i<read; i++) {
					bytesList.add(b[i]);
				}
			}
			bytes = new byte[bytesList.size()];
			for (int i=0; i<bytesList.size(); i++) {
				bytes[i] = bytesList.get(i);
			}
			in.close();
		}
		
		if (!download) {
			String base = Base64Utils.toBase64(bytes);
			bytes = base.getBytes();
		}
		response.setContentType(fileType.getContentType(filename));
		response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
		OutputStream out = response.getOutputStream();
		out.write(bytes);
		out.close();
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:MirrorIP,項目名稱:activity-recommendation-app,代碼行數:66,代碼來源:ARAppServiceImpl.java

示例3: getContentType

import javax.activation.MimetypesFileTypeMap; //導入方法依賴的package包/類
/**
 * Returns the mime type of the given file.
 * @param filePath the file path and name
 * @return String
 */
public static final String getContentType(String filePath) {
	FileTypeMap map = MimetypesFileTypeMap.getDefaultFileTypeMap();
	return map.getContentType(filePath);
}
 
開發者ID:wnbittle,項目名稱:praisenter,代碼行數:10,代碼來源:FileUtilities.java


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