Refine search
/** * Checks that this entry exists, throwing an exception if not. * * @return this * @throws NoSuchFileException if this entry does not exist */ public DirectoryEntry requireExists(Path pathForException) throws NoSuchFileException { if (!exists()) { throw new NoSuchFileException(pathForException.toString()); } return this; }
private void dump( String database, DatabaseLayout databaseLayout, Path transactionalLogsDirectory, Path archive ) throws CommandFailed { Path databasePath = databaseLayout.databaseDirectory().toPath(); try { File storeLockFile = databaseLayout.getStoreLayout().storeLockFile(); dumper.dump( databasePath, transactionalLogsDirectory, archive, path -> Objects.equals( path.getFileName().toString(), storeLockFile.getName() ) ); } catch ( FileAlreadyExistsException e ) { throw new CommandFailed( "archive already exists: " + e.getMessage(), e ); } catch ( NoSuchFileException e ) { if ( Paths.get( e.getMessage() ).toAbsolutePath().equals( databasePath ) ) { throw new CommandFailed( "database does not exist: " + database, e ); } wrapIOException( e ); } catch ( IOException e ) { wrapIOException( e ); } }
} catch (Exception notInJarWithPath) { notInJarWithPath.printStackTrace(); notFoundOnFilesystemWithExtensionTackedOn.printStackTrace(); throw new RuntimeException(" Could not locate DBTYpe settings : " + matchString, notInJarWithPath);
public static MavenArtifactFinder create(final Path localMavenRepositoryPath) throws MavenRepositoryNotFoundException { final Path absolutePath; try { absolutePath = localMavenRepositoryPath.normalize().toAbsolutePath(); } catch (IOError ex) { throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex); } catch (SecurityException ex) { throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, ex); } if (!Files.exists(absolutePath)) { throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, absolutePath, new NoSuchFileException(absolutePath.toString())); } if (!Files.isDirectory(absolutePath)) { throw new MavenRepositoryNotFoundException(localMavenRepositoryPath, absolutePath, new NotDirectoryException(absolutePath.toString())); } final RepositorySystem repositorySystem = createRepositorySystem(); return new MavenArtifactFinder(localMavenRepositoryPath, absolutePath, repositorySystem, createRepositorySystemSession(repositorySystem, absolutePath)); }
@Test void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryDoesntExist() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.file( "destination" ).toPath(); Path txLogsDestination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "txLogs" ); NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, txLogsDestination ) ); assertEquals( txLogsDestination.getParent().toString(), noSuchFileException.getMessage() ); }
tempFile = file.getParent().resolve(file.getFileName() + ".tmp"); if (Files.exists(tempFile)) { Log.error("WARNING: " + file.getFileName() + " was not found, but temp file from " + throw new NoSuchFileException("XML properties file does not exist: " + file.getFileName());
throw new NoSuchFileException(file.toString()); for (Path file : dependencyFiles) { layerConfigurationsBuilder.addFile( file.getFileName().toString().contains("SNAPSHOT") ? LayerType.SNAPSHOT_DEPENDENCIES : LayerType.DEPENDENCIES,
@Override public long fileLength(String name) throws IOException { ensureOpen(); if (pendingDeletes.contains(name)) { throw new NoSuchFileException("file \"" + name + "\" is pending delete"); } return Files.size(directory.resolve(name)); }
@Test void shouldGiveAClearMessageIfTheArchivesParentDoesntExist() throws Exception { doThrow( new NoSuchFileException( archive.getParent().toString() ) ).when( dumper ).dump(any(), any(), any(), any() ); CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( "foo.db" ) ); assertEquals( "unable to dump database: NoSuchFileException: " + archive.getParent(), commandFailed.getMessage() ); }
private String determineDotExecutable() throws IOException { if (this.dotExecutable == null) { return "dot"; } Path dotExecutablePath = this.dotExecutable.toPath(); if (!Files.exists(dotExecutablePath)) { throw new NoSuchFileException("The dot executable '" + this.dotExecutable + "' does not exist."); } else if (Files.isDirectory(dotExecutablePath) || !Files.isExecutable(dotExecutablePath)) { throw new IOException("The dot executable '" + this.dotExecutable + "' is not a file or cannot be executed."); } return dotExecutablePath.toAbsolutePath().toString(); }
@Test void shouldGiveAClearErrorMessageIfTheArchiveDoesntExist() { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = testDirectory.file( "the-destination" ).toPath(); NoSuchFileException exception = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( archive.toString(), exception.getMessage() ); }
@Override public FileStore getFileStore(Path path) throws IOException { if (Files.exists(path)) { return path.getFileSystem().getFileStores().iterator().next(); } else { throw new NoSuchFileException(path.toString()); } }
metrics.error(); LOG.error("Waiting on future", t); exceptionNotifier.notify(String.format("Error waiting on uploader future (%s)", t.getMessage()), t, ImmutableMap.of("metadataPath", uploader.getMetadataPath().toString())); toRetry.add(entry.getKey()); Files.delete(uploader.getMetadataPath()); } catch (NoSuchFileException nfe) { LOG.warn("File {} was already deleted", nfe.getFile()); } catch (IOException e) { LOG.warn("Couldn't delete {}", uploader.getMetadataPath(), e); exceptionNotifier.notify("Could not delete metadata file", e, ImmutableMap.of("metadataPath", uploader.getMetadataPath().toString())); metrics.error(); LOG.error("Waiting on future", t); exceptionNotifier.notify(String.format("Error waiting on uploader future (%s)", t.getMessage()), t, ImmutableMap.of("metadataPath", uploader.getMetadataPath().toString())); Files.delete(expiredUploader.getMetadataPath()); } catch (NoSuchFileException nfe) { LOG.warn("File {} was already deleted", nfe.getFile()); } catch (IOException e) { LOG.warn("Couldn't delete {}", expiredUploader.getMetadataPath(), e);
@Override public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) throws BackgroundException { if(status.isExists()) { new LocalDeleteFeature(session).delete(Collections.singletonList(renamed), new DisabledPasswordCallback(), callback); } if(!session.toPath(file).toFile().renameTo(session.toPath(renamed).toFile())) { throw new LocalExceptionMappingService().map("Cannot rename {0}", new NoSuchFileException(file.getName()), file); } // Copy attributes from original file return new Path(renamed.getParent(), renamed.getName(), renamed.getType(), new LocalAttributesFinderFeature(session).find(renamed)); }
if ( Paths.get( e.getMessage() ).toAbsolutePath().equals( archive.toAbsolutePath() ) )
@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(); } }
public void delete( Path path ) { HereFile hf = getHereFile( path ).orElseThrow( () -> u( new NoSuchFileException( path + " does not exist" ) ) ); HereFile parent = getHereFile( path.getParent() ).orElseThrow( () -> u( new NoSuchFileException( path + " does not exist" ) ) ); here.delete( parent, hf ); idCache.remove( path, hf ); }
protected void ensureCanRead(String name) throws IOException { if (pendingDeletes.contains(name)) { throw new NoSuchFileException("file \"" + name + "\" is pending delete and cannot be opened for read"); } }
return new XnioFileChannel(path.getFileSystem().provider().newFileChannel(path, openOptions)); } catch (NoSuchFileException e) { throw new FileNotFoundException(e.getMessage());
/** * This implementation opens a NIO file stream for the underlying file. * @see java.io.FileInputStream */ @Override public InputStream getInputStream() throws IOException { try { return Files.newInputStream(this.filePath); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } }