/** * 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()); } }
/** * This implementation opens a FileChannel for the underlying file. * @see java.nio.channels.FileChannel */ @Override public ReadableByteChannel readableChannel() throws IOException { try { return FileChannel.open(this.filePath, StandardOpenOption.READ); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } }
/** * This implementation opens a Channel for the underlying file. * @see Files#newByteChannel(Path, OpenOption...) */ @Override public ReadableByteChannel readableChannel() throws IOException { try { return Files.newByteChannel(this.path, StandardOpenOption.READ); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.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()); } }
/** * This implementation opens a FileChannel for the underlying file. * @see java.nio.channels.FileChannel */ @Override public ReadableByteChannel readableChannel() throws IOException { try { return FileChannel.open(this.filePath, StandardOpenOption.READ); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } }
/** * This implementation returns the underlying File/Path last-modified time. */ @Override public long lastModified() throws IOException { if (this.file != null) { return super.lastModified(); } else { try { return Files.getLastModifiedTime(this.filePath).toMillis(); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
/** * This implementation returns the underlying File/Path length. */ @Override public long contentLength() throws IOException { if (this.file != null) { long length = this.file.length(); if (length == 0L && !this.file.exists()) { throw new FileNotFoundException(getDescription() + " cannot be resolved in the file system for checking its content length"); } return length; } else { try { return Files.size(this.filePath); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
/** * This implementation opens a Channel for the underlying file. * @see Files#newByteChannel(Path, OpenOption...) */ @Override public ReadableByteChannel readableChannel() throws IOException { try { return Files.newByteChannel(this.path, StandardOpenOption.READ); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } }
/** * This implementation returns the underlying File/Path last-modified time. */ @Override public long lastModified() throws IOException { if (this.file != null) { return super.lastModified(); } else { try { return Files.getLastModifiedTime(this.filePath).toMillis(); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
/** * This implementation returns the underlying File/Path length. */ @Override public long contentLength() throws IOException { if (this.file != null) { long length = this.file.length(); if (length == 0L && !this.file.exists()) { throw new FileNotFoundException(getDescription() + " cannot be resolved in the file system for checking its content length"); } return length; } else { try { return Files.size(this.filePath); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
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 ); } }
if ( Paths.get( e.getMessage() ).toAbsolutePath().equals( archive.toAbsolutePath() ) )
return new XnioFileChannel(path.getFileSystem().provider().newFileChannel(path, openOptions)); } catch (NoSuchFileException e) { throw new FileNotFoundException(e.getMessage());
@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() ); }
@Test void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryDoesntExist() throws IOException { Path archive = testDirectory.file( "the-archive.dump" ).toPath(); Path destination = Paths.get( testDirectory.absolutePath().getAbsolutePath(), "subdir", "the-destination" ); NoSuchFileException noSuchFileException = assertThrows( NoSuchFileException.class, () -> new Loader().load( archive, destination, destination ) ); assertEquals( destination.getParent().toString(), noSuchFileException.getMessage() ); }
inode = getInode(f); } catch (NoSuchFileException e) { logger.info("File has been deleted in the meantime: " + e.getMessage()); continue;
@Test void shouldGiveAClearErrorMessageIfTheArchivesParentDirectoryDoesntExist() { Path directory = testDirectory.directory( "a-directory" ).toPath(); Path archive = testDirectory.file( "subdir/the-archive.dump" ).toPath(); NoSuchFileException exception = assertThrows( NoSuchFileException.class, () -> new Dumper().dump( directory, directory, archive, Predicates.alwaysFalse() ) ); assertEquals( archive.getParent().toString(), exception.getMessage() ); }
@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() ); }
log.error("Unable to copy uploaded file to static folder. Reason : {}", e.getMessage()); response = (serverError()); } catch (Exception e) {
@Test void shouldGiveAClearErrorMessageIfTheDirectoryDoesntExist() { Path directory = testDirectory.file( "a-directory" ).toPath(); Path archive = testDirectory.file( "the-archive.dump" ).toPath(); NoSuchFileException exception = assertThrows( NoSuchFileException.class, () -> new Dumper().dump( directory, directory, archive, Predicates.alwaysFalse() ) ); assertEquals( directory.toString(), exception.getMessage() ); }