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


Java IOUtils.copy方法代码示例

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


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

示例1: zip

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
private File zip(File destination, String name) {
    try {
        File z = new File(Files.createTempDir(), name+".zip");
        ZipArchiveOutputStream out = ZipHelper.setupZipOutputStream(new FileOutputStream(z)); 
        for(String f : files(destination, "")) {
          out.putArchiveEntry(new ZipArchiveEntry(f));
          FileInputStream in = new FileInputStream(new File(destination, f));
          IOUtils.copy(in, out);
          in.close();
          out.closeArchiveEntry();
        }
        out.close();
        return z;
    } catch(Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:18,代码来源:HtmlZip.java

示例2: get

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
@GetMapping("/**")
@ResponseBody
public void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String path = request.getServletPath();
    log.info("GET " + path);

    if (path.equals("/")) {
        path = "/index.html";
    }

    File f = ResourceManager.getResource(path.substring(1));
    boolean isInPublic = f.getAbsolutePath().startsWith(ResourceManager.PUBLIC_DIR.getAbsolutePath());
    //Verify that the file requested is in a public directory
    if (!f.getParentFile().getAbsolutePath().equals(ResourceManager.getDataDir().getAbsolutePath())
            && !isInPublic) {
        throw new FileNotFoundException();
    }

    if (!f.exists()) {
        throw new FileNotFoundException();
    }

    Metadata metadata = new Metadata();
    metadata.set(Metadata.RESOURCE_NAME_KEY, f.toString());

    MediaType mediaType = tika.getDetector().detect(
            TikaInputStream.get(f.toPath()), metadata);

    response.setContentType(mediaType.toString());
    response.setContentLengthLong(f.length());

    IOUtils.copy(new FileInputStream(f), response.getOutputStream());
    response.flushBuffer();
}
 
开发者ID:Frederikam,项目名称:fred.moe,代码行数:35,代码来源:SpringController.java

示例3: parse

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
public void parse(InputStream stream, ContentHandler handler,
                  Metadata metadata, ParseContext context) throws IOException,
        SAXException, TikaException {
    String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
    if(name != null && wanted.containsKey(name)) {
        FileOutputStream out = new FileOutputStream(wanted.get(name));
        IOUtils.copy(stream, out);
        out.close();
    } else {
        if(downstreamParser != null) {
            downstreamParser.parse(stream, handler, metadata, context);
        }
    }
}
 
开发者ID:zhishan332,项目名称:hunt4j,代码行数:15,代码来源:TikaHelper.java

示例4: download

import org.apache.tika.io.IOUtils; //导入方法依赖的package包/类
private boolean download(String src, String local, File destination, String playSession) {
    try {
        HttpClient client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
        URI u = new URI(src);
        String url;
        if(u.isAbsolute()) {
            url = u.toString();
        } else {
            url = "http://localhost:9000" + u.toString();
            HttpState state = new HttpState();
            Cookie session = new Cookie("localhost", "PLAY_SESSION",
                    playSession, "/", -1, false);
            state.addCookie(session);
            client.setState(state);
        }
        HttpMethod method = new GetMethod(url);
        method.setFollowRedirects(true);
        client.executeMethod(method);
        if(method.getStatusCode() == 200) {
            InputStream in = method.getResponseBodyAsStream();
            File f = new File(destination, local);
            f.getParentFile().mkdirs();
            FileOutputStream out = new FileOutputStream(new File(destination, local));
            IOUtils.copy(in, out);
            IOUtils.closeQuietly(out);
            method.releaseConnection();
            return true;
        } else {
            method.releaseConnection();
            return false;
        }
    } catch(Exception e) {
        return false;
    }
}
 
开发者ID:uq-eresearch,项目名称:aorra,代码行数:37,代码来源:HtmlZip.java


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