Java Code Examples for org.apache.commons.io.FileUtils#copyToFile()
The following examples show how to use
org.apache.commons.io.FileUtils#copyToFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebDriverHandlerImpl.java From IridiumApplicationTesting with MIT License | 6 votes |
private String copyDriver( @NotNull final InputStream stream, @NotNull final String name, @NotNull final List<File> tempFiles) throws IOException { checkNotNull(stream); checkArgument(StringUtils.isNotBlank(name)); final Path driverTemp = Files.createTempFile("driver", name); FileUtils.copyToFile(stream, driverTemp.toFile()); driverTemp.toFile().setExecutable(true); tempFiles.add(driverTemp.toFile()); final String driverPath = driverTemp.toAbsolutePath().toString(); LOGGER.info("Saving driver file {} to {}", name, driverPath); return driverPath; }
Example 2
Source File: LocalFileBlobExportMechanism.java From james-project with Apache License 2.0 | 6 votes |
private String copyBlobToFile(BlobId blobId, Optional<String> fileCustomPrefix, Optional<FileExtension> fileExtension) { try { File exportingDirectory = fileSystem.getFile(configuration.exportDirectory); FileUtils.forceMkdir(exportingDirectory); String fileName = ExportedFileNamesGenerator.generateFileName(fileCustomPrefix, blobId, fileExtension); String fileURL = configuration.exportDirectory + "/" + fileName; File file = fileSystem.getFile(fileURL); FileUtils.copyToFile(blobStore.read(blobStore.getDefaultBucketName(), blobId), file); return file.getAbsolutePath(); } catch (IOException e) { throw new BlobExportException("Error while copying blob to file", e); } }
Example 3
Source File: TestFSPackageRegistry.java From jackrabbit-filevault with Apache License 2.0 | 6 votes |
@Test public void testNonMetaXmlFile() throws Exception { PackageId idC = registry.register(getStream(TEST_PACKAGE_C_10), false); assertEquals(idC, registry.getInstallState(idC).getPackageId()); assertEquals(FSPackageStatus.REGISTERED, registry.getInstallState(idC).getStatus()); Field stateCache = registry.getClass().getDeclaredField("stateCache"); stateCache.setAccessible(true); stateCache.set(registry, new HashMap<String, FSInstallState>() ); Method getPackageMetaDataFile = registry.getClass().getDeclaredMethod("getPackageMetaDataFile", new Class<?>[]{idC.getClass()}); getPackageMetaDataFile.setAccessible(true); Method loadPackageCache = registry.getClass().getDeclaredMethod("loadPackageCache"); loadPackageCache.setAccessible(true); File metaFile = (File)getPackageMetaDataFile.invoke(registry, idC); FileUtils.copyToFile(getStream("repository.xml"), metaFile); loadPackageCache.invoke(registry); assertEquals(FSPackageStatus.NOTREGISTERED, registry.getInstallState(idC).getStatus()); }
Example 4
Source File: UploadUtil.java From spring-boot-plus with Apache License 2.0 | 5 votes |
/** * 上传文件 * * @param uploadPath 上传目录 * @param multipartFile 上传文件 * @param uploadFileNameHandle 回调 * @return * @throws Exception */ public static String upload(String uploadPath, MultipartFile multipartFile, UploadFileNameHandle uploadFileNameHandle) throws Exception { // 获取输入流 InputStream inputStream = multipartFile.getInputStream(); // 文件保存目录 File saveDir = new File(uploadPath); // 判断目录是否存在,不存在,则创建,如创建失败,则抛出异常 if (!saveDir.exists()) { boolean flag = saveDir.mkdirs(); if (!flag) { throw new RuntimeException("创建" + saveDir + "目录失败!"); } } String originalFilename = multipartFile.getOriginalFilename(); String saveFileName; if (uploadFileNameHandle == null) { saveFileName = new DefaultUploadFileNameHandleImpl().handle(originalFilename); } else { saveFileName = uploadFileNameHandle.handle(originalFilename); } log.info("saveFileName = " + saveFileName); File saveFile = new File(saveDir, saveFileName); // 保存文件到服务器指定路径 FileUtils.copyToFile(inputStream, saveFile); return saveFileName; }
Example 5
Source File: ImageUtilsTest.java From markdown-image-kit with MIT License | 5 votes |
@Test public void fileCopyTest() throws IOException { File file1 = new File("/Users/dong4j/Downloads/xu.png"); File file2 = new File("/Users/dong4j/Downloads/xu1.png"); FileUtils.copyToFile(new FileInputStream(file1), file2); FileUtil.copy(new FileInputStream(file1), new FileOutputStream(file2)); }
Example 6
Source File: RepoXMLHandlerTest.java From fdroidclient with GNU General Public License v3.0 | 5 votes |
private void writeResourceToObbDir(String assetName) throws IOException { InputStream input = getClass().getClassLoader().getResourceAsStream(assetName); String packageName = assetName.substring(assetName.indexOf("obb"), assetName.lastIndexOf('.')); File f = new File(App.getObbDir(packageName), assetName); FileUtils.copyToFile(input, f); input.close(); }
Example 7
Source File: UploadController.java From karate with MIT License | 4 votes |
private FileInfo getFileInfo(MultipartFile file, String message) throws Exception { String uuid = UUID.randomUUID().toString(); String filePath = FILES_BASE + uuid; FileUtils.copyToFile(file.getInputStream(), new File(filePath)); String filename1 = file.getOriginalFilename(); String contentType1 = file.getContentType(); FileInfo fileInfo = new FileInfo(uuid, filename1, message, contentType1); String json = mapper.writeValueAsString(fileInfo); FileUtils.writeStringToFile(new File(filePath + "_meta.txt"), json, "utf-8"); return fileInfo; }
Example 8
Source File: DigitalObjectResource.java From proarc with GNU General Public License v3.0 | 4 votes |
private SmartGwtResponse<Map<String, Object>> updateDisseminationImpl( @FormDataParam(DigitalObjectResourceApi.DIGITALOBJECT_PID) String pid, @FormDataParam(DigitalObjectResourceApi.BATCHID_PARAM) Integer batchId, @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_DATASTREAM) String dsId, @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_FILE) InputStream fileContent, @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_FILE) FormDataContentDisposition fileInfo, @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_FILE) FormDataBodyPart fileBodyPart, @FormDataParam(DigitalObjectResourceApi.DISSEMINATION_MIME) String mimeType ) throws IOException, DigitalObjectException { if (pid == null) { return SmartGwtResponse.<Map<String,Object>>asError(DigitalObjectResourceApi.DIGITALOBJECT_PID, "Missing PID!"); } if (fileContent == null) { return SmartGwtResponse.<Map<String,Object>>asError(DigitalObjectResourceApi.DISSEMINATION_FILE, "Missing file!"); } if (dsId != null && !dsId.equals(BinaryEditor.RAW_ID)) { throw RestException.plainText(Status.BAD_REQUEST, "Missing or unsupported datastream ID: " + dsId); } String filename = getFilename(fileInfo.getFileName()); File file = File.createTempFile("proarc_", null); try { FileUtils.copyToFile(fileContent, file); // XXX add config property or user permission if (file.length() > 1*1024 * 1024 * 1024) { // 1GB throw RestException.plainText(Status.BAD_REQUEST, "File contents too large!"); } MediaType mime; try { mime = mimeType != null ? MediaType.valueOf(mimeType) : fileBodyPart.getMediaType(); } catch (IllegalArgumentException ex) { return SmartGwtResponse.<Map<String,Object>>asError( DigitalObjectResourceApi.DISSEMINATION_MIME, "Invalid MIME type! " + mimeType); } LOG.log(Level.FINE, "filename: {0}, user mime: {1}, resolved mime: {2}, {3}/{4}", new Object[]{filename, mimeType, mime, pid, dsId}); DigitalObjectHandler doHandler = findHandler(pid, batchId); DisseminationHandler dissemination = doHandler.dissemination(BinaryEditor.RAW_ID); DisseminationInput input = new DisseminationInput(file, filename, mime); dissemination.setDissemination(input, session.asFedoraLog()); doHandler.commit(); } finally { file.delete(); } return new SmartGwtResponse<Map<String,Object>>(Collections.singletonMap("processId", (Object) 0L)); }
Example 9
Source File: AwsS3ObjectStorage.java From james-project with Apache License 2.0 | 4 votes |
private File copyToTempFile(Blob blob) throws IOException { File file = File.createTempFile(UUID.randomUUID().toString(), ".tmp"); FileUtils.copyToFile(blob.getPayload().openStream(), file); return file; }
Example 10
Source File: FakeGoServer.java From gocd with Apache License 2.0 | 4 votes |
public void copyTo(File output) throws IOException { try (InputStream in = source.getInputStream()) { FileUtils.copyToFile(in, output); } }