java.nio.file.Path.resolveSibling()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(340)

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

Path.resolveSibling介绍

暂无

代码示例

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

@Override
public Path resolveSibling(String other) {
  return delegate.resolveSibling(other);
}

代码示例来源:origin: stackoverflow.com

Path newName(Path oldName, String newNameString){
  return Files.move(oldName, oldName.resolveSibling(newNameString));
}

代码示例来源:origin: stackoverflow.com

Path source = Paths.get("path/here");
Files.move(source, source.resolveSibling("newname"));

代码示例来源:origin: SonarSource/sonarqube

private static Path getPack200Path(Path jar) {
  String jarFileName = jar.getFileName().toString();
  String filename = jarFileName.substring(0, jarFileName.length() - 3) + "pack.gz";
  return jar.resolveSibling(filename);
 }
}

代码示例来源:origin: pxb1988/dex2jar

public static void doFile(Path srcDex) throws IOException {
  String distName = srcDex.getFileName() + "_asmifier";
  doFile(srcDex, srcDex.resolveSibling(distName));
}

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

void cancel() throws IOException {
    if (casCurrent(this, CLOSED)) {
      delegate.close();
      final Path newPath = path.resolveSibling(path.getFileName() + ".new");
      Files.deleteIfExists(newPath);
    }
  }
}

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

public AtomicFileOutputStream(final Path path) throws IOException {
  final Path parent = path.getParent();
  if (parent != null && parent.getNameCount() != 0 && ! Files.exists(parent)) {
    Files.createDirectories(parent);
  }
  current = new OpenState(Files.newOutputStream(path.resolveSibling(path.getFileName() + ".new"), CREATE, TRUNCATE_EXISTING), path);
}

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

@Override
 public void action(URL url) {
  String fileName = url.getFile();
  File file = new File(url.getPath());
  String currentDateTime = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
  String newFileName = new StringBuilder(fileName)
    .insert(fileName.lastIndexOf("."), "-" + currentDateTime)
    .toString();
  Path filePath = file.toPath();
  try {
   Files.move(filePath, filePath.resolveSibling(newFileName));
  } catch (IOException e) {
   logger.error("There was an error during file {} rename.", fileName, e);
  }
 }
},

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

