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


Java FileUtils.copyInputStreamToFile方法代码示例

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


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

示例1: addFiles

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@POST @Path("add/files")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void addFiles(FormDataMultiPart body) {
    List<IBridge.UploadedFileInfo> files = new LinkedList<>();
    for(BodyPart part : body.getBodyParts()) {
        InputStream is = part.getEntityAs(InputStream.class);
        ContentDisposition meta = part.getContentDisposition();

        try {
            File tmpFile = File.createTempFile("dlup", ".dat");
            tmpFile.deleteOnExit();
            FileUtils.copyInputStreamToFile(is, tmpFile);
            LOGGER.info("File {} uploaded to {}", meta.getFileName(), tmpFile);
            files.add(new IBridge.UploadedFileInfo(tmpFile, meta.getFileName()));
        } catch (IOException e) {
            LOGGER.error("Cannot create temporary file for upload", e);
        }
    }

    downloadsService.addFiles(files, globalConfig.getDownloadPath());
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:22,代码来源:Downloads.java

示例2: createPostAtoZs

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Override
public String createPostAtoZs() {
    String html = null;

    String backToTop = mailUI.getMessage("posts.az.page.backtotop");
    String azFileName = environment.getProperty("posts.az.file.name");
    String azFilePath = applicationSettings.getPostAtoZFilePath();

    Map<String, Object> model = new Hashtable<>();
    model.put("alphaLinks", postService.getAlphaLInks());
    model.put("alphaPosts", postService.getAlphaPosts());
    model.put("backToTop", backToTop);

    try {
        Template template = fm.getTemplate("posts/az.ftl");
        html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
        InputStream in = IOUtils.toInputStream(html, "UTF-8");
        FileUtils.copyInputStreamToFile(in, new File(azFilePath + azFileName));
    } catch (IOException | TemplateException e) {
        logger.error("Problem creating A-to-Z template or HTML file: " + e.getMessage());
    }
    return html;
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:24,代码来源:FmServiceImpl.java

示例3: serverSign

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void serverSign() throws IOException, GeneralSecurityException {
    FileRef pdfFile;
    try (InputStream stream = resource("cz/inqool/uas/sign/test.pdf")) {
        pdfFile = repository.create(stream, "test.pdf", "application/pdf", false);
    }

    byte[] cert = resourceBytes("cz/inqool/uas/sign/cert.pem");
    String certBase64 = Base64.encodeBase64String(cert);

    String key = Utils.resourceString("cz/inqool/uas/sign/key8.pem");

    FileRef ref = signer.serverSign(pdfFile.getId(), certBase64, key);

    File targetFile = new File("test.pdf");

    FileRef tmp = repository.get(ref.getId());

    FileUtils.copyInputStreamToFile(tmp.getStream(), targetFile);
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:21,代码来源:PdfSignerTest.java

示例4: setUp

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    File input = temp.newFile(String.format("%s.%s", getBasename(), getFormat().getDefaultFileExtension()));
    FileUtils.copyInputStreamToFile(getInputStream(), input);

    output = temp.newFile(String.format("%S.java", getBasename())).toPath();

    RDF4JSchemaGeneratorCore vb = new RDF4JSchemaGeneratorCore(input.getAbsolutePath(), getFormat());
    vb.setPrefix(getPrefix());
    vb.generate(output);
    System.out.println(output);
}
 
开发者ID:ansell,项目名称:rdf4j-schema-generator,代码行数:13,代码来源:AbstractSchemaSpecificTest.java

示例5: checkModpackIcon

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private static void checkModpackIcon(){
	if(!Constants.MODPACKICON.exists()){
		try {
			FileUtils.copyInputStreamToFile(FileUtil.getResourceStream("images/modpack.png"), Constants.MODPACKICON);
		} catch (IOException e) {
			OneClientLogging.error(e);
		}
	}
}
 
开发者ID:HearthProject,项目名称:OneClient,代码行数:10,代码来源:Main.java

示例6: setUp

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    File input = temp.newFile("ldp.ttl");
    FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/ldp.ttl"), input);

    output = temp.newFile("LPD.java").toPath();

    RDF4JSchemaGeneratorCore vb = new RDF4JSchemaGeneratorCore(input.getAbsolutePath(), (String) null);
    vb.generate(output);
    System.out.println(output);
}
 
开发者ID:ansell,项目名称:rdf4j-schema-generator,代码行数:12,代码来源:SchemaGeneratorCompileTest.java

示例7: inputStreamToFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static File inputStreamToFile(InputStream stream) {
    if (stream != null) {
        File tmp = new File(Clock.getCurrentDate() + "_" + Clock.getCurrentTime());
        tmp.deleteOnExit();
        try {
            FileUtils.copyInputStreamToFile(stream, tmp);
            return tmp;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
开发者ID:faizan-ali,项目名称:full-javaee-app,代码行数:14,代码来源:CustomUtilities.java

示例8: testCreateQrcodeWithLogo

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void testCreateQrcodeWithLogo() throws Exception {
    try (InputStream inputStream = ClassLoader.getSystemResourceAsStream("logo.png")) {
        File logoFile = Files.createTempFile("logo_", ".jpg").toFile();
        FileUtils.copyInputStreamToFile(inputStream, logoFile);
        logger.info("{}",logoFile);
        byte[] bytes = QrcodeUtils.createQrcode(content, 800, logoFile);
        Path path = Files.createTempFile("qrcode_with_logo_", ".jpg");
        generatedQrcodePaths.add(path);
        logger.info("{}",path.toAbsolutePath());
        Files.write(path, bytes);
    }
}
 
开发者ID:binarywang,项目名称:qrcode-utils,代码行数:14,代码来源:QrcodeUtilsTest.java

示例9: createDefaultImageFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * This method will return default image when visitor image in not available.
 * 
 * @throws IOException 
 * @return file
 */
public static File createDefaultImageFile(Resource resource, String path) throws IOException {
	String fileNameWithOutExt = FilenameUtils.removeExtension(path);
	InputStream inputStream = resource.getInputStream();
	File tempFile = File.createTempFile(fileNameWithOutExt, "."+FilenameUtils.getExtension(path));
	FileUtils.copyInputStreamToFile(inputStream, tempFile);
	return tempFile;
}
 
开发者ID:Zymr,项目名称:visitormanagement,代码行数:14,代码来源:Util.java

示例10: init

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@BeforeClass
void init() throws IOException
{
   InputStream is=ProcessingManager.class.getResourceAsStream("size-test.zip");
   
   File tmp_folder = Files.createTempDir();
   File output = new File (tmp_folder, "size-test.zip");
   FileUtils.copyInputStreamToFile(is, output);
   is.close();
   
   sample = output;
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:13,代码来源:ProcessingManagerTest.java

示例11: translateFile

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void translateFile(String fileNameToTranslate, String expectedFileName) throws Exception{
    File expectedFile = new File(EXPECTED_CSV_FILE);
    expectedFile.deleteOnExit();
    File actualTranslatedFile = new File(ACTUAL_TRANSLATED_FILE);
    actualTranslatedFile.deleteOnExit();
    try {
        FileOutputStream fileOutputStream = new FileOutputStream(actualTranslatedFile);
        xlsxToCsvConverter.convert(ClassLoader.getSystemResourceAsStream(fileNameToTranslate), fileOutputStream);
        FileUtils.copyInputStreamToFile(ClassLoader.getSystemResourceAsStream(expectedFileName), expectedFile);
        compareCSVFiles(actualTranslatedFile.getPath(), expectedFile.getPath());
    } catch (Exception e) {
        throw new IOException("I/O exception - couldn't handle streams and files");
    }
}
 
开发者ID:kenshoo,项目名称:file-format-streaming-converter,代码行数:15,代码来源:XlsxToCsvConverterTest.java

示例12: saveCached

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
private void saveCached(String hash, ImageInfo info) throws IOException {
    File cacheDirectory = getCache();
    if (cacheDirectory == null) {
        return;
    }
    File cachedImage = new File(cacheDirectory, hash + ".jpg");
    FileUtils.copyInputStreamToFile(info.inputStream, cachedImage);
    info.inputStream.reset();
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:10,代码来源:BlurImageController.java

示例13: download

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * http 下载请求
 *
 * @param url  请求地址
 * @param path 保存路径
 * @return  result 相应结果
 */
public static boolean download(String url, String path) {
    CloseableHttpClient httpClient = HttpClientFactory.createHttpClient();
    HttpGet request = new HttpGet(url);
    CloseableHttpResponse response;
    boolean res = false;
    try {
        response = httpClient.execute(request, CookieContext.createHttpClientContext());
        if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
            HttpEntity httpEntity = response.getEntity();
            InputStream is = httpEntity.getContent();
            if (!new File(path).exists()) {
                new File(path).getParentFile().mkdirs();
                new File(path).createNewFile();
            }
            FileUtils.copyInputStreamToFile(is, new File(path));
            if (httpEntity != null) {
                EntityUtils.consume(httpEntity);
            }
            res = true;
        }
    } catch (IOException e) {
        logger.error(e.getMessage());
    } finally {
        try {
            httpClient.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    return res;
}
 
开发者ID:1991wangliang,项目名称:lorne_core,代码行数:39,代码来源:HttpUtils.java

示例14: exportSubnodeTemplates

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
    * Export the subnodes' templates into the selected dir.
    *
    * @param node
    * @param outputDir
    * @throws ExportToolContentException
    * @throws RepositoryCheckedException
    * @throws IOException
    */
   private void exportSubnodeTemplates(PedagogicalPlannerSequenceNode node, File outputDir)
    throws IOException, RepositoryCheckedException, ExportToolContentException {
if (node != null) {
    if (node.getLearningDesignId() == null) {
	if (node.getSubnodes() != null) {
	    for (PedagogicalPlannerSequenceNode subnode : node.getSubnodes()) {
		exportSubnodeTemplates(subnode, outputDir);
	    }
	}
    } else {

	List<String> toolsErrorMsgs = new ArrayList<String>();
	String exportedLdFilePath = getExportService().exportLearningDesign(node.getLearningDesignId(),
		toolsErrorMsgs);
	if (!toolsErrorMsgs.isEmpty()) {
	    StringBuffer errorMessages = new StringBuffer();
	    for (String error : toolsErrorMsgs) {
		errorMessages.append(error);
	    }
	    throw new ExportToolContentException(errorMessages.toString());
	}
	FileInputStream inputStream = new FileInputStream(exportedLdFilePath);

	File ldIdDir = new File(outputDir, node.getLearningDesignId().toString());
	ldIdDir.mkdirs();
	File targetFile = new File(ldIdDir,
		node.getLearningDesignTitle() + PedagogicalPlannerAction.FILE_EXTENSION_ZIP);

	PedagogicalPlannerAction.log
		.debug("Preparing for zipping the template file: " + node.getLearningDesignTitle());
	FileUtils.copyInputStreamToFile(inputStream, targetFile);
    }
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:44,代码来源:PedagogicalPlannerAction.java

示例15: loadTextureFromServer

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
protected void loadTextureFromServer()
{
    this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet())
    {
        private static final String __OBFID = "CL_00001050";
        public void run()
        {
            HttpURLConnection httpurlconnection = null;
            ThreadDownloadImageData.logger.debug("Downloading http texture from {} to {}", new Object[] {ThreadDownloadImageData.this.imageUrl, ThreadDownloadImageData.this.cacheFile});

            try
            {
                httpurlconnection = (HttpURLConnection)(new URL(ThreadDownloadImageData.this.imageUrl)).openConnection(Minecraft.getMinecraft().getProxy());
                httpurlconnection.setDoInput(true);
                httpurlconnection.setDoOutput(false);
                httpurlconnection.connect();

                if (httpurlconnection.getResponseCode() / 100 != 2)
                {
                    return;
                }

                BufferedImage bufferedimage;

                if (ThreadDownloadImageData.this.cacheFile != null)
                {
                    FileUtils.copyInputStreamToFile(httpurlconnection.getInputStream(), ThreadDownloadImageData.this.cacheFile);
                    bufferedimage = ImageIO.read(ThreadDownloadImageData.this.cacheFile);
                }
                else
                {
                    bufferedimage = TextureUtil.readBufferedImage(httpurlconnection.getInputStream());
                }

                if (ThreadDownloadImageData.this.imageBuffer != null)
                {
                    bufferedimage = ThreadDownloadImageData.this.imageBuffer.parseUserSkin(bufferedimage);
                }

                ThreadDownloadImageData.this.setBufferedImage(bufferedimage);
            }
            catch (Exception exception)
            {
                ThreadDownloadImageData.logger.error((String)"Couldn\'t download http texture", (Throwable)exception);
                return;
            }
            finally
            {
                if (httpurlconnection != null)
                {
                    httpurlconnection.disconnect();
                }

                ThreadDownloadImageData.this.imageFound = Boolean.valueOf(ThreadDownloadImageData.this.bufferedImage != null);
            }
        }
    };
    this.imageThread.setDaemon(true);
    this.imageThread.start();
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:61,代码来源:ThreadDownloadImageData.java


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