类java.nio.file.CopyOption源码实例Demo

下面列出了怎么用java.nio.file.CopyOption的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopyReplaceNonEmptyDirAllowedDifferentFileSystems() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");
    addFile("/baz");

    CopyOption[] options = { StandardCopyOption.REPLACE_EXISTING };
    FileSystemException exception = assertThrows(FileSystemException.class,
            () -> fileSystem.copy(createPath("/baz"), createPath(fileSystem2, "/foo"), options));
    assertEquals("/foo", exception.getFile());

    verify(getExceptionFactory()).createDeleteException(eq("/foo"), any(SftpException.class), eq(true));
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertTrue(Files.isRegularFile(getPath("/baz")));
}
 
源代码2 项目: mycore   文件: MCRFileSystemProvider.java
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
    HashSet<CopyOption> copyOptions = Sets.newHashSet(options);
    if (copyOptions.contains(StandardCopyOption.ATOMIC_MOVE)) {
        throw new AtomicMoveNotSupportedException(source.toString(), target.toString(),
            "ATOMIC_MOVE not supported yet");
    }
    if (Files.isDirectory(source)) {
        MCRPath src = MCRFileSystemUtils.checkPathAbsolute(source);
        MCRDirectory srcRootDirectory = MCRFileSystemUtils.getFileCollection(src.getOwner());
        if (srcRootDirectory.hasChildren()) {
            throw new IOException("Directory is not empty");
        }
    }
    copy(source, target, options);
    delete(source);
}
 
源代码3 项目: mycore   文件: MCRFileSystemProvider.java
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
    HashSet<CopyOption> copyOptions = Sets.newHashSet(options);
    if (copyOptions.contains(StandardCopyOption.ATOMIC_MOVE)) {
        throw new AtomicMoveNotSupportedException(source.toString(), target.toString(),
            "ATOMIC_MOVE not supported yet");
    }
    if (Files.isDirectory(source)) {
        MCRPath src = MCRFileSystemUtils.checkPathAbsolute(source);
        MCRDirectory srcRootDirectory = getRootDirectory(src);
        if (srcRootDirectory.hasChildren()) {
            throw new IOException("Directory is not empty");
        }
    }
    copy(source, target, options);
    delete(source);
}
 
源代码4 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveNonEmptyDirDifferentFileSystem() throws IOException {
    addDirectory("/foo");
    addDirectory("/baz");
    addFile("/baz/qux");

    CopyOption[] options = {};
    FileSystemException exception = assertThrows(FileSystemException.class,
            () -> fileSystem.move(createPath("/baz"), createPath(fileSystem2, "/foo/bar"), options));
    assertEquals("/baz", exception.getFile());

    verify(getExceptionFactory()).createDeleteException(eq("/baz"), any(SftpException.class), eq(true));
    assertTrue(Files.isDirectory(getPath("/baz")));
    assertTrue(Files.isRegularFile(getPath("/baz/qux")));
    assertEquals(1, getChildCount("/baz"));

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isDirectory(getPath("/foo/bar")));
    assertFalse(Files.isRegularFile(getPath("/foo/bar/qux")));
    assertEquals(1, getChildCount("/foo"));
    assertEquals(0, getChildCount("/foo/bar"));
}
 
源代码5 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveReplaceFileDifferentFileSystem() throws IOException {
    addDirectory("/foo");
    addDirectory("/foo/bar");
    addFile("/baz");

    CopyOption[] options = {};
    FileAlreadyExistsException exception = assertThrows(FileAlreadyExistsException.class,
            () -> fileSystem.move(createPath("/baz"), createPath(fileSystem2, "/foo/bar"), options));
    assertEquals("/foo/bar", exception.getFile());

    verify(getExceptionFactory(), never()).createMoveException(anyString(), anyString(), any(SftpException.class));
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isDirectory(getPath("/foo/bar")));
    assertTrue(Files.isRegularFile(getPath("/baz")));
}
 
源代码6 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopySFTPFailure() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");

    // failure: target parent does not exist

    CopyOption[] options = {};
    NoSuchFileException exception = assertThrows(NoSuchFileException.class,
            () -> fileSystem.copy(createPath("/foo/bar"), createPath("/baz/bar"), options));
    assertEquals("/baz/bar", exception.getFile());

    verify(getExceptionFactory()).createNewOutputStreamException(eq("/baz/bar"), any(SftpException.class), anyCollection());
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
    assertFalse(Files.exists(getPath("/baz/bar")));
}
 
