本文整理匯總了Java中java.nio.file.StandardCopyOption類的典型用法代碼示例。如果您正苦於以下問題:Java StandardCopyOption類的具體用法?Java StandardCopyOption怎麽用?Java StandardCopyOption使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StandardCopyOption類屬於java.nio.file包,在下文中一共展示了StandardCopyOption類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: store
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
@Override
public void store(MultipartFile file) {
String filename = StringUtils.cleanPath(file.getOriginalFilename());
try {
if (file.isEmpty()) {
throw new UploadException("Failed to store empty file " + filename);
}
if (filename.contains("..")) {
// This is a security check
throw new UploadException(
"Cannot store file with relative path outside current directory "
+ filename);
}
Files.copy(file.getInputStream(), this.rootLocation.resolve(filename),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new UploadException("Failed to store file " + filename, e);
}
}
示例2: copyOwnResources
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
/**
* Copies the resources from the specified module that affects itself. Resources that affect dependencies of the
* specified module are not copied.
*/
private void copyOwnResources(List<CarnotzetModule> processedModules, CarnotzetModule module) throws IOException {
Path expandedJarPath = expandedJars.resolve(module.getName());
Path resolvedModulePath = resolved.resolve(module.getServiceId());
if (!resolvedModulePath.toFile().exists() && !resolvedModulePath.toFile().mkdirs()) {
throw new CarnotzetDefinitionException("Could not create directory " + resolvedModulePath);
}
// copy all regular files at the root of the expanded jar (such as carnotzet.properties)
// copy all directories that do not reconfigure another module from the expanded jar recursively
Files.find(expandedJarPath, 1, isRegularFile().or(nameMatchesModule(processedModules).negate()))
.forEach(source -> {
try {
if (Files.isRegularFile(source)) {
Files.copy(source, resolvedModulePath.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING);
} else if (Files.isDirectory(source)) {
FileUtils.copyDirectory(source.toFile(), resolvedModulePath.resolve(source.getFileName()).toFile());
}
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
});
}
示例3: add
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
@Override
public void add( String name ) {
try {
if ( name.matches( ".*\\.mine$|.*\\.r\\d+$" ) ) { // Resolve a conflict
File conflicted = new File( directory + File.separator + FilenameUtils.separatorsToSystem( FilenameUtils.removeExtension( name ) ) );
FileUtils.rename( new File( directory, name ),
conflicted,
StandardCopyOption.REPLACE_EXISTING );
svnClient.resolved( conflicted );
} else {
svnClient.addFile( new File( directory, name ) );
}
} catch ( Exception e ) {
showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
}
}
示例4: copyFilesInDirectory
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
public static final void copyFilesInDirectory(File from, File to) throws IOException
{
if (!to.exists())
{
to.mkdirs();
}
for (File file : from.listFiles())
{
if (file.isDirectory())
{
copyFilesInDirectory(file, new File(to.getAbsolutePath() + "/" + file.getName()));
} else
{
File n = new File(to.getAbsolutePath() + "/" + file.getName());
Files.copy(file.toPath(), n.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
示例5: download
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
public boolean download(String siaPath, Path destination) {
LOGGER.info("downloading {}", siaPath);
// final String dest = destination.toAbsolutePath().toString();
final FileTime lastModified = SiaFileUtil.getFileTime(siaPath);
final String tempFileName = destination.getFileName().toString() + ".tempdownload";
Path tempFile = destination.getParent().resolve(tempFileName);
final HttpResponse<String> downloadResult = siaCommand(SiaCommand.DOWNLOAD, ImmutableMap.of("destination", tempFile.toAbsolutePath().toString()), siaPath);
final boolean noHosts = checkErrorFragment(downloadResult, NO_HOSTS);
if (noHosts) {
LOGGER.warn("unable to download file {} due to NO_HOSTS ", siaPath);
return false;
}
if (statusGood(downloadResult)) {
try {
Files.setLastModifiedTime(tempFile, lastModified);
Files.move(tempFile, destination, StandardCopyOption.ATOMIC_MOVE);
Files.setLastModifiedTime(destination, lastModified);
} catch (IOException e) {
throw new RuntimeException("unable to do atomic swap of file " + destination);
}
return true;
}
LOGGER.warn("unable to download siaPath {} for an unexpected reason: {} ", siaPath, downloadResult.getBody());
return false;
}
示例6: copyYangFilesToTarget
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
/**
* Copies YANG files to the current project's output directory.
*
* @param yangFileInfo list of YANG files
* @param outputDir project's output directory
* @param project maven project
* @throws IOException when fails to copy files to destination resource directory
*/
public static void copyYangFilesToTarget(Set<YangFileInfo> yangFileInfo, String outputDir, MavenProject project)
throws IOException {
List<File> files = getListOfFile(yangFileInfo);
String path = outputDir + TARGET_RESOURCE_PATH;
File targetDir = new File(path);
targetDir.mkdirs();
for (File file : files) {
Files.copy(file.toPath(),
new File(path + file.getName()).toPath(),
StandardCopyOption.REPLACE_EXISTING);
}
addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
}
示例7: setup
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
/**
* Prepare jars files for the tests
*/
private static void setup () throws IOException {
Path classes = Paths.get(WORK_DIR);
Path testSrc = Paths.get(System.getProperty("test.src"),
"test1", "com", "foo", "TestClass.java");
Path targetDir = classes.resolve("test3");
Path testTarget = targetDir.resolve("TestClass.java");
Files.createDirectories(targetDir);
Files.copy(testSrc, testTarget, StandardCopyOption.REPLACE_EXISTING);
// Compile sources for corresponding test
CompilerUtils.compile(targetDir, targetDir);
// Prepare txt files
Files.write(targetDir.resolve("hello.txt"), "Hello world".getBytes(),
StandardOpenOption.CREATE);
Files.write(targetDir.resolve("bye.txt"), "Bye world".getBytes(),
StandardOpenOption.CREATE);
// Create jar
JarUtils.createJarFile(classes.resolve("foo.jar"), targetDir);
}
示例8: upgrade
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
/**
* Moves the index folder found in <code>source</code> to <code>target</code>
*/
void upgrade(final Index index, final Path source, final Path target) throws IOException {
boolean success = false;
try {
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
success = true;
} catch (NoSuchFileException | FileNotFoundException exception) {
// thrown when the source is non-existent because the folder was renamed
// by another node (shared FS) after we checked if the target exists
logger.error((Supplier<?>) () -> new ParameterizedMessage("multiple nodes trying to upgrade [{}] in parallel, retry " +
"upgrading with single node", target), exception);
throw exception;
} finally {
if (success) {
logger.info("{} moved from [{}] to [{}]", index, source, target);
logger.trace("{} syncing directory [{}]", index, target);
IOUtils.fsync(target, true);
}
}
}
示例9: validateAndClose
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
private void validateAndClose(File tmpfile) throws IOException {
if (ok && isMultiRelease) {
try (JarFile jf = new JarFile(tmpfile)) {
ok = Validator.validate(this, jf);
if (!ok) {
error(formatMsg("error.validator.jarfile.invalid", fname));
}
} catch (IOException e) {
error(formatMsg2("error.validator.jarfile.exception", fname, e.getMessage()));
}
}
Path path = tmpfile.toPath();
try {
if (ok) {
if (fname != null) {
Files.move(path, Paths.get(fname), StandardCopyOption.REPLACE_EXISTING);
} else {
Files.copy(path, new FileOutputStream(FileDescriptor.out));
}
}
} finally {
Files.deleteIfExists(path);
}
}
示例10: initBundled
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
private void initBundled() throws IOException {
File tmpDir = new File(System.getProperty("java.io.tmpdir"), "solc");
tmpDir.mkdirs();
InputStream is = getClass().getResourceAsStream("/native/" + getOS() + "/solc/file.list");
Scanner scanner = new Scanner(is);
while (scanner.hasNext()) {
String s = scanner.next();
File targetFile = new File(tmpDir, s);
InputStream fis = getClass().getResourceAsStream("/native/" + getOS() + "/solc/" + s);
Files.copy(fis, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
if (solc == null) {
// first file in the list denotes executable
solc = targetFile;
solc.setExecutable(true);
}
targetFile.deleteOnExit();
}
}
示例11: changeImage
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
/**
* Loads image from file system and sets it as avatar
* @param f image which is needed to be set as avatar
*/
private void changeImage(File f){
if(f != null) {
try{
Files.copy(f
.toPath(), new File("data/avatars/"+p
.getUsername()+"Avatar.png")
.toPath(), StandardCopyOption.REPLACE_EXISTING
);
p.setProfileImg(new Picture("file:data/avatars/"+p.getUsername()+"Avatar.png"));
dc.save();
} catch (Exception e){
e.printStackTrace();
}
}
}
示例12: send_errors_report
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
public void send_errors_report() throws MessagingException, IOException {
String log_file = pManager.get_Log_File_Path();
Path logf = Paths.get(log_file);
String attach = log_file + ".report";
Path report = Paths.get(attach);
try {
if (log_file != null && Files.exists(logf)) {
if (transport == null || !transport.isConnected()) {
senderConnect();
}
Files.copy(logf, report, StandardCopyOption.REPLACE_EXISTING);
String[] to = {pManager.getSupportEmail()};
sendMultipartMessage("Errors Report", to, "", attach);
}
} catch (Exception ex) {
Files.deleteIfExists(report);
throw ex;
}
Files.deleteIfExists(report);
}
示例13: downloadDocument
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
@GET
@Path(DOWNLOAD_DOCUMENT_API)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadDocument(@PathParam(PARAMETER_EVENT_ID) String eventId,
@QueryParam(QUERY_PARAMETER_PATH) String path) {
Response response = null;
try {
Document document = documentDao.findByPath(path);
InputStream inputStream = document.getContentStream().getStream();
File file = new File(document.getName());
Files.copy(inputStream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
response = Response.status(Response.Status.OK)
.header(HEADER_CONTENT_DISPOSITION, "attachment; filename=" + file.getName()).entity(file).build();
} catch (IOException e) {
logger.error(ERROR_PROBLEM_OCCURED_WHILE_DOWNLOADING_DOCUMENT, e);
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
return response;
}
示例14: setUp
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
/**
* Creates regular/modular jar files for TestClient and TestClassLoader.
*/
private static void setUp() throws Exception {
// Generate regular jar files for TestClient and TestClassLoader
JarUtils.createJarFile(CL_JAR, TEST_CLASSES,
"cl/TestClassLoader.class");
JarUtils.createJarFile(C_JAR, TEST_CLASSES,
"c/TestClient.class");
// Generate modular jar files for TestClient and TestClassLoader with
// their corresponding ModuleDescriptor.
Files.copy(CL_JAR, MCL_JAR,
StandardCopyOption.REPLACE_EXISTING);
updateModuleDescr(MCL_JAR, ModuleDescriptor.newModule("mcl")
.exports("cl").requires("java.base").build());
Files.copy(C_JAR, MC_JAR,
StandardCopyOption.REPLACE_EXISTING);
updateModuleDescr(MC_JAR, ModuleDescriptor.newModule("mc")
.exports("c").requires("java.base").requires("mcl").build());
Files.copy(C_JAR, AMC_JAR,
StandardCopyOption.REPLACE_EXISTING);
updateModuleDescr(AMC_JAR, ModuleDescriptor.newModule("mc")
.exports("c").requires("java.base").requires("cl").build());
}
示例15: update
import java.nio.file.StandardCopyOption; //導入依賴的package包/類
@Override
public void update(Session session) {
final String sessionId = ensureStringSessionId(session);
final Path oldPath = sessionId2Path(sessionId);
if (!Files.exists(oldPath)) {
throw new UnknownSessionException(sessionId);
}
try {
final Path newPath = Files.createTempFile(tmpDir, null, null);
Files.write(newPath, serialize(session));
Files.move(newPath, oldPath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new SerializationException(e);
}
}