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


Java StandardCopyOption类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:itdl,项目名称:AIweb,代码行数:20,代码来源:UploadKaServiceImpl.java

示例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);
				}
			});
}
 
开发者ID:swissquote,项目名称:carnotzet,代码行数:28,代码来源:ResourcesManager.java

示例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() );
  }
}
 
开发者ID:HiromuHota,项目名称:pdi-git-plugin,代码行数:17,代码来源:SVN.java

示例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);
        }
    }
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:19,代码来源:FileCopy.java

示例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;
    }
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:27,代码来源:SiaUtil.java

示例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);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:25,代码来源:YangPluginUtils.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:GetResourceAsStream.java

示例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);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:IndexFolderUpgrader.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:Main.java

示例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();
    }
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:20,代码来源:Solc.java

示例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();
        }
    }
}
 
开发者ID:hadalhw17,项目名称:Artatawe,代码行数:20,代码来源:ProfileScene.java

示例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);
}
 
开发者ID:adbenitez,项目名称:MailCopier,代码行数:22,代码来源:MailCopier.java

示例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;
}
 
开发者ID:SAP,项目名称:cloud-ariba-partner-flow-extension-ext,代码行数:22,代码来源:EventResource.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:ClassLoaderTest.java

示例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);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:FileBasedSessionDAO.java


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