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"); } }
/** * 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; }
@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)); }
@Override public void deleteFile(String name) throws IOException { ensureOpen(); FileEntry removed = files.remove(name); if (removed == null) { throw new NoSuchFileException(name); } }
private JavaContainerBuilder addDirectory( Path directory, AbsoluteUnixPath destination, LayerType layerType, Predicate<Path> pathFilter) throws IOException { if (!Files.exists(directory)) { throw new NoSuchFileException(directory.toString()); } if (!Files.isDirectory(directory)) { throw new NotDirectoryException(directory.toString()); } layerConfigurationsBuilder.addDirectoryContents(layerType, directory, pathFilter, destination); classpath.add(destination.toString()); return this; } }
public static void checkWritableDirectory( Path directory ) throws FileSystemException { if ( !exists( directory ) ) { throw new NoSuchFileException( directory.toString() ); } if ( isRegularFile( directory ) ) { throw new FileSystemException( directory.toString() + ": Not a directory" ); } if ( !isWritable( directory ) ) { throw new AccessDeniedException( directory.toString() ); } }
@Override public void rename(String source, String dest) throws IOException { ensureOpen(); FileEntry file = files.get(source); if (file == null) { throw new NoSuchFileException(source); } if (files.putIfAbsent(dest, file) != null) { throw new FileAlreadyExistsException(dest); } if (!files.remove(source, file)) { throw new IllegalStateException("File was unexpectedly replaced: " + source); } files.remove(source); }
@Override public void rename(String source, String dest) throws IOException { ensureOpen(); if (pendingDeletes.contains(source)) { throw new NoSuchFileException("file \"" + source + "\" is pending delete and cannot be moved"); } maybeDeletePendingFiles(); if (pendingDeletes.remove(dest)) { privateDeleteFile(dest, true); // try again to delete it - this is best effort pendingDeletes.remove(dest); // watch out if the delete fails it's back in here. } Files.move(directory.resolve(source), directory.resolve(dest), StandardCopyOption.ATOMIC_MOVE); }
/** * Returns the result of the file lookup for the given path. */ public DirectoryEntry lookUp( File workingDirectory, JimfsPath path, Set<? super LinkOption> options) throws IOException { checkNotNull(path); checkNotNull(options); DirectoryEntry result = lookUp(workingDirectory, path, options, 0); if (result == null) { // an intermediate file in the path did not exist or was not a directory throw new NoSuchFileException(path.toString()); } return result; }
@Override public long fileLength(String name) throws IOException { ensureOpen(); FileEntry file = files.get(name); if (file == null) { throw new NoSuchFileException(name); } return file.length(); }
@Override public void deleteFile(String name) throws IOException { if (pendingDeletes.contains(name)) { throw new NoSuchFileException("file \"" + name + "\" is already pending delete"); } privateDeleteFile(name, false); maybeDeletePendingFiles(); }
@Override public IndexInput openInput(String name, IOContext context) throws IOException { ensureOpen(); FileEntry e = files.get(name); if (e == null) { throw new NoSuchFileException(name); } else { return e.openInput(); } }
/** {@inheritDoc} */ @Override protected VisorEither<VisorFileBlock> run(VisorFileBlockTaskArg arg) { try { URL url = U.resolveIgniteUrl(arg.getPath()); if (url == null) return new VisorEither<>(new NoSuchFileException("File path not found: " + arg.getPath())); VisorFileBlock block = readBlock( new File(url.toURI()), arg.getOffset(), arg.getBlockSize(), arg.getLastModified()); return new VisorEither<>(block); } catch (IOException e) { return new VisorEither<>(e); } catch (URISyntaxException ignored) { return new VisorEither<>(new NoSuchFileException("File path not found: " + arg.getPath())); } }
@Override public PageSwapper createPageSwapper( File file, int filePageSize, PageEvictionCallback onEviction, boolean createIfNotExist, boolean noChannelStriping ) throws IOException { if ( !fs.fileExists( file ) ) { if ( createIfNotExist ) { fs.create( file ).close(); } else { throw new NoSuchFileException( file.getPath(), null, "Cannot map non-existing file" ); } } return new SingleFilePageSwapper( file, fs, filePageSize, onEviction, noChannelStriping ); }
@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() ); }
@Override public void deleteFileOrThrow( File file ) throws IOException { file = canonicalFile( file ); if ( !fileExists( file ) ) { throw new NoSuchFileException( file.getAbsolutePath() ); } if ( !deleteFile( file ) ) { throw new IOException( "Could not delete file: " + file ); } }
@Override public void renameFile( File from, File to, CopyOption... copyOptions ) throws IOException { from = canonicalFile( from ); to = canonicalFile( to ); if ( !files.containsKey( from ) ) { throw new NoSuchFileException( "'" + from + "' doesn't exist" ); } boolean replaceExisting = false; for ( CopyOption copyOption : copyOptions ) { replaceExisting |= copyOption == REPLACE_EXISTING; } if ( files.containsKey( to ) && !replaceExisting ) { throw new FileAlreadyExistsException( "'" + to + "' already exists" ); } if ( !isDirectory( to.getParentFile() ) ) { throw new NoSuchFileException( "Target directory[" + to.getParent() + "] does not exists" ); } files.put( to, files.remove( from ) ); }
@Override public void delete(Path path) throws IOException { initStorage(); CloudStoragePath cloudPath = CloudStorageUtil.checkPath(path); if (!deleteIfExists(cloudPath)) { throw new NoSuchFileException(cloudPath.toString()); } }
@Test void shouldGiveAClearMessageIfTheArchiveDoesntExist() throws IOException, IncorrectFormat { doThrow( new NoSuchFileException( archive.toString() ) ).when( loader ).load( any(), any(), any() ); CommandFailed commandFailed = assertThrows( CommandFailed.class, () -> execute( null ) ); assertEquals( "archive does not exist: " + archive, commandFailed.getMessage() ); }
@Override public CloudStorageFileAttributes readAttributes() throws IOException { if (path.seemsLikeADirectory() && path.getFileSystem().config().usePseudoDirectories()) { return new CloudStoragePseudoDirectoryAttributes(path); } BlobInfo blobInfo = storage.get(path.getBlobId()); if (blobInfo == null) { throw new NoSuchFileException(path.toUri().toString()); } return new CloudStorageObjectAttributes(blobInfo); }