java.nio.file.NoSuchFileException.<init>()方法的使用及代码示例

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

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

NoSuchFileException.<init>介绍

暂无

代码示例

代码示例来源: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: 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: 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: org.apache.lucene/lucene-core

@Override
public void deleteFile(String name) throws IOException {
 ensureOpen();
 FileEntry removed = files.remove(name);
 if (removed == null) {
  throw new NoSuchFileException(name);
 }
}

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

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

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

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

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

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

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

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

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

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

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

@Override
public long fileLength(String name) throws IOException {
 ensureOpen();
 FileEntry file = files.get(name);
 if (file == null) {
  throw new NoSuchFileException(name);
 }
 return file.length();
}

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

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

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

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

代码示例来源:origin: apache/ignite

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

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

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

代码示例来源: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: neo4j/neo4j

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

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

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

代码示例来源:origin: googleapis/google-cloud-java

@Override
public void delete(Path path) throws IOException {
 initStorage();
 CloudStoragePath cloudPath = CloudStorageUtil.checkPath(path);
 if (!deleteIfExists(cloudPath)) {
  throw new NoSuchFileException(cloudPath.toString());
 }
}

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

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

代码示例来源:origin: googleapis/google-cloud-java

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

相关文章