java.nio.file.NoSuchFileException类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(479)

本文整理了Java中java.nio.file.NoSuchFileException类的一些代码示例,展示了NoSuchFileException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NoSuchFileException类的具体详情如下:
包路径:java.nio.file.NoSuchFileException
类名称:NoSuchFileException

NoSuchFileException介绍

暂无

代码示例

代码示例来源:origin: google/jimfs

/**
 * 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;
}

代码示例来源:origin: neo4j/neo4j

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

代码示例来源:origin: pmd/pmd

} catch (Exception notInJarWithPath) {
  notInJarWithPath.printStackTrace();
  notFoundOnFilesystemWithExtensionTackedOn.printStackTrace();
  throw new RuntimeException(" Could not locate DBTYpe settings : " + matchString,
      notInJarWithPath);

代码示例来源:origin: embulk/embulk

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

代码示例来源:origin: neo4j/neo4j

@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() );
}

代码示例来源:origin: igniterealtime/Openfire

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());

代码示例来源:origin: GoogleContainerTools/jib

throw new NoSuchFileException(file.toString());
for (Path file : dependencyFiles) {
 layerConfigurationsBuilder.addFile(
   file.getFileName().toString().contains("SNAPSHOT")
     ? LayerType.SNAPSHOT_DEPENDENCIES
     : LayerType.DEPENDENCIES,

代码示例来源:origin: org.apache.lucene/lucene-core

@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));
}

代码示例来源:origin: neo4j/neo4j

@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() );
}

代码示例来源:origin: ferstl/depgraph-maven-plugin

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();
}

代码示例来源:origin: neo4j/neo4j

@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() );
}

代码示例来源:origin: gluster/glusterfs-java-filesystem

@Override
public FileStore getFileStore(Path path) throws IOException {
  if (Files.exists(path)) {
    return path.getFileSystem().getFileStores().iterator().next();
  } else {
    throw new NoSuchFileException(path.toString());
  }
}

代码示例来源:origin: HubSpot/Singularity

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);

代码示例来源:origin: iterate-ch/cyberduck

@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));
}

代码示例来源:origin: neo4j/neo4j

if ( Paths.get( e.getMessage() ).toAbsolutePath().equals( archive.toAbsolutePath() ) )

代码示例来源:origin: org.apache.taverna.language/taverna-robundle

@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();
  }
}

代码示例来源:origin: de.pfabulist.lindwurm/stellvertreter

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

代码示例来源:origin: org.apache.lucene/lucene-core

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

代码示例来源:origin: wildfly/wildfly

return new XnioFileChannel(path.getFileSystem().provider().newFileChannel(path, openOptions));
} catch (NoSuchFileException e) {
  throw new FileNotFoundException(e.getMessage());

代码示例来源:origin: spring-projects/spring-framework

/**
 * 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());
  }
}

相关文章