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


Java Magic.getMagicMatch方法代码示例

本文整理汇总了Java中net.sf.jmimemagic.Magic.getMagicMatch方法的典型用法代码示例。如果您正苦于以下问题:Java Magic.getMagicMatch方法的具体用法?Java Magic.getMagicMatch怎么用?Java Magic.getMagicMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sf.jmimemagic.Magic的用法示例。


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

示例1: getFileExtension

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
/**
 * 传入文件的前部门字节流,获取文件的实际扩展名
 *
 * @param metaStream
 * @return
 */
public static String getFileExtension(byte[] metaStream) {
    if (metaStream == null)
        return "";

    String extension = "";

    try {
        // onlyMimeMatch true
        MagicMatch match = Magic.getMagicMatch(metaStream, true);
        if (match != null) {

            extension = match.getExtension();
        }
        if ("".equals(extension)) {
            String[] exs = match.getMimeType().split("/");
            extension = exs[1];

        }

    } catch (Exception e) {
    }

    return extension;
}
 
开发者ID:muzixinly,项目名称:wejoy-tool,代码行数:31,代码来源:FileUtil.java

示例2: getMimeType

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
/**
  * return the mime type of a file, dont check extension
  * @param barr
  * @return mime type of the file
  * @throws IOException 
  */
 public static String getMimeType(byte[] barr, String defaultValue) {
     
 	//String mt = getMimeType(new ByteArrayInputStream(barr), null);
 	//if(!StringUtil.isEmpty(mt,true)) return mt;
 	
 	PrintStream out = System.out;
     try {
     	System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
         MagicMatch match = Magic.getMagicMatch(barr);
         return match.getMimeType();
     } 
     catch (Throwable t) {
     	ExceptionUtil.rethrowIfNecessary(t);
return defaultValue;
     }
     finally {
     	System.setOut(out);
     }
 }
 
开发者ID:lucee,项目名称:Lucee4,代码行数:26,代码来源:IOUtil.java

示例3: fetch

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
@Override
public Page fetch(Task task) throws FetchException {
    try {
        if (task.getUrl().startsWith("selenium://")) {
            task.setUrl(task.getUrl().substring("selenium://".length()));
        }
        Page page = new Page();
        long timer = System.currentTimeMillis();
        if (cookies.size() > 0) {
            cookies.forEach(cookie -> webDriver.manage().addCookie(cookie));
        }
        webDriver.get(task.getUrl());
        task.addVisitCount();
        page.setTask(task);
        page.setResponseTime(System.currentTimeMillis() - timer);
        byte[] bytes = webDriver.getPageSource().getBytes();
        page.setContent(bytes);
        // we cannot get content-type form selenium :(
        // see https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/141#issuecomment-191404952
        // using magic-match is a compromise.
        MagicMatch match = Magic.getMagicMatch(bytes);
        page.setContentType(match.getMimeType());
        return page;
    } catch (Throwable throwable) {
        throw new FetchException(throwable.getMessage(), throwable);
    }
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:28,代码来源:SeleniumFetcher.java

示例4: fetch

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
@Override
public Page fetch(Task task) throws FetchException {
    try {
        if (task.getUrl().startsWith("phantomjs://")) {
            task.setUrl(task.getUrl().substring("phantomjs://".length()));
        }
        Page page = new Page();
        long timer = System.currentTimeMillis();
        if (cookies.size() > 0) {
            cookies.forEach(cookie -> webDriver.manage().addCookie(cookie));
        }
        webDriver.get(task.getUrl());
        byte[] bytes = webDriver.getPageSource().getBytes();
        page.setResponseTime(System.currentTimeMillis() - timer);
        task.addVisitCount();
        page.setTask(task);
        page.setContent(bytes);
        // webDriver cannot get content-type form selenium :(
        // see https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/141#issuecomment-191404952
        // using magic-match is a compromise, which might cause efficiency problems.
        MagicMatch match = Magic.getMagicMatch(bytes);
        page.setContentType(match.getMimeType());
        return page;
    } catch (Throwable throwable) {
        throw new FetchException(throwable.getMessage(), throwable);
    }
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:28,代码来源:PhantomJSFetcher.java

示例5: checkImageContents

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
private void checkImageContents(MultipartFile file) {
    MagicMatch match;
    try {
        match = Magic.getMagicMatch(file.getBytes());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    String mimeType = match.getMimeType();
    if (!mimeType.startsWith("image")) {
        throw new IllegalArgumentException("Not an image type: " + mimeType);
    }
}
 
开发者ID:florind,项目名称:inception-serving-sb,代码行数:13,代码来源:AppController.java

示例6: perseMimeType

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
private static String perseMimeType(byte[] bytes){
	try {
		MagicMatch match = Magic.getMagicMatch(bytes);
		String mimeType = match.getMimeType();
		return mimeType;
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:10,代码来源:UploadObject.java

示例7: getMimeType

import net.sf.jmimemagic.Magic; //导入方法依赖的package包/类
public static String getMimeType(byte[] data) {
    String mimeType = "application/octet-stream";
    MagicMatch match = null;
    try {
        match = Magic.getMagicMatch(data);
        mimeType = match.getMimeType();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        e.printStackTrace();
    }
    return mimeType;
}
 
开发者ID:nextreports,项目名称:nextreports-server,代码行数:13,代码来源:MimeTypeUtil.java


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