源代码7 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopyReplaceNonEmptyDirAllowed() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");
    addFile("/baz");

    CopyOption[] options = { StandardCopyOption.REPLACE_EXISTING };
    FileSystemException exception = assertThrows(FileSystemException.class,
            () -> fileSystem.copy(createPath("/baz"), createPath("/foo"), options));
    assertEquals("/foo", exception.getFile());

    verify(getExceptionFactory()).createDeleteException(eq("/foo"), any(SftpException.class), eq(true));
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertTrue(Files.isRegularFile(getPath("/baz")));
}
 
源代码8 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveSFTPFailure() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");

    // failure: non-existing target parent

    CopyOption[] options = {};
    FileSystemException exception = assertThrows(FileSystemException.class,
            () -> fileSystem.move(createPath("/foo/bar"), createPath("/baz/bar"), options));
    assertEquals("/foo/bar", exception.getFile());
    assertEquals("/baz/bar", exception.getOtherFile());

    verify(getExceptionFactory()).createMoveException(eq("/foo/bar"), eq("/baz/bar"), any(SftpException.class));
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码9 项目: copybara   文件: CopyMoveVisitor.java
CopyMoveVisitor(Path before, Path after, @Nullable PathMatcher pathMatcher, boolean overwrite, boolean isCopy) {
  this.before = before;
  this.after = after;
  this.pathMatcher = pathMatcher;
  this.isCopy = isCopy;
  if (overwrite) {
    moveMode = new CopyOption[]{LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING};
  } else {
    moveMode = new CopyOption[]{LinkOption.NOFOLLOW_LINKS};
  }
}
 
