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


Java NotDirectoryException類代碼示例

本文整理匯總了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;
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:18,代碼來源:ModelExporter.java

示例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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:FileUtils.java

示例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;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:Security.java

示例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());
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:ExceptionSerializationTests.java

示例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();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:JrtFileSystem.java

示例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);
    }
}
 
開發者ID:Hill30,項目名稱:amq-kahadb-tool,代碼行數:18,代碼來源:KahaDBJournalsReader.java

示例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);
    }
}
 
開發者ID:Hill30,項目名稱:amq-kahadb-tool,代碼行數:18,代碼來源:KahaDBJournalsStatistics.java

示例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();
        }
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:19,代碼來源:MCRGoogleSitemapCommon.java

示例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;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:23,代碼來源:MCRFileSystemProvider.java

示例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;
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:24,代碼來源:MCRFileSystemProvider.java

示例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();
}
 
開發者ID:William-Hai,項目名稱:JCore-UtilLibrary,代碼行數:29,代碼來源:FileSearchUtils.java

示例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();
}
 
開發者ID:William-Hai,項目名稱:JCore-UtilLibrary,代碼行數:29,代碼來源:FileSearchUtils.java

示例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;
    }
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:appengine-plugins-core,代碼行數:30,代碼來源:FilePermissions.java

示例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);
    }
}
 
開發者ID:William-Hai,項目名稱:CorpusSpider,代碼行數:20,代碼來源:ExtractionHTMLText.java

示例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);
}
 
開發者ID:wkgcass,項目名稱:Style,代碼行數:22,代碼來源:Directory.java


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