本文整理匯總了Java中java.nio.file.NotDirectoryException類的典型用法代碼示例。如果您正苦於以下問題:Java NotDirectoryException類的具體用法?Java NotDirectoryException怎麽用?Java NotDirectoryException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NotDirectoryException類屬於java.nio.file包,在下文中一共展示了NotDirectoryException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mkdirObjects
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
private File mkdirObjects(File parentOutDir, String outDirName)
throws NotDirectoryException, DirectoryException {
File objectDir = new File(parentOutDir, outDirName);
if(objectDir.exists()) {
if(!objectDir.isDirectory()) {
throw new NotDirectoryException(objectDir.getAbsolutePath());
}
} else {
if(!objectDir.mkdir()) {
throw new DirectoryException(MessageFormat.format(
"Could not create objects directory: {0}",
objectDir.getAbsolutePath()));
}
}
return objectDir;
}
示例2: findJsonSpec
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/**
* Returns the json files found within the directory provided as argument.
* Files are looked up in the classpath, or optionally from {@code fileSystem} if its not null.
*/
public static Set<Path> findJsonSpec(FileSystem fileSystem, String optionalPathPrefix, String path) throws IOException {
Path dir = resolveFile(fileSystem, optionalPathPrefix, path, null);
if (!Files.isDirectory(dir)) {
throw new NotDirectoryException(path);
}
Set<Path> jsonFiles = new HashSet<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path item : stream) {
if (item.toString().endsWith(JSON_SUFFIX)) {
jsonFiles.add(item);
}
}
}
if (jsonFiles.isEmpty()) {
throw new NoSuchFileException(path, null, "no json files found");
}
return jsonFiles;
}
示例3: ensureDirectoryExists
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/**
* Ensures configured directory {@code path} exists.
* @throws IOException if {@code path} exists, but is not a directory, not accessible, or broken symbolic link.
*/
static void ensureDirectoryExists(Path path) throws IOException {
// this isn't atomic, but neither is createDirectories.
if (Files.isDirectory(path)) {
// verify access, following links (throws exception if something is wrong)
// we only check READ as a sanity test
path.getFileSystem().provider().checkAccess(path.toRealPath(), AccessMode.READ);
} else {
// doesn't exist, or not a directory
try {
Files.createDirectories(path);
} catch (FileAlreadyExistsException e) {
// convert optional specific exception so the context is clear
IOException e2 = new NotDirectoryException(path.toString());
e2.addSuppressed(e);
throw e2;
}
}
}
示例4: testFileSystemExceptions
import java.nio.file.NotDirectoryException; //導入依賴的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());
}
}
}
示例5: iteratorOf
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/**
* returns the list of child paths of the given directory "path"
*
* @param path name of the directory whose content is listed
* @return iterator for child paths of the given directory path
*/
Iterator<Path> iteratorOf(JrtPath path, DirectoryStream.Filter<? super Path> filter)
throws IOException {
Node node = checkNode(path).resolveLink(true);
if (!node.isDirectory()) {
throw new NotDirectoryException(path.getName());
}
if (filter == null) {
return node.getChildren()
.stream()
.map(child -> (Path)(path.resolve(new JrtPath(this, child.getNameString()).getFileName())))
.iterator();
}
return node.getChildren()
.stream()
.map(child -> (Path)(path.resolve(new JrtPath(this, child.getNameString()).getFileName())))
.filter(p -> { try { return filter.accept(p);
} catch (IOException x) {}
return false;
})
.iterator();
}
示例6: showData
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
public void showData(String sourceDirPath, boolean useAnyKeyToContinue) throws NotDirectoryException {
if(isNullOrEmpty(sourceDirPath)) {
throw new NullPointerException("sourceDirPath");
}
File sourceDir = new File(sourceDirPath);
if(!sourceDir.isDirectory()) {
throw new NotDirectoryException("sourceDirPath");
}
try {
showData(sourceDir, useAnyKeyToContinue);
}
catch (Throwable throwable) {
showException(throwable);
}
}
示例7: showStatistic
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
public void showStatistic(String sourceDirPath, boolean useAnyKeyToContinue) throws NotDirectoryException {
if(isNullOrEmpty(sourceDirPath)) {
throw new NullPointerException("sourceDirPath");
}
File sourceDir = new File(sourceDirPath);
if(!sourceDir.isDirectory()) {
throw new NotDirectoryException("sourceDirPath");
}
try {
showStatistic(sourceDir, useAnyKeyToContinue);
}
catch (Throwable throwable) {
showException(throwable);
}
}
示例8: MCRGoogleSitemapCommon
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/** The constructor
* @throws NotDirectoryException */
public MCRGoogleSitemapCommon(File baseDir) throws NotDirectoryException {
if (!Objects.requireNonNull(baseDir, "baseDir may not be null.").isDirectory()) {
throw new NotDirectoryException(baseDir.getAbsolutePath());
}
this.webappBaseDir = baseDir;
LOGGER.info("Using webappbaseDir: {}", baseDir.getAbsolutePath());
objidlist = new ArrayList<>();
if ((numberOfURLs < 1) || (numberOfURLs > 50000))
numberOfURLs = 50000;
if (cdir.length() != 0) {
File sitemap_directory = new File(webappBaseDir, cdir);
if (!sitemap_directory.exists()) {
sitemap_directory.mkdirs();
}
}
}
示例9: getParentDirectory
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
private static MCRDirectory getParentDirectory(MCRPath mcrPath) throws NoSuchFileException, NotDirectoryException {
if (mcrPath.getNameCount() == 0) {
throw new IllegalArgumentException("Root component has no parent: " + mcrPath);
}
MCRDirectory rootDirectory = getRootDirectory(mcrPath);
if (mcrPath.getNameCount() == 1) {
return rootDirectory;
}
MCRPath parentPath = mcrPath.getParent();
MCRFilesystemNode parentNode = rootDirectory.getChildByPath(getAbsolutePathFromRootComponent(parentPath)
.toString());
if (parentNode == null) {
throw new NoSuchFileException(rootDirectory.toPath().toString(), getAbsolutePathFromRootComponent(mcrPath)
.toString(), "Parent directory does not exists.");
}
if (parentNode instanceof MCRFile) {
throw new NotDirectoryException(parentNode.toPath().toString());
}
MCRDirectory parentDir = (MCRDirectory) parentNode;
parentDir.getChildren();//warm-up cache
return parentDir;
}
示例10: resolvePath
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
static MCRFilesystemNode resolvePath(MCRPath path) throws IOException {
try {
String ifsid = nodeCache.getUnchecked(path);
MCRFilesystemNode node = MCRFilesystemNode.getNode(ifsid);
if (node != null) {
return node;
}
nodeCache.invalidate(path);
return resolvePath(path);
} catch (UncheckedExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoSuchFileException) {
throw (NoSuchFileException) cause;
}
if (cause instanceof NotDirectoryException) {
throw (NotDirectoryException) cause;
}
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw e;
}
}
示例11: getAllFileName
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/**
* 獲得一個文件目錄下的所有文件名稱(隻包含文件名本身)
*
* @param folderName
* 文件目錄
* @return
* 文件名稱數組
* @throws FileNameNotExistsException
* 文件名不存在異常
* @throws NotDirectoryException
* 不是目錄異常
*/
public static String[] getAllFileName(String folderName) throws FileNameNotExistsException, NotDirectoryException {
if (StringUtils.isEmpty(folderName)) {
throw new NullPointerException("目錄名為空,請輸入文件目錄");
}
File folderFile = new File(folderName);
if (!folderFile.exists()) {
throw new FileNameNotExistsException(folderName + "當前文件目錄不存在");
}
if (!folderFile.isDirectory()) {
throw new NotDirectoryException(folderName + "不是目錄");
}
return folderFile.list();
}
示例12: getAllSubFiles
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/**
* 獲得一個文件目錄下的所有文件
*
* @param folderName
* 文件目錄
* @return
* 子文件
* @throws FileNameNotExistsException
* 文件名不存在異常
* @throws NotDirectoryException
* 不是目錄異常
*/
public static File[] getAllSubFiles(String folderName) throws FileNameNotExistsException, NotDirectoryException {
if (StringUtils.isEmpty(folderName)) {
throw new NullPointerException("目錄名為空,請輸入文件目錄");
}
File folderFile = new File(folderName);
if (!folderFile.exists()) {
throw new FileNameNotExistsException(folderName + "當前文件目錄不存在");
}
if (!folderFile.isDirectory()) {
throw new NotDirectoryException(folderName + "不是目錄");
}
return folderFile.listFiles();
}
示例13: verifyDirectoryCreatable
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
/**
* Check whether the current process can create a directory at the specified path. This is useful
* for providing immediate feedback to an end user that a path they have selected or typed may not
* be suitable before attempting to create the directory; e.g. in a tooltip.
*
* @param path tentative location for directory
* @throws AccessDeniedException if a directory in the path is not writable
* @throws NotDirectoryException if a segment of the path is a file
*/
public static void verifyDirectoryCreatable(Path path)
throws AccessDeniedException, NotDirectoryException {
for (Path segment = path; segment != null; segment = segment.getParent()) {
if (Files.exists(segment)) {
if (Files.isDirectory(segment)) {
// Can't create a directory if the bottom most currently existing directory in
// the path is not writable.
if (!Files.isWritable(segment)) {
throw new AccessDeniedException(segment + " is not writable");
}
} else {
// Can't create a directory if a non-directory file already exists with that name
// somewhere in the path.
throw new NotDirectoryException(segment + " is a file");
}
break;
}
}
}
示例14: parserURL
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
private void parserURL() throws NotDirectoryException, FileNameNotExistsException {
String[] fileNames = FileSearchUtils.getAllFileName(Constants.RAW_PATH);
for (String fileName : fileNames) {
try {
AtomicInteger urlIndex = new AtomicInteger(0);
List<String> urList = FileReadUtils.readLines(Constants.RAW_PATH + fileName);
for (String url : urList) {
mPool.submit(new ParserHTMLRunnable(splitWordUtils, url, FileUtils.removeSuffixName(fileName), StringUtils.formatIntegerString(urlIndex.get(), "#00000")), 3000);
urlIndex.incrementAndGet();
ThreadUtils.sleep(50);
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("" + fileName);
}
}
示例15: mkdir
import java.nio.file.NotDirectoryException; //導入依賴的package包/類
public Directory mkdir(String dir) throws FileAlreadyExistsException, FileOperationFailedException {
dir = dir.trim();
try {
cd(dir);
} catch (FileNotFoundException e) {
File f;
if (dir.startsWith("/")) {
f = new File(dir);
} else {
f = new File(fullPath() + dir);
}
if (!f.mkdir()) throw new FileOperationFailedException("mkdir " + dir);
try {
return new Directory(f);
} catch (FileNotFoundException | NotDirectoryException e1) {
throw Style.$(e1);
}
} catch (NotDirectoryException ignore) {
}
throw new FileAlreadyExistsException(fullPath() + " " + dir);
}