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


Java IOUtils.copy方法代码示例

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


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

示例1: doDownload

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**
 * 通过httpClient get 下载文件
 *
 * @param url      网络文件全路径
 * @param savePath 保存文件全路径
 * @return 状态码 200表示成功
 */
public static int doDownload(String url, String savePath) {
	// 创建默认的HttpClient实例.
	CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
	HttpGet get = new HttpGet(url);
	CloseableHttpResponse closeableHttpResponse = null;
	try {
		closeableHttpResponse = closeableHttpClient.execute(get);
		HttpEntity entity = closeableHttpResponse.getEntity();
		if (entity != null) {
			InputStream in = entity.getContent();
			FileOutputStream out = new FileOutputStream(savePath);
			IOUtils.copy(in, out);
			EntityUtils.consume(entity);
			closeableHttpResponse.close();
		}
		int code = closeableHttpResponse.getStatusLine().getStatusCode();
		closeableHttpClient.close();
		return code;
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		closeSource(closeableHttpClient, closeableHttpResponse);
	}
	return 0;
}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:33,代码来源:HttpClientUtil.java

示例2: fetchFavicons

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
private static List<Image> fetchFavicons() {

		List<Image> favicons = new ArrayList<Image>(FAVICON_RESOURCE_SUFFIXES.length);

		ByteArrayOutputStream faviconOut = new ByteArrayOutputStream();
		for (String faviconSuffix : FAVICON_RESOURCE_SUFFIXES) {
			try {
				faviconOut.reset();

				InputStream resourceIn = WebzLauncherGUI.class.getResourceAsStream(FAVICON_RESOURCE_PREFIX + faviconSuffix);
				if (resourceIn != null) {

					IOUtils.copy(resourceIn, faviconOut);
					favicons.add(new ImageIcon(faviconOut.toByteArray()).getImage());
				}
			} catch (IOException e) {
				// it's just a favicon - ignore
			}
		}
		return favicons;
	}
 
开发者ID:terems-org,项目名称:webz-server,代码行数:22,代码来源:WebzLauncherGUI.java

示例3: graphs

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = { "/graph **", "/graph **/**" })
public void graphs(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.setContentType("image/png");

    String path = (String) request
            .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    stataService.saveCmd(path);

    path = path.substring(7);

    stataService.run("graph display " + path);

    File f = stataService.graph(path);

    InputStream in = new FileInputStream(f);
    IOUtils.copy(in, response.getOutputStream());
}
 
开发者ID:mas802,项目名称:stata-ux,代码行数:19,代码来源:HtmlController.java

示例4: readObject

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**
 * Reads the state of this object during deserialization.
 *
 * @param in The stream from which the state should be read.
 *
 * @throws IOException if an error occurs.
 * @throws ClassNotFoundException if class cannot be found.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
    // read values
    in.defaultReadObject();

    OutputStream output = getOutputStream();
    if (cachedContent != null) {
        output.write(cachedContent);
    } else {
        FileInputStream input = new FileInputStream(dfosFile);
        IOUtils.copy(input, output);
        dfosFile.delete();
        dfosFile = null;
    }
    output.close();

    cachedContent = null;
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:27,代码来源:DiskFileItem.java

示例5: testSaveAsDocx

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@Test
public void testSaveAsDocx() throws FileNotFoundException, IOException{
	
	File inputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.doc");
	File outputFile = new File("D:/Workspace/kbase-doc/target/classes/static/DATAS/1512561737109/1.docx");
	IOUtils.copy(new FileInputStream(inputFile), new FileOutputStream(outputFile));
	
}
 
开发者ID:ekoz,项目名称:kbase-doc,代码行数:9,代码来源:ConverteTests.java

示例6: getMandateFile

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@ApiOperation(value = "Get mandate file")
@RequestMapping(method = GET, value = "/{id}/file")
public void getMandateFile(@PathVariable("id") Long mandateId,
                           @ApiIgnore @AuthenticationPrincipal AuthenticatedPerson authenticatedPerson,
                           HttpServletResponse response) throws IOException {

    Mandate mandate = getMandateOrThrow(mandateId, authenticatedPerson.getUserId());
    response.addHeader("Content-Disposition", "attachment; filename=Tuleva_avaldus.bdoc");

    byte[] content = mandate.getMandate().orElseThrow(() -> new RuntimeException("Mandate is not signed"));

    IOUtils.copy(new ByteArrayInputStream(content), response.getOutputStream());
    response.flushBuffer();

}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:16,代码来源:MandateController.java

