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