源代码10 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveReplaceFileAllowed() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");
    addFile("/baz");

    CopyOption[] options = { StandardCopyOption.REPLACE_EXISTING };
    fileSystem.move(createPath("/baz"), createPath("/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码11 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopyReplaceEmptyDirAllowedDifferentFileSystems() throws IOException {
    addDirectory("/foo");
    addDirectory("/baz");

    CopyOption[] options = { StandardCopyOption.REPLACE_EXISTING };
    fileSystem.copy(createPath("/baz"), createPath(fileSystem2, "/foo"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isDirectory(getPath("/foo")));
}
 
源代码12 项目: marathonv5   文件: Copy.java
/**
 * Copy source file to target location.
 *
 * @return
 */
static boolean copyFile(Path source, Path target) {
    CopyOption[] options = new CopyOption[] { COPY_ATTRIBUTES, REPLACE_EXISTING };
    target = getUnique(target);
    try {
        Files.copy(source, target, options);
        return true;
    } catch (Exception x) {
        System.err.format("Unable to copy: %s: %s%n", source, x);
        return false;
    }
}
 
源代码13 项目: AndroidRipper   文件: AndroidRipperStarter.java
protected void createAPKs(String testSuitePath, String appPackage, String appMainActivity, String extractorClass,
		String toolsPath, String debugKeyStorePath, String autAPK, String tempPath) {
	// replace strings
	println("Editing 'Configuration.java'");
	replaceStringsInFile(
			testSuitePath + "/smali/it/unina/android/ripper/configuration/Configuration.smali.template",
			testSuitePath + "/smali/it/unina/android/ripper/configuration/Configuration.smali", appPackage,
			appMainActivity);
	println("Editing 'AndroidManifest.xml'");
	replaceStringsInFile(testSuitePath + "/AndroidManifest.xml.template", testSuitePath + "/AndroidManifest.xml",
			appPackage, appMainActivity);

	try {
		println("Cleaning apks...");
		println("Building AndroidRipper...");

		execCommand("java -jar " + toolsPath + "apktool.jar b " + testSuitePath + " -o " + tempPath + "/ar.apk");

		println("Signing AndroidRipper...");

		execCommand("jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore " + debugKeyStorePath
				+ "/debug.keystore -storepass android -keypass android " + tempPath + "/ar.apk androiddebugkey");
		execCommand("zipalign 4 " + tempPath + "/ar.apk " + tempPath + "/ripper.apk");

		Files.copy(FileSystems.getDefault().getPath(autAPK),
				FileSystems.getDefault().getPath(tempPath + "/temp.apk"),
				(CopyOption) StandardCopyOption.REPLACE_EXISTING);

		println("Signing AUT...");
		ZipUtils.deleteFromZip(tempPath + "/temp.apk");
		execCommand("jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore " + debugKeyStorePath
				+ "/debug.keystore -storepass android -keypass android " + tempPath
				+ "/temp.apk androiddebugkey");
		execCommand("jarsigner -verify " + tempPath + "/temp.apk");
		execCommand("zipalign -v 4 " + tempPath + "/temp.apk " + tempPath + "/aut.apk");
		
	} catch (Throwable t) {
		throw new RipperRuntimeException(AndroidRipperStarter.class, "createAPKs", "apk build failed", t);
	}
}
 
源代码14 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveNonEmptyDirSameParent() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");

    CopyOption[] options = {};
    try {
        fileSystem.move(createPath("/foo"), createPath("/baz"), options);
    } finally {
        assertFalse(Files.exists(getPath("/foo")));
        assertTrue(Files.isDirectory(getPath("/baz")));
        assertTrue(Files.isRegularFile(getPath("/baz/bar")));
    }
}
 
源代码15 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveFileDifferentFileSystem() throws IOException {
    addDirectory("/foo");
    addFile("/baz");

    CopyOption[] options = {};
    fileSystem.move(createPath("/baz"), createPath(fileSystem2, "/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码16 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveFile() throws IOException {
    addDirectory("/foo");
    addFile("/baz");

    CopyOption[] options = {};
    fileSystem.move(createPath("/baz"), createPath("/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码17 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopyEmptyDir() throws IOException {
    addDirectory("/foo");
    addDirectory("/baz");

    CopyOption[] options = {};
    fileSystem.copy(createPath("/baz"), createPath("/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isDirectory(getPath("/foo/bar")));
    assertTrue(Files.isDirectory(getPath("/baz")));

    assertEquals(0, getChildCount("/foo/bar"));
}
 
源代码18 项目: hkxpack   文件: FileUtils.java
/**
 * Convert a given resource to a temporary {@link File}.
 * @param resourceName the resource to convert
 * @return the {@link File} object pointing to the temporary File.
 * @throws Exception
 */
public static File resourceToTemporaryFile(final String resourceName) throws IOException {
	InputStream inputStream = FileUtils.class.getResourceAsStream(resourceName);
	File tempFile = File.createTempFile(resourceName, ".tmp");
    Files.copy(inputStream, tempFile.toPath(), new CopyOption[]{StandardCopyOption.REPLACE_EXISTING});
    inputStream.close();
    return tempFile;
}
 
源代码19 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveEmptyDir() throws IOException {
    addDirectory("/foo");
    addDirectory("/baz");

    CopyOption[] options = {};
    fileSystem.move(createPath("/baz"), createPath("/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isDirectory(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码20 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopyFileDifferentFileSystems() throws IOException {
    addDirectory("/foo");
    addFile("/baz");

    CopyOption[] options = {};
    fileSystem.copy(createPath("/baz"), createPath(fileSystem2, "/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertTrue(Files.isRegularFile(getPath("/baz")));
}
 
源代码21 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveReplaceEmptyDirDifferentFileSystem() throws IOException {
    addDirectory("/foo");
    addFile("/baz");

    CopyOption[] options = {};
    FileAlreadyExistsException exception = assertThrows(FileAlreadyExistsException.class,
            () -> fileSystem.move(createPath("/baz"), createPath(fileSystem2, "/foo"), options));
    assertEquals("/foo", exception.getFile());

    verify(getExceptionFactory(), never()).createMoveException(anyString(), anyString(), any(SftpException.class));
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/baz")));
}
 
源代码22 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveEmptyDirDifferentFileSystem() throws IOException {
    addDirectory("/foo");
    addDirectory("/baz");

    CopyOption[] options = {};
    fileSystem.move(createPath("/baz"), createPath(fileSystem2, "/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isDirectory(getPath("/foo/bar")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码23 项目: manifold   文件: PathUtil.java
public static boolean renameTo( Path from, Path to, CopyOption... options )
{
  try
  {
    return Files.move( from, to, options ) != null;
  }
  catch( IOException e )
  {
    return false;
  }
}
 
源代码24 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveNonEmptyRoot() throws IOException {
    addDirectory("/foo");

    CopyOption[] options = {};
    DirectoryNotEmptyException exception = assertThrows(DirectoryNotEmptyException.class,
            () -> fileSystem.move(createPath("/"), createPath("/baz"), options));
    assertEquals("/", exception.getFile());

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertFalse(Files.exists(getPath("/baz")));
}
 
源代码25 项目: mycore   文件: MCRFileSystemProvider.java
private void checkCopyOptions(CopyOption[] options) {
    for (CopyOption option : options) {
        if (!SUPPORTED_COPY_OPTIONS.contains(option)) {
            throw new UnsupportedOperationException("Unsupported copy option: " + option);
        }
    }
}
 
源代码26 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testMoveReplaceEmptyDir() throws IOException {
    addDirectory("/foo");
    addFile("/baz");

    CopyOption[] options = {};
    FileSystemException exception = assertThrows(FileSystemException.class,
            () -> fileSystem.move(createPath("/baz"), createPath("/foo"), options));
    assertEquals("/baz", exception.getFile());
    assertEquals("/foo", exception.getOtherFile());

    verify(getExceptionFactory()).createMoveException(eq("/baz"), eq("/foo"), any(SftpException.class));
    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/baz")));
}
 
源代码27 项目: baratine   文件: JFileSystemProvider.java
@Override
public void copy(Path source, Path target, CopyOption... options)
  throws IOException
{
  JPath jSource = (JPath) source;
  JPath jTarget = (JPath) target;

  try (InputStream is = jSource.getBfsFile().openRead()) {
    if (is == null) {
      throw new IOException(L.l("unable to read from file {0}", source.toUri()));
    }

    ArrayList<WriteOption> bfsOptionList = new ArrayList<>();
    for (CopyOption option : options) {
      if (option == StandardCopyOption.REPLACE_EXISTING) {
        bfsOptionList.add(WriteOption.Standard.OVERWRITE);
      }
    }

    WriteOption []bfsOptions = new WriteOption[bfsOptionList.size()];
    bfsOptionList.toArray(bfsOptions);

    try (OutputStream os = jTarget.getBfsFile().openWrite(bfsOptions)) {
      if (os == null) {
        throw new IOException(L.l("unable to write to file {0}", target.toUri()));
      }

      IoUtil.copy(is, os);
    }
  }
}
 
源代码28 项目: lucene-solr   文件: WindowsFS.java
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {
  synchronized (openFiles) {
    checkDeleteAccess(source);
    Object key = getKeyOrNull(target);
    super.move(source, target, options);
    if (key != null) {
      Object newKey = getKey(target);
      if (newKey.equals(key) == false) {
        // we need to transfer ownership here if we have open files on this file since the getKey() method will
        // return a different i-node next time we call it with the target path and our onClose method will
        // trip an assert
        Map<Path, Integer> map = openFiles.get(key);
        if (map != null) {
          Integer v = map.remove(target);
          if (v != null) {
            Map<Path, Integer> pathIntegerMap = openFiles.computeIfAbsent(newKey, k -> new HashMap<>());
            Integer existingValue = pathIntegerMap.getOrDefault(target, 0);
            pathIntegerMap.put(target, existingValue + v);
          }
          if (map.isEmpty()) {
            openFiles.remove(key);
          }
        }
      }
    }
  }
}
 
源代码29 项目: sftp-fs   文件: SFTPFileSystemTest.java
@Test
public void testCopyReplaceFileAllowedDifferentFileSystems() throws IOException {
    addDirectory("/foo");
    addFile("/foo/bar");
    addFile("/baz");

    CopyOption[] options = { StandardCopyOption.REPLACE_EXISTING };
    fileSystem.copy(createPath("/baz"), createPath(fileSystem2, "/foo/bar"), options);

    assertTrue(Files.isDirectory(getPath("/foo")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
    assertTrue(Files.isRegularFile(getPath("/foo/bar")));
}
 
源代码30 项目: lucene-solr   文件: VerboseFS.java
@Override
public void copy(Path source, Path target, CopyOption... options) throws IOException {
  Throwable exception = null;
  try {
    super.copy(source, target, options);
  } catch (Throwable t) {
    exception = t;
  } finally {
    sop("copy" + Arrays.toString(options) + ": " + path(source) + " -> " + path(target), exception);
  }
}
 
 类所在包
 同包方法