示例7: cacheInputStream

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
private void cacheInputStream() throws IOException {
  /* Cache the inputstream in order to read it multiple times. For
   * convenience, I use apache.commons IOUtils
   */
  cachedBytes = new ByteArrayOutputStream();
  IOUtils.copy(super.getInputStream(), cachedBytes);
}
 
开发者ID:saintdan,项目名称:spring-microservices-boilerplate,代码行数:8,代码来源:RequestWrapper.java

示例8: graph

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping("/graph")
public void graph(HttpServletResponse response) throws IOException {
    response.setContentType("image/png");

    stataService.saveCmd("/graph");
    File f = stataService.graph();

    InputStream in = new FileInputStream(f);
    IOUtils.copy(in, response.getOutputStream());
}
 
开发者ID:mas802,项目名称:stata-ux,代码行数:11,代码来源:HtmlController.java

示例9: est

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping("/est")
public void est(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.setContentType("text/html");

    String path = (String) request
            .getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
    stataService.saveCmd(path);

    File f = stataService.est();

    InputStream in = new FileInputStream(f);
    IOUtils.copy(in, response.getOutputStream());
}
 
开发者ID:mas802,项目名称:stata-ux,代码行数:15,代码来源:HtmlController.java

示例10: service

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
/**************************************************************************/
@Override
protected void service(HttpServletRequest req, HttpServletResponse rsp)
        throws ServletException, IOException
{
    InputStream is = this.getClass().getResourceAsStream("examplerdf.rdf");
    IOUtils.copy(is, rsp.getOutputStream());
    IOUtils.closeQuietly(is);
}
 
开发者ID:hugomanguinhas,项目名称:europeana,代码行数:10,代码来源:DummyServlet.java

示例11: writeInternal

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@Override
protected void writeInternal(InputStream inputStream, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
  IOUtils.copy(inputStream, outputMessage.getBody());
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:6,代码来源:LocAccessLogTest.java

示例12: findPhotoByName

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
public String findPhotoByName(String name) throws IOException {
  InputStream inputStream = fileStorage.read(name);
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  IOUtils.copy(inputStream, byteArrayOutputStream);
  return String.valueOf(byteArrayOutputStream);
}
 
开发者ID:sys-devel-d,项目名称:pimp,代码行数:7,代码来源:UserService.java

示例13: exportZipByGroupId

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/api/sql/exportByGroupId", method = RequestMethod.GET, produces = "application/zip")
public byte[] exportZipByGroupId(
        @RequestParam long groupid,
        @RequestParam String filename,
        HttpServletResponse response) throws Exception {
    //setting headers
    response.setContentType("application/zip");
    response.setStatus(HttpServletResponse.SC_OK);
    response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + ".zip\"");

    //creating byteArray stream, make it bufforable and passing this buffor to ZipOutputStream
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
    ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);

    //simple file list, just for tests
    List<File> files = prepareSqlFileByGroupId(groupid);

    //packing files
    for (File file : files) {
        //new zip entry and copying inputstream with file to zipOutputStream, after all closing streams
        zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
        FileInputStream fileInputStream = new FileInputStream(file);

        IOUtils.copy(fileInputStream, zipOutputStream);

        fileInputStream.close();
        zipOutputStream.closeEntry();
    }
    if (zipOutputStream != null) {
        zipOutputStream.finish();
        zipOutputStream.flush();
        IOUtils.closeQuietly(zipOutputStream);
    }
    IOUtils.closeQuietly(bufferedOutputStream);
    IOUtils.closeQuietly(byteArrayOutputStream);

    housekeepCreateFile();

    return byteArrayOutputStream.toByteArray();
}
 
开发者ID:lawrencelai,项目名称:Oriole,代码行数:42,代码来源:SqlExportController.java