void close() throws IOException {
  if (casCurrent(this, CLOSED)) {
    // atomic cleanup operation: close out our stream
    delegate.close();
    final Path path = this.path;
    final Path newPath = path.resolveSibling(path.getFileName() + ".new");
    try {
      // move new file in
      Files.move(newPath, path, REPLACE_EXISTING, ATOMIC_MOVE);
    } catch (Throwable t) {
      try {
        // didn't work, gotta delete our temp copy
        Files.deleteIfExists(newPath);
      } catch (Throwable problem) {
        problem.addSuppressed(t);
        throw problem;
      }
      throw t;
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

private void processFileError(InputFile inputFile, SensorContext context) {
 Path ioFile = inputFile.file().toPath();
 Path errorFile = ioFile.resolveSibling(ioFile.getFileName() + ERROR_EXTENSION).toAbsolutePath();
 if (Files.exists(errorFile) && Files.isRegularFile(errorFile)) {
  LOG.debug("Processing " + errorFile.toString());
  try {
   List<String> lines = Files.readAllLines(errorFile, context.fileSystem().encoding());
   for (String line : lines) {
    if (StringUtils.isBlank(line) || line.startsWith("#")) {
     continue;
    }
    processLine(line, inputFile, context);
   }
  } catch (IOException e) {
   throw new IllegalStateException(e);
  }
 }
}

代码示例来源:origin: ata4/disunity

public SerializedFileReader(Path file) throws IOException {
  String fileName = file.getFileName().toString();
  String fileExt = FilenameUtils.getExtension(fileName);
  // load audio buffer if existing
  readResourceStream(file.resolveSibling(fileName + ".streamingResourceImage"));
  readResourceStream(file.resolveSibling(fileName + ".resS"));
  // join split serialized files before loading
  if (fileExt.startsWith("split")) {
    L.fine("Found split serialized file");
    fileName = FilenameUtils.removeExtension(fileName);
    List<Path> parts = new ArrayList<>();
    int splitIndex = 0;
    // collect all files with .split0 to .splitN extension
    while (true) {
      String splitName = String.format("%s.split%d", fileName, splitIndex);
      Path part = file.resolveSibling(splitName);
      if (Files.notExists(part)) {
        break;
      }
      L.log(Level.FINE, "Adding splinter {0}", part.getFileName());
      splitIndex++;
      parts.add(part);
    }
    // load all parts to one byte buffer
    in = DataReaders.forByteBuffer(ByteBufferUtils.load(parts));
  } else {
    in = DataReaders.forFile(file, READ);
  }
}

代码示例来源:origin: looly/hutool

final CopyOption[] options = isOverride ? new CopyOption[] { StandardCopyOption.REPLACE_EXISTING } : new CopyOption[] {};
try {
  return Files.move(path, path.resolveSibling(newName), options).toFile();
} catch (IOException e) {
  throw new IORuntimeException(e);

代码示例来源:origin: looly/hutool

final CopyOption[] options = isOverride ? new CopyOption[] { StandardCopyOption.REPLACE_EXISTING } : new CopyOption[] {};
try {
  return Files.move(path, path.resolveSibling(newName), options).toFile();
} catch (IOException e) {
  throw new IORuntimeException(e);

代码示例来源:origin: SonarSource/sonarqube

private void processSignificantCodeFile(InputFile inputFile, SensorContext context) {
 Path ioFile = inputFile.path();
 Path significantCodeFile = ioFile.resolveSibling(ioFile.getFileName() + FILE_EXTENSION).toAbsolutePath();
 if (Files.exists(significantCodeFile) && Files.isRegularFile(significantCodeFile)) {
  LOG.debug("Processing " + significantCodeFile.toString());
  try {
   List<String> lines = Files.readAllLines(significantCodeFile, context.fileSystem().encoding());
   NewSignificantCode significantCode = context.newSignificantCode()
    .onFile(inputFile);
   for (String line : lines) {
    if (StringUtils.isBlank(line) || line.startsWith("#")) {
     continue;
    }
    processLine(line, inputFile, significantCode);
   }
   significantCode.save();
  } catch (IOException e) {
   throw new IllegalStateException(e);
  }
 }
}

代码示例来源:origin: ata4/disunity

static void read(Path propsFile, Bundle bundle) throws IOException {
    BundleProps props;

    try (Reader reader = Files.newBufferedReader(propsFile, CHARSET)) {
      props = new Gson().fromJson(reader, BundleProps.class);
    }

    BundleHeader header = bundle.header();
    header.compressed(props.compressed);
    header.streamVersion(props.streamVersion);
    header.unityVersion(new UnityVersion(props.unityVersion));
    header.unityRevision(new UnityVersion(props.unityRevision));

    String bundleName = PathUtils.getBaseName(propsFile);
    Path bundleDir = propsFile.resolveSibling(bundleName);

    props.files.stream().map(bundleDir::resolve).forEach(file -> {
      bundle.entries().add(new BundleExternalEntry(file));
    });
  }
}

代码示例来源:origin: ata4/disunity

outputDir = file.resolveSibling(fileName);

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

/**
 * Finds a path with various endings or null if not found.
 *
 * @param basePath the base name
 * @param endings a list of endings to search for
 * @return new path or null if not found
 */
public static Path findWithEnding(Path basePath, String... endings) {
  for (String ending : endings) {
    Path newPath = basePath.resolveSibling(basePath.getFileName() + ending);
    if (Files.exists(newPath)) {
      return newPath;
    }
  }
  return null;
}

代码示例来源:origin: magefree/mage

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (matcher.matches(file)) {
      Path gifPath = file.resolveSibling(file.getFileName().toString().replaceAll("\\.jpg$", ".gif"));
      Files.move(file, gifPath, StandardCopyOption.REPLACE_EXISTING);
    }
    return FileVisitResult.CONTINUE;
  }
});

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

/**
 * Begin a staged file writing operation.
 * @param target The file to write.
 * @return A staged file
 */
public static StagedWrite begin(Path target) {
  UUID key = UUID.randomUUID();
  String stageName = ".tmp." + key + "." + target.getFileName().toString();
  Path stage = target.resolveSibling(stageName);
  return new StagedWrite(target, stage);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

/**
 * deletes all files associated with a reader. package-private to be able to simulate node failures at this point
 */
void deleteReaderFiles(TranslogReader reader) {
  IOUtils.deleteFilesIgnoringExceptions(reader.path(),
    reader.path().resolveSibling(getCommitCheckpointFileName(reader.getGeneration())));
}

相关文章