Search in sources :

Example 31 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project hadoop by apache.

the class RawLocalFileSystem method setTimes.

/**
   * Sets the {@link Path}'s last modified time and last access time to
   * the given valid times.
   *
   * @param mtime the modification time to set (only if no less than zero).
   * @param atime the access time to set (only if no less than zero).
   * @throws IOException if setting the times fails.
   */
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
    try {
        BasicFileAttributeView view = Files.getFileAttributeView(pathToFile(p).toPath(), BasicFileAttributeView.class);
        FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;
        FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;
        view.setTimes(fmtime, fatime, null);
    } catch (NoSuchFileException e) {
        throw new FileNotFoundException("File " + p + " does not exist");
    }
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) FileTime(java.nio.file.attribute.FileTime)

Example 32 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project uavstack by uavorg.

the class ReliableTaildirEventReader method getInode.

private long getInode(File file) throws IOException {
    UserDefinedFileAttributeView view = null;
    // windows system and file customer Attribute
    if (TaildirSourceConfigurationConstants.OS_WINDOWS.equals(os)) {
        // 把文件的内容属性值放置在view里面?
        view = Files.getFileAttributeView(file.toPath(), UserDefinedFileAttributeView.class);
        try {
            // view.size得到inode属性值大小
            ByteBuffer buffer = ByteBuffer.allocate(view.size(inode));
            // 把属性值放置在buffer中
            view.read(inode, buffer);
            buffer.flip();
            // 返回编码后的inode的属性值
            return Long.parseLong(Charset.defaultCharset().decode(buffer).toString());
        } catch (NoSuchFileException e) {
            long winode = random.nextLong();
            view.write(inode, Charset.defaultCharset().encode(String.valueOf(winode)));
            return winode;
        }
    }
    // 返回unix的inode的属性值
    long inode = (long) Files.getAttribute(file.toPath(), "unix:ino");
    return inode;
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) UserDefinedFileAttributeView(java.nio.file.attribute.UserDefinedFileAttributeView) ByteBuffer(java.nio.ByteBuffer)

Example 33 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j-documentation by neo4j.

the class GenerateProcedureReference method main.

public static void main(String[] args) throws IOException {
    Args arguments = Args.parse(args);
    printUsage();
    List<String> orphans = arguments.orphans();
    Path outFile = orphans.size() == 1 ? Paths.get(orphans.get(0)) : null;
    String id = arguments.has("id") || warnMissingOption("ID", "--id=my-id", DEFAULT_ID) ? arguments.get("id") : DEFAULT_ID;
    String title = arguments.has("title") || warnMissingOption("title", "--title=my-title", DEFAULT_TITLE) ? arguments.get("title") : DEFAULT_TITLE;
    String edition = arguments.has("edition") || warnMissingOption("edition", "--edition=community", DEFAULT_EDITION) ? arguments.get("edition") : DEFAULT_EDITION;
    Predicate<ProcedureReferenceGenerator.Procedure> filter = filter(arguments);
    System.out.printf("[+++] id=%s  title=%s%n", id, title);
    try {
        String doc = new ProcedureReferenceGenerator().document(id, title, edition, filter);
        if (null != outFile) {
            Path parentDir = outFile.getParent();
            if (!Files.exists(parentDir)) {
                Files.createDirectories(parentDir);
            }
            System.out.println("Saving docs in '" + outFile.toFile().getAbsolutePath() + "'.");
            Files.write(outFile, doc.getBytes());
        } else {
            System.out.println(doc);
        }
    } catch (NoSuchElementException nse) {
        nse.printStackTrace();
        throw nse;
    } catch (NoSuchFileException nsf) {
        nsf.printStackTrace();
        throw nsf;
    }
}
Also used : Path(java.nio.file.Path) Args(org.neo4j.helpers.Args) NoSuchFileException(java.nio.file.NoSuchFileException) NoSuchElementException(java.util.NoSuchElementException)

Example 34 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project neo4j-documentation by neo4j.

the class ConfigDocsTool method main.

