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


Java FileSystemUtils类代码示例

本文整理汇总了Java中org.springframework.util.FileSystemUtils的典型用法代码示例。如果您正苦于以下问题:Java FileSystemUtils类的具体用法?Java FileSystemUtils怎么用?Java FileSystemUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setUp

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
/**
 * Pre-load some fake images
 *
 * @return Spring Boot {@link CommandLineRunner} automatically run after app context is loaded.
 */
@Bean
CommandLineRunner setUp() throws IOException {
	return (args) -> {
		FileSystemUtils.deleteRecursively(new File(UPLOAD_ROOT));

		Files.createDirectory(Paths.get(UPLOAD_ROOT));

		FileCopyUtils.copy("Test file",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-cover.jpg"));

		FileCopyUtils.copy("Test file2",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-2nd-edition-cover.jpg"));

		FileCopyUtils.copy("Test file3",
			new FileWriter(UPLOAD_ROOT + "/bazinga.png"));
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:25,代码来源:ImageService.java

示例2: write

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Override
public File write(Package pkg, File targetDirectory) {
	PackageMetadata packageMetadata = pkg.getMetadata();
	File tmpDir = TempFileUtils.createTempDirectory("skipper" + packageMetadata.getName()).toFile();
	File rootPackageDir = new File(tmpDir,
			String.format("%s-%s", packageMetadata.getName(), packageMetadata.getVersion()));
	rootPackageDir.mkdir();
	writePackage(pkg, rootPackageDir);
	if (!pkg.getDependencies().isEmpty()) {
		File packagesDir = new File(rootPackageDir, "packages");
		packagesDir.mkdir();
		for (Package dependencyPkg : pkg.getDependencies()) {
			File packageDir = new File(packagesDir, dependencyPkg.getMetadata().getName());
			packageDir.mkdir();
			writePackage(dependencyPkg, packageDir);
		}
	}
	File targetZipFile = PackageFileUtils.calculatePackageZipFile(pkg.getMetadata(), targetDirectory);
	ZipUtil.pack(rootPackageDir, targetZipFile, true);
	FileSystemUtils.deleteRecursively(tmpDir);
	return targetZipFile;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:23,代码来源:DefaultPackageWriter.java

示例3: setUp

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
/**
 * Pre-load some test images
 *
 * @return Spring Boot {@link CommandLineRunner} automatically
 *         run after app context is loaded.
 */
@Bean
CommandLineRunner setUp() throws IOException {
	return (args) -> {
		FileSystemUtils.deleteRecursively(new File(UPLOAD_ROOT));

		Files.createDirectory(Paths.get(UPLOAD_ROOT));

		FileCopyUtils.copy("Test file",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-cover.jpg"));

		FileCopyUtils.copy("Test file2",
			new FileWriter(UPLOAD_ROOT +
				"/learning-spring-boot-2nd-edition-cover.jpg"));

		FileCopyUtils.copy("Test file3",
			new FileWriter(UPLOAD_ROOT + "/bazinga.png"));
	};
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:26,代码来源:ImageService.java

示例4: setUp

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
	operations.dropCollection(Image.class);

	operations.insert(new Image("1",
		"learning-spring-boot-cover.jpg"));
	operations.insert(new Image("2",
		"learning-spring-boot-2nd-edition-cover.jpg"));
	operations.insert(new Image("3",
		"bazinga.png"));

	FileSystemUtils.deleteRecursively(new File(ImageService.UPLOAD_ROOT));

	Files.createDirectory(Paths.get(ImageService.UPLOAD_ROOT));

	FileCopyUtils.copy("Test file",
		new FileWriter(ImageService.UPLOAD_ROOT +
			"/learning-spring-boot-cover.jpg"));

	FileCopyUtils.copy("Test file2",
		new FileWriter(ImageService.UPLOAD_ROOT +
			"/learning-spring-boot-2nd-edition-cover.jpg"));

	FileCopyUtils.copy("Test file3",
		new FileWriter(ImageService.UPLOAD_ROOT + "/bazinga.png"));
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:27,代码来源:ImageServiceTests.java

示例5: createDownloadFile

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
private byte[] createDownloadFile(Function<File, File> action) {
    Path tmpDir = null;

    try {
        tmpDir = createTempDir();

        if (logger.isDebugEnabled()) {
            logger.debug("Generating project in temporary directory " + tmpDir.toFile());
        }

        File download = action.apply(tmpDir.toFile());
        return fileToByteArray(download);
    } catch(Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (tmpDir != null) {
            if (!FileSystemUtils.deleteRecursively(tmpDir.toFile())) {
                logger.warn("Unable to delete temporary directory " + tmpDir.toFile());
            }
        }
    }
}
 
开发者ID:bmuschko,项目名称:gradle-initializr,代码行数:23,代码来源:DefaultGradleInitializrService.java

示例6: createProject

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
public ProjectConnection createProject(String name) throws IOException {
	File projectDirectory = new File("target/" + name);
	projectDirectory.mkdirs();

	File gradleScript = new File(projectDirectory, "build.gradle");

	if (new File("src/test/resources", name).isDirectory()) {
		FileSystemUtils.copyRecursively(new File("src/test/resources", name),
				projectDirectory);
	}
	else {
		FileCopyUtils.copy(new File("src/test/resources/" + name + ".gradle"),
				gradleScript);
	}

	GradleConnector gradleConnector = GradleConnector.newConnector();
	gradleConnector.useGradleVersion(this.gradleVersion);

	((DefaultGradleConnector) gradleConnector).embedded(true);
	return gradleConnector.forProjectDirectory(projectDirectory).connect();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:ProjectCreator.java

示例7: explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Test
public void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath()
		throws Exception {
	File warRoot = new File("target/exploded-war");
	FileSystemUtils.deleteRecursively(warRoot);
	warRoot.mkdirs();
	File webInfClasses = new File(warRoot, "WEB-INF/classes");
	webInfClasses.mkdirs();
	File webInfLib = new File(warRoot, "WEB-INF/lib");
	webInfLib.mkdirs();
	File webInfLibFoo = new File(webInfLib, "foo.jar");
	new JarOutputStream(new FileOutputStream(webInfLibFoo)).close();
	WarLauncher launcher = new WarLauncher(new ExplodedArchive(warRoot, true));
	List<Archive> archives = launcher.getClassPathArchives();
	assertThat(archives).hasSize(2);
	assertThat(getUrls(archives)).containsOnly(webInfClasses.toURI().toURL(),
			new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/"));
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:WarLauncherTests.java

示例8: explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Test
public void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath()
		throws Exception {
	File warRoot = new File("target/exploded-war");
	FileSystemUtils.deleteRecursively(warRoot);
	warRoot.mkdirs();
	File webInfClasses = new File(warRoot, "WEB-INF/classes");
	webInfClasses.mkdirs();
	File webInfLib = new File(warRoot, "WEB-INF/lib");
	webInfLib.mkdirs();
	File webInfLibFoo = new File(webInfLib, "foo.jar");
	new JarOutputStream(new FileOutputStream(webInfLibFoo)).close();

	WarLauncher launcher = new WarLauncher(new ExplodedArchive(warRoot, true));
	List<Archive> archives = launcher.getClassPathArchives();
	assertEquals(2, archives.size());

	assertThat(getUrls(archives), hasItems(webInfClasses.toURI().toURL(),
			new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/")));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:21,代码来源:WarLauncherTests.java

示例9: run

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Override
public void run(String... args) throws Exception {

    FileSystemUtils.deleteRecursively(new File(dbDataDir));

    LOG.info("Creating Spatial alias");
    jdbcTemplate.execute("CREATE ALIAS IF NOT EXISTS SPATIAL_INIT FOR \"org.h2gis.h2spatialext.CreateSpatialExtension.initSpatialExtension\";");

    LOG.info("Initializing spatial extension");
    jdbcTemplate.execute("CALL SPATIAL_INIT();");

    loadData("DOP_ZPS_Stani_l_mercator.shp", "DOP_ZPS_Stani_l");
    loadData("DOP_ZachParkoviste_b_mercator.shp", "DOP_ZachParkoviste_b");
    loadData("DOP_ZachParkoviste_b_mercator-buffer20.shp", "DOP_ZachParkoviste_b_buffer20");
    loadData("DOP_ZPS_Automaty_b_mercator.shp", "DOP_ZPS_Automaty_b");
    loadData("DOP_ZPS_Automaty_b_mercator-buffer20.shp", "DOP_ZPS_Automaty_b_buffer20");

}
 
开发者ID:bedla,项目名称:parkovani-v-praze,代码行数:19,代码来源:ShapeFileLoaderController.java

示例10: export

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
public void export() {
    if (!enabled) {
        return;
    }
    if (exporting.getAndSet(true)) {
        throw new IllegalStateException("Export already in progress");
    }

    try {
        LOGGER.info("Database export started");
        final Stopwatch stopwatch = Stopwatch.createStarted();

        initDirs();
        exportToFiles();

        Validate.isTrue(FileSystemUtils.deleteRecursively(exportDir), "Recursive delete failed: ", exportDir);
        Validate.isTrue(tmpDir.renameTo(exportDir), "Rename failed: ", tmpDir);

        LOGGER.info("Database export complete after {} in {}", stopwatch.stop().toString(), exportDir);
    } finally {
        exporting.set(false);
    }
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:24,代码来源:RpslObjectsExporter.java

示例11: initDirs

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
private void initDirs() {
    if (exportDir.exists()) {
        Validate.isTrue(exportDir.canWrite(), "Unable to write to: ", exportDir);
        Validate.isTrue(exportFileWriterFactory.isExportDir(exportDir), "Existing dir does not have correct structure: ", exportDir);
        LOGGER.info("Use existing: {}", exportDir);
    } else {
        Validate.isTrue(exportDir.mkdirs(), "Unable to create export dir: ", exportDir);
        LOGGER.info("Created: {}", exportDir);
    }

    if (tmpDir.exists()) {
        Validate.isTrue(exportFileWriterFactory.isExportDir(tmpDir), "Existing dir does not have correct structure: ", tmpDir);
        Validate.isTrue(FileSystemUtils.deleteRecursively(tmpDir), "Unable to remove temp dir: ", tmpDir);
        LOGGER.info("Delete existing: {}", tmpDir);
    }

    Validate.isTrue(tmpDir.mkdirs(), "Unable to create temp dir: ", tmpDir);
    LOGGER.info("Created: {}", tmpDir);
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:20,代码来源:RpslObjectsExporter.java

示例12: deserializePackageFromDatabase

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
private Package deserializePackageFromDatabase(PackageMetadata packageMetadata) {
	// package file was uploaded to a local DB hosted repository
	Path tmpDirPath = null;
	try {
		tmpDirPath = TempFileUtils.createTempDirectory("skipper");
		File targetPath = new File(tmpDirPath + File.separator + packageMetadata.getName());
		targetPath.mkdirs();
		File targetFile = PackageFileUtils.calculatePackageZipFile(packageMetadata, targetPath);
		try {
			StreamUtils.copy(packageMetadata.getPackageFile().getPackageBytes(), new FileOutputStream(targetFile));
		}
		catch (IOException e) {
			throw new SkipperException(
					"Could not copy package file for " + packageMetadata.getName() + "-"
							+ packageMetadata.getVersion() +
							" from database to target file " + targetFile,
					e);
		}
		ZipUtil.unpack(targetFile, targetPath);
		Package pkgToReturn = this.packageReader.read(new File(targetPath, packageMetadata.getName() + "-" +
				packageMetadata.getVersion()));
		pkgToReturn.setMetadata(packageMetadata);
		return pkgToReturn;
	}
	finally {
		if (tmpDirPath != null && !FileSystemUtils.deleteRecursively(tmpDirPath.toFile())) {
			logger.warn("Temporary directory can not be deleted: " + tmpDirPath);
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:31,代码来源:PackageService.java

示例13: upload

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Transactional
public PackageMetadata upload(UploadRequest uploadRequest) {
	validateUploadRequest(uploadRequest);
	Repository localRepositoryToUpload = getRepositoryToUpload(uploadRequest.getRepoName());
	Path packageDirPath = null;
	try {
		packageDirPath = TempFileUtils.createTempDirectory("skipperUpload");
		File packageDir = new File(packageDirPath + File.separator + uploadRequest.getName());
		packageDir.mkdir();
		Path packageFile = Paths
				.get(packageDir.getPath() + File.separator + uploadRequest.getName() + "-"
						+ uploadRequest.getVersion() + "." + uploadRequest.getExtension());
		Assert.isTrue(packageDir.exists(), "Package directory doesn't exist.");
		Files.write(packageFile, uploadRequest.getPackageFileAsBytes());
		ZipUtil.unpack(packageFile.toFile(), packageDir);
		String unzippedPath = packageDir.getAbsolutePath() + File.separator + uploadRequest.getName()
				+ "-" + uploadRequest.getVersion();
		File unpackagedFile = new File(unzippedPath);
		Assert.isTrue(unpackagedFile.exists(), "Package is expected to be unpacked, but it doesn't exist");
		Package packageToUpload = this.packageReader.read(unpackagedFile);
		PackageMetadata packageMetadata = packageToUpload.getMetadata();
		if (localRepositoryToUpload != null) {
			packageMetadata.setRepositoryId(localRepositoryToUpload.getId());
			packageMetadata.setRepositoryName(localRepositoryToUpload.getName());
		}
		packageMetadata.setPackageFile(new PackageFile((uploadRequest.getPackageFileAsBytes())));
		return this.packageMetadataRepository.save(packageMetadata);
	}
	catch (IOException e) {
		throw new SkipperException("Failed to upload the package.", e);
	}
	finally {
		if (packageDirPath != null && !FileSystemUtils.deleteRecursively(packageDirPath.toFile())) {
			logger.warn("Temporary directory can not be deleted: " + packageDirPath);
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:38,代码来源:PackageService.java

示例14: cleanTempFiles

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
/**
 * Clean all the temporary files that are related to this root directory.
 * @see #createDistributionFile
 */
public void cleanTempFiles(File dir) {
	List<File> tempFiles = temporaryFiles.remove(dir.getName());
	if (!tempFiles.isEmpty()) {
		tempFiles.forEach((File file) -> {
			if (file.isDirectory()) {
				FileSystemUtils.deleteRecursively(file);
			}
			else if (file.exists()) {
				file.delete();
			}
		});
	}
}
 
开发者ID:rvillars,项目名称:edoras-one-initializr,代码行数:18,代码来源:ProjectGenerator.java

示例15: deleteAll

import org.springframework.util.FileSystemUtils; //导入依赖的package包/类
@Override
public void deleteAll() {
    logger.info("开发初始化清理数据,start");
    FileSystemUtils.deleteRecursively(rootPaht.toFile());
    stringRedisTemplate.delete(Constants.FILE_UPLOAD_STATUS);
    stringRedisTemplate.delete(Constants.FILE_MD5_KEY);
    logger.info("开发初始化清理数据,end");
}
 
开发者ID:Fourwenwen,项目名称:Breakpoint-http,代码行数:9,代码来源:StorageServiceImpl.java


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