當前位置: 首頁>>代碼示例>>Java>>正文


Java DirectoryNotEmptyException類代碼示例

本文整理匯總了Java中java.nio.file.DirectoryNotEmptyException的典型用法代碼示例。如果您正苦於以下問題:Java DirectoryNotEmptyException類的具體用法?Java DirectoryNotEmptyException怎麽用?Java DirectoryNotEmptyException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DirectoryNotEmptyException類屬於java.nio.file包,在下文中一共展示了DirectoryNotEmptyException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFileSystemExceptions

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
public void testFileSystemExceptions() throws IOException {
    for (FileSystemException ex : Arrays.asList(new FileSystemException("a", "b", "c"),
        new NoSuchFileException("a", "b", "c"),
        new NotDirectoryException("a"),
        new DirectoryNotEmptyException("a"),
        new AtomicMoveNotSupportedException("a", "b", "c"),
        new FileAlreadyExistsException("a", "b", "c"),
        new AccessDeniedException("a", "b", "c"),
        new FileSystemLoopException("a"))) {

        FileSystemException serialize = serialize(ex);
        assertEquals(serialize.getClass(), ex.getClass());
        assertEquals("a", serialize.getFile());
        if (serialize.getClass() == NotDirectoryException.class ||
            serialize.getClass() == FileSystemLoopException.class ||
            serialize.getClass() == DirectoryNotEmptyException.class) {
            assertNull(serialize.getOtherFile());
            assertNull(serialize.getReason());
        } else {
            assertEquals(serialize.getClass().toString(), "b", serialize.getOtherFile());
            assertEquals(serialize.getClass().toString(), "c", serialize.getReason());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:ExceptionSerializationTests.java

示例2: clearCache

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
/**
 * Clear this ReactiveJournal's {@link #getDir() data directory} from ReactiveJournal-specific binary files, and remove it as
 * well (but only if it has become empty). If other files have been created inside the data directory, it is the
 * responsibility of the user to delete them AND the data directory.
 *
 * @throws IOException in case of directory traversal or file deletion problems
 */
public void clearCache() throws IOException {
    LOG.info("Deleting existing recording [{}]", dir);
    Path journalDir = Paths.get(dir);
    if(Files.exists(journalDir)) {
        Files.walk(journalDir)
                .map(Path::toFile)
                .filter(f -> f.isFile() && f.getName().endsWith(".cq4"))
                .peek(f -> LOG.info("Removing {}", f.getName()))
                .forEach(File::delete);

        try {
            Files.deleteIfExists(journalDir);
        } catch (DirectoryNotEmptyException e) {
            LOG.info("Directory does not only contain cq4 files, not deleted");
        }
    }
}
 
開發者ID:danielshaya,項目名稱:reactivejournal,代碼行數:25,代碼來源:ReactiveJournal.java

示例3: startProject

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
/**
 *
 * @param projectName The name of the project to create
 *
 */
public void startProject(String projectName) {
    PROJECT_NAME = projectName;
    File projectFolder = new File(projectName);
    if (projectFolder.exists()) {
        try {
            throw new DirectoryNotEmptyException(projectName);
        } catch (DirectoryNotEmptyException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        projectFolder.mkdir();
        System.out.println("Project " + projectName + " Successfully Created at " + projectFolder.getAbsolutePath());
        PROJECT_ROOT = projectFolder.getAbsolutePath() + File.separatorChar;
        createWorkingPackages(projectFolder.getAbsolutePath() + File.separatorChar);
    }

}
 
開發者ID:othreecodes,項目名稱:APX,代碼行數:23,代碼來源:Operations.java

示例4: removeRoot

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Override
public void removeRoot(String owner) throws FileSystemException {
    MCRPath rootPath = getPath(owner, "", this);
    MCRDirectory rootDirectory = MCRDirectory.getRootDirectory(owner);
    if (rootDirectory == null) {
        throw new NoSuchFileException(rootPath.toString());
    }
    if (rootDirectory.isDeleted()) {
        return;
    }
    if (rootDirectory.hasChildren()) {
        throw new DirectoryNotEmptyException(rootPath.toString());
    }
    try {
        rootDirectory.delete();
    } catch (RuntimeException e) {
        LogManager.getLogger(getClass()).warn("Catched run time exception while removing root directory.", e);
        throw new FileSystemException(rootPath.toString(), null, e.getMessage());
    }
    LogManager.getLogger(getClass()).info("Removed root directory: {}", rootPath);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:22,代碼來源:MCRIFSFileSystem.java

示例5: rename

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Override
public boolean rename(final Path src, final Path dst) throws IOException {
	final File srcFile = pathToFile(src);
	final File dstFile = pathToFile(dst);

	final File dstParent = dstFile.getParentFile();

	// Files.move fails if the destination directory doesn't exist
	//noinspection ResultOfMethodCallIgnored -- we don't care if the directory existed or was created
	dstParent.mkdirs();

	try {
		Files.move(srcFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
		return true;
	}
	catch (NoSuchFileException | AccessDeniedException | DirectoryNotEmptyException | SecurityException ex) {
		// catch the errors that are regular "move failed" exceptions and return false
		return false;
	}
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:21,代碼來源:LocalFileSystem.java

示例6: safeCopyFails

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Test(expected = DirectoryNotEmptyException.class)
public void safeCopyFails() throws Exception {
	Path tmp = Files.createTempDirectory("test");
	tmp.toFile().deleteOnExit();
	Path f1 = tmp.resolve("f1");
	f1.toFile().deleteOnExit();
	Path d1 = tmp.resolve("d1");
	d1.toFile().deleteOnExit();
	Files.createFile(f1);

	// Make d1 difficult to overwrite
	Files.createDirectory(d1);
	Files.createFile(d1.resolve("child"));

	try {
		// Files.copy(f1, d1, StandardCopyOption.REPLACE_EXISTING);
		Bundles.safeCopy(f1, d1);
	} finally {
		assertEquals(Arrays.asList("d1", "f1"), ls(tmp));
		assertTrue(Files.exists(f1));
		assertTrue(Files.isDirectory(d1));
	}
}
 
開發者ID:apache,項目名稱:incubator-taverna-language,代碼行數:24,代碼來源:TestBundles.java

示例7: delete

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
void delete(EphemeralFsPath path) throws IOException {
    synchronized(fsLock) {
        ResolvedPath resolvedPath = ResolvedPath.resolve(path, true);
        if(resolvedPath.hasTarget()) {
            INode iNode = resolvedPath.getTarget();
            if(iNode.isDir() && !iNode.isEmpty()) {
                throw new DirectoryNotEmptyException(path.toString());
            }
        }
        if(!resolvedPath.didResolve()) {
            throw new NoSuchFileException(path.toString());
        }
        if(getSettings().isWindows() && resolvedPath.getResolvedProperties().getDosIsReadOnly()) {
            throw new AccessDeniedException(path.toString());
        }
        resolvedPath.getParent().remove(resolvedPath.getPath().getFileName());
    }
    
}
 
開發者ID:sbridges,項目名稱:ephemeralfs,代碼行數:20,代碼來源:EphemeralFsFileSystem.java

示例8: testCopyDirFailsDestIfDestNotEmptyEvenWithReplaceExisting

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Test
public void testCopyDirFailsDestIfDestNotEmptyEvenWithReplaceExisting() throws Exception {
    
    Path source = root.resolve("source");
    Path dest = root.resolve("dest");
    Files.createDirectories(source);
    Files.createDirectories(dest);
    Files.createDirectories(dest.resolve("destChild"));
    
    try
    {
        Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
        fail();
    } catch(DirectoryNotEmptyException e) {
        //pass
    }
}
 
開發者ID:sbridges,項目名稱:ephemeralfs,代碼行數:18,代碼來源:CopyTest.java

示例9: testDirMoveAlreadyExistsNotEmpty

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Test
public void testDirMoveAlreadyExistsNotEmpty() throws Exception {
    Path sourceDir = Files.createDirectory(root.resolve("sourceDir"));
    Files.createFile(sourceDir.resolve("aFile"));
    
    Path targetDir = Files.createDirectory(root.resolve("targetDir"));
    Files.createFile(targetDir.resolve("aFile"));
    
    try
    {
        Files.move(sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING);
        fail();
    } catch(DirectoryNotEmptyException e) {
        //pass
    }
    
}
 
開發者ID:sbridges,項目名稱:ephemeralfs,代碼行數:18,代碼來源:MoveTest.java

示例10: execute

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Override
protected void execute(ElfinderStorage elfinderStorage, HttpServletRequest request, JSONObject json) throws Exception {
    String[] targets = request.getParameterValues(ElFinderConstants.ELFINDER_PARAMETER_TARGETS);
    List<String> removed = new ArrayList<>();

    for (String target : targets) {
        VolumeHandler vh = findTarget(elfinderStorage, target);
        try {
            vh.delete();
            removed.add(vh.getHash());
        } catch (DirectoryNotEmptyException dne) {
            json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_ERROR, "Directory not empty!");
        }


    }

    json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_REMOVED, removed.toArray());
}
 
開發者ID:trustsystems,項目名稱:elfinder-java-connector,代碼行數:20,代碼來源:RmCommand.java

示例11: parseDirectory

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
/**
 * Loads all XML files from {@code path} and calls {@link #parseFile(File)} for each one of them.
 * @param dir the directory object to scan.
 * @param recursive parses all sub folders if there is.
 * @return {@code false} if it fails to find the directory, {@code true} otherwise.
 */
protected boolean parseDirectory(File dir, boolean recursive)
{
	if (!dir.exists())
	{
		VotingRewardInterface.getInstance().logWarning(getClass().getSimpleName() + ": Folder " + dir.getAbsolutePath() + " doesn't exist!", new DirectoryNotEmptyException(dir.getAbsolutePath()));
		return false;
	}
	
	final File[] listOfFiles = dir.listFiles();
	for (File f : listOfFiles)
	{
		if (recursive && f.isDirectory())
		{
			parseDirectory(f, recursive);
		}
		else if (getCurrentFileFilter().accept(f))
		{
			parseFile(f);
		}
	}
	return true;
}
 
開發者ID:UnAfraid,項目名稱:VotingReward,代碼行數:29,代碼來源:DocumentParser.java

示例12: testDirectoryNotEmptyExceptionOnDelete

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
@Test(expected = DirectoryNotEmptyException.class)
public void testDirectoryNotEmptyExceptionOnDelete()
    throws URISyntaxException, IOException {
  // Create the directory
  URI uriDir = clusterUri
      .resolve("/tmp/testDirectoryNotEmptyExceptionOnDelete");
  Path pathDir = Paths.get(uriDir);
  // Check that directory doesn't exists
  if (Files.exists(pathDir)) {
    Files.delete(pathDir);
  }

  Files.createDirectory(pathDir);
  assertTrue(Files.exists(pathDir));
  // Create the file
  Path path = pathDir.resolve("test_file");
  Files.createFile(path);
  assertTrue(Files.exists(path));

  Files.delete(pathDir); // this one generate the exception
  assertFalse(Files.exists(path));

}
 
開發者ID:damiencarol,項目名稱:jsr203-hadoop,代碼行數:24,代碼來源:TestFileSystem.java

示例13: testCreateDirectories

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
/**
 * Test for
 * {@link Files#createDirectories(Path, java.nio.file.attribute.FileAttribute...)
 * Files.createDirectories()}.
 * 
 * @throws IOException
 */
@Test(expected = DirectoryNotEmptyException.class)
public void testCreateDirectories() throws IOException {
  Path rootPath = Paths.get(clusterUri);

  Path dir = rootPath.resolve(rootPath.resolve("tmp/1/2/3/4/5"));

  Path dir2 = Files.createDirectories(dir);
  assertTrue(Files.exists(dir2));

  Files.delete(rootPath.resolve("tmp/1/2/3/4/5"));
  Files.delete(rootPath.resolve("tmp/1/2/3/4"));
  Files.delete(rootPath.resolve("tmp/1/2/3"));
  Files.delete(rootPath.resolve("tmp/1/2"));
  // Throws
  Files.delete(rootPath.resolve("tmp"));
}
 
開發者ID:damiencarol,項目名稱:jsr203-hadoop,代碼行數:24,代碼來源:TestFiles.java

示例14: removeDirs

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
private void removeDirs(String d) {
    try {
        Files.deleteIfExists(Paths.get(PATH + SEPARATOR + d));
    } catch (IOException e) {
        if(!(e instanceof DirectoryNotEmptyException)) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:10,代碼來源:ArchiveUtilTest.java

示例15: removeFilesAndEmptyDirs

import java.nio.file.DirectoryNotEmptyException; //導入依賴的package包/類
private void removeFilesAndEmptyDirs(List<String> dirsToRetry, Map.Entry<String, String> k) {
    try {
        Files.deleteIfExists(Paths.get(PATH + SEPARATOR + k.getKey()));
    } catch (IOException e) {
        if(e instanceof DirectoryNotEmptyException) {
            dirsToRetry.add(k.getKey());
        } else {
            e.printStackTrace();
        }
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:12,代碼來源:ArchiveUtilTest.java


注:本文中的java.nio.file.DirectoryNotEmptyException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。