java.nio.file.NoSuchFileException Java Examples
The following examples show how to use
java.nio.file.NoSuchFileException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestZipFS.java From incubator-taverna-language with Apache License 2.0 | 6 votes |
@Test public void setLastModifiedTime() throws Exception { Path root = fs.getRootDirectories().iterator().next(); Path folder = root.resolve("folder"); Files.createDirectory(folder); Path file = root.resolve("file"); Files.createFile(file); FileTime someTimeAgo = FileTime.from(365 * 12, TimeUnit.DAYS); Files.setLastModifiedTime(folder, someTimeAgo); Files.setLastModifiedTime(file, someTimeAgo); try { Files.setLastModifiedTime(root, someTimeAgo); } catch (NoSuchFileException ex) { System.err .println("Unexpected failure of setLastModifiedTime on root"); ex.printStackTrace(); } }
Example #2
Source File: FileSystemMonitor.java From singer with Apache License 2.0 | 6 votes |
/** * Handle the modified event. We can ignore the changes in watermark files that * starts with '.' character. * @throws IOException */ private void handleEntryModifyEvent(Path logDir , Path modified ) throws IOException { Path fullPath = logDir.resolve(modified); long inode; try { inode = SingerUtils.getFileInode(fullPath); } catch(NoSuchFileException e) { LOG.warn("Failed to get inode info for " + fullPath, e); return; } List<LogStream> logStreams = LogStreamManager.getLogStreamsFor(logDir, fullPath); for (LogStream stream : logStreams) { if (stream != null) { stream.append(new LogFile(inode), fullPath.toString()); } else if (!modified.toString().startsWith(".")) { LOG.debug("Found a file {} that is not in any log stream", modified); } } }
Example #3
Source File: BlobStoreRepository.java From crate with Apache License 2.0 | 6 votes |
/** * Get the latest snapshot index blob id. Snapshot index blobs are named index-N, where N is * the next version number from when the index blob was written. Each individual index-N blob is * only written once and never overwritten. The highest numbered index-N blob is the latest one * that contains the current snapshots in the repository. * * Package private for testing */ long latestIndexBlobId() throws IOException { try { // First, try listing all index-N blobs (there should only be two index-N blobs at any given // time in a repository if cleanup is happening properly) and pick the index-N blob with the // highest N value - this will be the latest index blob for the repository. Note, we do this // instead of directly reading the index.latest blob to get the current index-N blob because // index.latest is not written atomically and is not immutable - on every index-N change, // we first delete the old index.latest and then write the new one. If the repository is not // read-only, it is possible that we try deleting the index.latest blob while it is being read // by some other operation (such as the get snapshots operation). In some file systems, it is // illegal to delete a file while it is being read elsewhere (e.g. Windows). For read-only // repositories, we read for index.latest, both because listing blob prefixes is often unsupported // and because the index.latest blob will never be deleted and re-written. return listBlobsToGetLatestIndexId(); } catch (UnsupportedOperationException e) { // If its a read-only repository, listing blobs by prefix may not be supported (e.g. a URL repository), // in this case, try reading the latest index generation from the index.latest blob try { return readSnapshotIndexLatestBlob(); } catch (NoSuchFileException nsfe) { return RepositoryData.EMPTY_REPO_GEN; } } }
Example #4
Source File: BlockDeviceSize.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { try (FileChannel ch = FileChannel.open(BLK_PATH, READ); RandomAccessFile file = new RandomAccessFile(BLK_FNAME, "r")) { long size1 = ch.size(); long size2 = file.length(); if (size1 != size2) { throw new RuntimeException("size differs when retrieved" + " in different ways: " + size1 + " != " + size2); } System.out.println("OK"); } catch (NoSuchFileException nsfe) { System.err.println("File " + BLK_FNAME + " not found." + " Skipping test"); } catch (AccessDeniedException ade) { System.err.println("Access to " + BLK_FNAME + " is denied." + " Run test as root."); } }
Example #5
Source File: DirectoryManifest.java From genie with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public FileVisitResult visitFileFailed(final Path file, final IOException ioe) { if (ioe instanceof FileSystemLoopException) { log.warn("Detected file system cycle visiting while visiting {}. Skipping.", file); return FileVisitResult.SKIP_SUBTREE; } else if (ioe instanceof AccessDeniedException) { log.warn("Access denied for file {}. Skipping", file); return FileVisitResult.SKIP_SUBTREE; } else if (ioe instanceof NoSuchFileException) { log.warn("File or directory disappeared while visiting {}. Skipping", file); return FileVisitResult.SKIP_SUBTREE; } else { log.error("Got unknown error {} while visiting {}. Terminating visitor", ioe.getMessage(), file, ioe); // TODO: Not sure if we should do this or skip subtree or just continue and ignore it? return FileVisitResult.TERMINATE; } }
Example #6
Source File: AppendToTest.java From cactoos with MIT License | 6 votes |
/** * Ensures that AppendTo is failing on a negative predicate result. */ @Test public void failsIfFileDoesNotExist() { final File source = new File( new Randomized( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' ).asString() ); new Assertion<>( "Can't throw exception with proper message", () -> new AppendTo(source).stream(), new Throws<>( source.getPath(), NoSuchFileException.class ) ).affirm(); }
Example #7
Source File: BlobStoreRepository.java From crate with Apache License 2.0 | 6 votes |
private RepositoryData getRepositoryData(long indexGen) { if (indexGen == RepositoryData.EMPTY_REPO_GEN) { return RepositoryData.EMPTY; } try { final String snapshotsIndexBlobName = INDEX_FILE_PREFIX + Long.toString(indexGen); RepositoryData repositoryData; // EMPTY is safe here because RepositoryData#fromXContent calls namedObject try (InputStream blob = blobContainer().readBlob(snapshotsIndexBlobName); XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, blob)) { repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen); } return repositoryData; } catch (NoSuchFileException ex) { // repository doesn't have an index blob, its a new blank repo return RepositoryData.EMPTY; } catch (IOException ioe) { throw new RepositoryException(metadata.name(), "could not read repository data from index blob", ioe); } }
Example #8
Source File: BlockDeviceSize.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { try (FileChannel ch = FileChannel.open(BLK_PATH, READ); RandomAccessFile file = new RandomAccessFile(BLK_FNAME, "r")) { long size1 = ch.size(); long size2 = file.length(); if (size1 != size2) { throw new RuntimeException("size differs when retrieved" + " in different ways: " + size1 + " != " + size2); } System.out.println("OK"); } catch (NoSuchFileException nsfe) { System.err.println("File " + BLK_FNAME + " not found." + " Skipping test"); } catch (AccessDeniedException ade) { System.err.println("Access to " + BLK_FNAME + " is denied." + " Run test as root."); } }
Example #9
Source File: TestDirectoryReader.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testOpenReaderAfterDelete() throws IOException { Path dirFile = createTempDir("deletetest"); Directory dir = newFSDirectory(dirFile); if (dir instanceof BaseDirectoryWrapper) { ((BaseDirectoryWrapper)dir).setCheckIndexOnClose(false); // we will hit NoSuchFileException in MDW since we nuked it! } expectThrowsAnyOf(Arrays.asList(FileNotFoundException.class, NoSuchFileException.class), () -> DirectoryReader.open(dir) ); IOUtils.rm(dirFile); // Make sure we still get a CorruptIndexException (not NPE): expectThrowsAnyOf(Arrays.asList(FileNotFoundException.class, NoSuchFileException.class), () -> DirectoryReader.open(dir) ); dir.close(); }
Example #10
Source File: S_Data.java From rdf-delta with Apache License 2.0 | 6 votes |
@Override protected void executeAction(DeltaAction action) throws IOException { LOG.info("GET "+action.getURL()); Id dsRef = Id.fromString(action.httpArgs.datasourceName); String filenameIRI = determineData(action, dsRef); ContentType ct = RDFLanguages.guessContentType(filenameIRI) ; String fn = IRILib.IRIToFilename(filenameIRI); Path path = Paths.get(fn); try ( InputStream in = Files.newInputStream(path) ) { action.response.setStatus(HttpSC.OK_200); action.response.setContentType(ct.getContentTypeStr()); IOUtils.copy(in, action.response.getOutputStream()); } catch (NoSuchFileException | FileNotFoundException ex) { throw new DeltaNotFoundException(action.getURL()); } }
Example #11
Source File: StackedFileHashCacheTest.java From buck with Apache License 2.0 | 6 votes |
@Test public void skipsFirstCacheBecauseIgnoredForArchiveMemberPathAbsolutePath() throws IOException { Config config = ConfigBuilder.createFromText("[project]", "ignore = world.jar"); Path fullPath = Paths.get("world.jar"); ProjectFilesystem filesystem = TestProjectFilesystems.createProjectFilesystem(tmp.getRoot(), config); writeJarWithHashes(filesystem, filesystem.resolve(fullPath)); ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(filesystem.resolve(fullPath), Paths.get("Nonexistent.class")); ProjectFileHashCache innerCache = DefaultFileHashCache.createDefaultFileHashCache(filesystem, fileHashCacheMode); StackedFileHashCache cache = new StackedFileHashCache(ImmutableList.of(innerCache)); expectedException.expect(NoSuchFileException.class); cache.getForArchiveMember( archiveMemberPath.getArchivePath(), archiveMemberPath.getMemberPath()); }
Example #12
Source File: BlockDeviceSize.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { try (FileChannel ch = FileChannel.open(BLK_PATH, READ); RandomAccessFile file = new RandomAccessFile(BLK_FNAME, "r")) { long size1 = ch.size(); long size2 = file.length(); if (size1 != size2) { throw new RuntimeException("size differs when retrieved" + " in different ways: " + size1 + " != " + size2); } System.out.println("OK"); } catch (NoSuchFileException nsfe) { System.err.println("File " + BLK_FNAME + " not found." + " Skipping test"); } catch (AccessDeniedException ade) { System.err.println("Access to " + BLK_FNAME + " is denied." + " Run test as root."); } }
Example #13
Source File: AppleToolchainDiscovery.java From buck with Apache License 2.0 | 6 votes |
private static void addIdentifierForToolchain( Path toolchainDir, ImmutableMap.Builder<String, AppleToolchain> identifierToToolchainBuilder) throws IOException { boolean addedToolchain = false; String[] potentialPlistNames = {"ToolchainInfo.plist", "Info.plist"}; for (String plistName : potentialPlistNames) { try { Optional<AppleToolchain> toolchain = toolchainFromPlist(toolchainDir, plistName); if (toolchain.isPresent()) { identifierToToolchainBuilder.put(toolchain.get().getIdentifier(), toolchain.get()); addedToolchain = true; break; } } catch (FileNotFoundException | NoSuchFileException e) { LOG.debug("Loading toolchain from plist %s for %s failed", plistName, toolchainDir); } } if (!addedToolchain) { LOG.debug( "Failed to resolve info about toolchain %s from plist files %s", toolchainDir.toString(), Arrays.toString(potentialPlistNames)); } }
Example #14
Source File: UnpackHelper.java From Launcher with GNU General Public License v3.0 | 6 votes |
public static boolean unpackZipNoCheck(String resource, Path target) throws IOException { try { if (Files.isDirectory(target)) return false; Files.deleteIfExists(target); Files.createDirectory(target); try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL(resource))) { for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { if (entry.isDirectory()) continue; // Skip dirs // Unpack file IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName()))); } } return true; } catch (NoSuchFileException e) { return true; } }
Example #15
Source File: MCRIView2Tools.java From mycore with GNU General Public License v3.0 | 6 votes |
public static int getImageType(Path iviewFileRoot, ImageReader imageReader, int zoomLevel, int x, int y) throws IOException { String tileName = new MessageFormat("{0}/{1}/{2}.jpg", Locale.ROOT).format(new Object[] { zoomLevel, y, x }); Path tile = iviewFileRoot.resolve(tileName); if (Files.exists(tile)) { try (SeekableByteChannel fileChannel = Files.newByteChannel(tile)) { ImageInputStream iis = ImageIO.createImageInputStream(fileChannel); if (iis == null) { throw new IOException("Could not acquire ImageInputStream from SeekableByteChannel: " + tile); } imageReader.setInput(iis, true); int imageType = MCRImage.getImageType(imageReader); imageReader.reset(); iis.close(); return imageType; } } else { throw new NoSuchFileException(iviewFileRoot.toString(), tileName, null); } }
Example #16
Source File: SFTPFileSystem.java From sftp-fs with Apache License 2.0 | 6 votes |
@SuppressWarnings("resource") private SFTPAttributesAndOutputStreamPair newOutputStream(Channel channel, SFTPPath path, boolean requireAttributes, OpenOptions options) throws IOException { // retrieve the attributes unless create is true and createNew is false, because then the file can be created SftpATTRS attributes = null; if (!options.create || options.createNew) { attributes = findAttributes(channel, path, false); if (attributes != null && attributes.isDir()) { throw Messages.fileSystemProvider().isDirectory(path.path()); } if (!options.createNew && attributes == null) { throw new NoSuchFileException(path.path()); } else if (options.createNew && attributes != null) { throw new FileAlreadyExistsException(path.path()); } } // else the file can be created if necessary if (attributes == null && requireAttributes) { attributes = findAttributes(channel, path, false); } OutputStream out = channel.newOutputStream(path.path(), options); return new SFTPAttributesAndOutputStreamPair(attributes, out); }
Example #17
Source File: DiskChunk.java From InflatableDonkey with MIT License | 6 votes |
Optional<InputStream> doInputStream() throws IOException { try { InputStream is = Files.newInputStream(file, READ); if (logger.isTraceEnabled()) { logger.trace("-- doInputStream() - open: {}", Hex.toHexString(checksum())); IOConsumer<InputStream> callback = u -> logger.trace("-- doInputStream() - callback close: {}", Hex.toHexString(checksum())); is = new HookInputStream(is, callback); } return Optional.of(is); } catch (NoSuchFileException ex) { logger.warn("-- doInputStream() - file was just deleted: {}", ex); return Optional.empty(); } }
Example #18
Source File: FileSystemStorage.java From pravega with Apache License 2.0 | 6 votes |
private <T> T throwException(String segmentName, Exception e) throws StreamSegmentException { if (e instanceof NoSuchFileException || e instanceof FileNotFoundException) { throw new StreamSegmentNotExistsException(segmentName); } if (e instanceof FileAlreadyExistsException) { throw new StreamSegmentExistsException(segmentName); } if (e instanceof IndexOutOfBoundsException) { throw new IllegalArgumentException(e.getMessage()); } if (e instanceof AccessControlException || e instanceof AccessDeniedException || e instanceof NonWritableChannelException) { throw new StreamSegmentSealedException(segmentName, e); } throw Exceptions.sneakyThrow(e); }
Example #19
Source File: LocalFileSystem.java From flink with Apache License 2.0 | 6 votes |
@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; } }
Example #20
Source File: AbstractBuildPackageComputationTest.java From buck with Apache License 2.0 | 6 votes |
@Test @Parameters(method = "getAnyPathParams") public void throwsIfNamedDirectoryAncestorIsRegularFile(Kind kind, String targetName) throws ExecutionException, InterruptedException, IOException { filesystem.createNewFile(Paths.get("file")); BuildTargetPatternToBuildPackagePathKey key = key(CanonicalCellName.rootCell(), kind, "file/dir", targetName); thrown.expect(ExecutionException.class); thrown.expectCause( Matchers.anyOf( IsInstanceOf.instanceOf(NoSuchFileException.class), IsInstanceOf.instanceOf(NotDirectoryException.class))); transform("BUCK", key); }
Example #21
Source File: Cube.java From datakernel with Apache License 2.0 | 6 votes |
@Override public Promise<QueryResult> query(CubeQuery cubeQuery) throws QueryException { DefiningClassLoader queryClassLoader = getQueryClassLoader(new CubeClassLoaderCache.Key( new LinkedHashSet<>(cubeQuery.getAttributes()), new LinkedHashSet<>(cubeQuery.getMeasures()), cubeQuery.getWhere().getDimensions())); long queryStarted = eventloop.currentTimeMillis(); return new RequestContext<>().execute(queryClassLoader, cubeQuery) .whenComplete((queryResult, e) -> { if (e == null) { queryTimes.recordValue((int) (eventloop.currentTimeMillis() - queryStarted)); } else { queryErrors++; queryLastError = e; if (e instanceof NoSuchFileException) { logger.warn("Query failed because of NoSuchFileException. " + cubeQuery.toString(), e); } } }); }
Example #22
Source File: BlockDeviceSize.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { try (FileChannel ch = FileChannel.open(BLK_PATH, READ); RandomAccessFile file = new RandomAccessFile(BLK_FNAME, "r")) { long size1 = ch.size(); long size2 = file.length(); if (size1 != size2) { throw new RuntimeException("size differs when retrieved" + " in different ways: " + size1 + " != " + size2); } System.out.println("OK"); } catch (NoSuchFileException nsfe) { System.err.println("File " + BLK_FNAME + " not found." + " Skipping test"); } catch (AccessDeniedException ade) { System.err.println("Access to " + BLK_FNAME + " is denied." + " Run test as root."); } }
Example #23
Source File: ChunkUtils.java From hadoop-ozone with Apache License 2.0 | 6 votes |
private static ContainerProtos.Result translate(Exception cause) { if (cause instanceof FileNotFoundException || cause instanceof NoSuchFileException) { return UNABLE_TO_FIND_CHUNK; } if (cause instanceof IOException) { return IO_EXCEPTION; } if (cause instanceof NoSuchAlgorithmException) { return NO_SUCH_ALGORITHM; } return CONTAINER_INTERNAL_ERROR; }
Example #24
Source File: StackedFileHashCache.java From buck with Apache License 2.0 | 5 votes |
@Override public long getSize(Path path) throws IOException { Optional<Pair<ProjectFileHashCache, Path>> found = lookup(path); if (!found.isPresent()) { throw new NoSuchFileException(path.toString()); } return found.get().getFirst().getSize(found.get().getSecond()); }
Example #25
Source File: ConsoleOutView.java From gocd with Apache License 2.0 | 5 votes |
@Override public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType(getContentType()); response.setCharacterEncoding(charset.name()); try (final PrintWriter writer = response.getWriter()) { try { consumer.stream(line -> writer.write(line + "\n")); } catch (FileNotFoundException | NoSuchFileException e) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } finally { consumer.close(); } }
Example #26
Source File: Command.java From digdag with Apache License 2.0 | 5 votes |
protected Properties loadSystemProperties() throws IOException { // Property order of precedence: // 1. Explicit configuration file (if --config was specified) // 2. JVM System properties (-D...) // 3. DIGDAG_CONFIG env var // 4. Default config file (unless --config was specified) // This order was chosen as the most "natural" ordering, reflecting the order in which // users may supply configuration properties to digdag. Generally properties specified "later" // should take precedence. Properties props = new Properties(); if (configPath == null) { // If no configuration file was specified, load the default configuration, if it exists. Path defaultConfigPath = ConfigUtil.defaultConfigPath(env); try { props.putAll(PropertyUtils.loadFile(defaultConfigPath)); } catch (NoSuchFileException ex) { log.trace("configuration file not found: {}", defaultConfigPath, ex); } } // Load properties from DIGDAG_CONFIG env props.load(new StringReader(env.getOrDefault("DIGDAG_CONFIG", ""))); // Load properties from system properties props.putAll(System.getProperties()); // Load explicit configuration file, if specified. if (configPath != null) { props.putAll(PropertyUtils.loadFile(Paths.get(configPath))); } return props; }
Example #27
Source File: FileSystemHttpFile.java From armeria with Apache License 2.0 | 5 votes |
@Override protected ByteChannel newStream() throws IOException { try { return Files.newByteChannel(path, StandardOpenOption.READ); } catch (NoSuchFileException e) { return null; } }
Example #28
Source File: MockStorageProvider.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
@Override protected MockStorageModel loadWriteModel ( final StorageContext context ) throws Exception { try ( ObjectInputStream is = new ObjectInputStream ( Files.newInputStream ( context.getBasePath ().resolve ( this.key ) ) ) ) { return (MockStorageModel)is.readObject (); } catch ( final NoSuchFileException e ) { return new MockStorageModel ( this.initialValue ); } }
Example #29
Source File: ReplicaFileDeleter.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Used only by asserts: returns true if the file exists * (can be opened), false if it cannot be opened, and * (unlike Java's File.exists) throws IOException if * there's some unexpected error. */ private static boolean slowFileExists(Directory dir, String fileName) throws IOException { try { dir.openInput(fileName, IOContext.DEFAULT).close(); return true; } catch (NoSuchFileException | FileNotFoundException e) { return false; } }
Example #30
Source File: LocalReplicatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testObtainMissingFile() throws IOException { replicator.publish(createRevision(1)); SessionToken res = replicator.checkForUpdate(null); expectThrowsAnyOf(Arrays.asList(FileNotFoundException.class, NoSuchFileException.class), () -> { replicator.obtainFile(res.id, res.sourceFiles.keySet().iterator().next(), "madeUpFile"); }); }