示例14: exportZipByTargetVersion

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/api/sql/exportByTargetVersion", method = RequestMethod.GET, produces = "application/zip")
public byte[] exportZipByTargetVersion(
        @RequestParam String targetVision,
        @RequestParam String filename,
        HttpServletResponse response) throws Exception {
    //setting headers
    response.setContentType("application/zip");
    response.setStatus(HttpServletResponse.SC_OK);
    response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + ".zip\"");

    //creating byteArray stream, make it bufforable and passing this buffor to ZipOutputStream
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
    ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);
    List<SqlCIGroup> sqlCIGroupList = sqlCIGroupRepository.findByTargetVersion(targetVision);
    //simple file list, just for tests
    ArrayList<File> files = new ArrayList<File>();
    Iterator itrSqlCIGroup = sqlCIGroupList.iterator();
    while (itrSqlCIGroup.hasNext()) {
        SqlCIGroup sqlCIGroup = (SqlCIGroup) itrSqlCIGroup.next();
        files.addAll(prepareSqlFileByGroupId(sqlCIGroup.getId()));
    }

    //packing files
    for (File file : files) {
        //new zip entry and copying inputstream with file to zipOutputStream, after all closing streams
        zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
        FileInputStream fileInputStream = new FileInputStream(file);

        IOUtils.copy(fileInputStream, zipOutputStream);

        fileInputStream.close();
        zipOutputStream.closeEntry();
    }
    if (zipOutputStream != null) {
        zipOutputStream.finish();
        zipOutputStream.flush();
        IOUtils.closeQuietly(zipOutputStream);
    }
    IOUtils.closeQuietly(bufferedOutputStream);
    IOUtils.closeQuietly(byteArrayOutputStream);

    housekeepCreateFile();

    return byteArrayOutputStream.toByteArray();
}
 
开发者ID:lawrencelai,项目名称:Oriole,代码行数:47,代码来源:SqlExportController.java

示例15: testAdditionalWebInfClassesPaths

import org.apache.tomcat.util.http.fileupload.IOUtils; //导入方法依赖的package包/类
@Test
public void testAdditionalWebInfClassesPaths() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0-virtual-webapp/src/main/webapp");
    // app dir is relative to server home
    StandardContext ctx = (StandardContext) tomcat.addWebapp(null, "/test",
        appDir.getAbsolutePath());
    File tempFile = File.createTempFile("virtualWebInfClasses", null);

    File additionWebInfClasses = new File(tempFile.getAbsolutePath() + ".dir");
    Assert.assertTrue(additionWebInfClasses.mkdirs());
    File targetPackageForAnnotatedClass =
        new File(additionWebInfClasses,
            MyAnnotatedServlet.class.getPackage().getName().replace('.', '/'));
    Assert.assertTrue(targetPackageForAnnotatedClass.mkdirs());
    InputStream annotatedServletClassInputStream =
        this.getClass().getResourceAsStream(
            MyAnnotatedServlet.class.getSimpleName() + ".class");
    FileOutputStream annotatedServletClassOutputStream =
        new FileOutputStream(new File(targetPackageForAnnotatedClass,
            MyAnnotatedServlet.class.getSimpleName() + ".class"));
    IOUtils.copy(annotatedServletClassInputStream, annotatedServletClassOutputStream);
    annotatedServletClassInputStream.close();
    annotatedServletClassOutputStream.close();

    VirtualWebappLoader loader = new VirtualWebappLoader(ctx.getParentClassLoader());
    loader.setVirtualClasspath("test/webapp-3.0-virtual-webapp/target/classes;" + //
        "test/webapp-3.0-virtual-library/target/classes;" + //
        additionWebInfClasses.getAbsolutePath());
    ctx.setLoader(loader);

    tomcat.start();
    // first test that without the setting on StandardContext the annotated
    // servlet is not detected
    assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE, 404);

    tomcat.stop();

    // then test that if we configure StandardContext with the additional
    // path, the servlet is detected
    // ctx.setAdditionalVirtualWebInfClasses(additionWebInfClasses.getAbsolutePath());
    VirtualDirContext resources = new VirtualDirContext();
    resources.setExtraResourcePaths("/WEB-INF/classes=" + additionWebInfClasses);
    ctx.setResources(resources);

    tomcat.start();
    assertPageContains("/test/annotatedServlet", MyAnnotatedServlet.MESSAGE);
    tomcat.stop();
    FileUtils.deleteDirectory(additionWebInfClasses);
    tempFile.delete();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:53,代码来源:TestVirtualContext.java


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