public static void main(String[] args) throws IOException {
    Args arguments = Args.parse(args);
    printUsage();
    List<String> orphans = arguments.orphans();
    Path outFile = orphans.size() == 1 ? Paths.get(orphans.get(0)) : null;
    String id = arguments.has("id") || warnMissingOption("ID", "--id=my-id", DEFAULT_ID) ? arguments.get("id") : DEFAULT_ID;
    String title = arguments.has("title") || warnMissingOption("title", "--title=my-title", DEFAULT_TITLE) ? arguments.get("title") : DEFAULT_TITLE;
    String idPrefix = arguments.has("id-prefix") || warnMissingOption("ID prefix", "--id-prefix=my-id-prefix", DEFAULT_ID_PREFIX) ? arguments.get("id-prefix") : DEFAULT_ID_PREFIX;
    Predicate<ConfigValue> filter = filters(arguments);
    System.out.printf("[+++] id=%s  title=%s  idPrefix=%s%n", id, title, idPrefix);
    try {
        String doc = new ConfigDocsGenerator().document(filter, id, title, idPrefix);
        if (null != outFile) {
            Path parentDir = outFile.getParent();
            if (!Files.exists(parentDir)) {
                Files.createDirectories(parentDir);
            }
            System.out.println("Saving docs in '" + outFile.toFile().getAbsolutePath() + "'.");
            Files.write(outFile, doc.getBytes());
        } else {
            System.out.println(doc);
        }
    } catch (NoSuchElementException nse) {
        nse.printStackTrace();
        throw nse;
    } catch (NoSuchFileException nsf) {
        nsf.printStackTrace();
        throw nsf;
    }
}
Also used : Path(java.nio.file.Path) Args(org.neo4j.helpers.Args) ConfigValue(org.neo4j.configuration.ConfigValue) NoSuchFileException(java.nio.file.NoSuchFileException) NoSuchElementException(java.util.NoSuchElementException)

Example 35 with NoSuchFileException

use of java.nio.file.NoSuchFileException in project ddf by codice.

the class MetadataConfigurationParser method parseEntityDescriptions.

private void parseEntityDescriptions(List<String> entityDescriptions) throws IOException {
    String ddfHome = System.getProperty("ddf.home");
    for (String entityDescription : entityDescriptions) {
        buildEntityDescriptor(entityDescription);
    }
    Path metadataFolder = Paths.get(ddfHome, ETC_FOLDER, METADATA_ROOT_FOLDER);
    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(metadataFolder)) {
        for (Path path : directoryStream) {
            if (Files.isReadable(path)) {
                try (InputStream fileInputStream = Files.newInputStream(path)) {
                    EntityDescriptor entityDescriptor = readEntityDescriptor(new InputStreamReader(fileInputStream, "UTF-8"));
                    LOGGER.info("entityId = {}", entityDescriptor.getEntityID());
                    entityDescriptorMap.put(entityDescriptor.getEntityID(), entityDescriptor);
                    if (updateCallback != null) {
                        updateCallback.accept(entityDescriptor);
                    }
                }
            }
        }
    } catch (NoSuchFileException e) {
        LOGGER.debug("IDP metadata directory is not configured.", e);
    }
}
Also used : Path(java.nio.file.Path) EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) NoSuchFileException(java.nio.file.NoSuchFileException)

Aggregations

NoSuchFileException (java.nio.file.NoSuchFileException)255 IOException (java.io.IOException)103 Path (java.nio.file.Path)103 FileNotFoundException (java.io.FileNotFoundException)41 Test (org.junit.Test)35 InputStream (java.io.InputStream)30 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)25 File (java.io.File)20 NotDirectoryException (java.nio.file.NotDirectoryException)19 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)18 HashSet (java.util.HashSet)16 OutputStream (java.io.OutputStream)15 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)15 ArrayList (java.util.ArrayList)15 FileChannel (java.nio.channels.FileChannel)14 AccessDeniedException (java.nio.file.AccessDeniedException)14 HashMap (java.util.HashMap)13 Map (java.util.Map)12 ByteBuffer (java.nio.ByteBuffer)11 SeekableByteChannel (java.nio.channels.SeekableByteChannel)11