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");
}
}
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;
}
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;
}
}
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;
}
}
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);
}
}
Aggregations