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