當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。