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

x33g5p2x  于2022-01-17 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(641)

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

Files.newOutputStream介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

private synchronized OutputStream current() throws IOException {
  if (current==null)
    try {
      current = Files.newOutputStream(out.toPath(), StandardOpenOption.CREATE,
          appendOnNextOpen ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING);
    } catch (FileNotFoundException | NoSuchFileException | InvalidPathException e) {
      throw new IOException("Failed to open "+out,e);
    }
  return current;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Disable a plugin wihout checking any dependency. Only add the disable file.
 * @throws IOException
 */
private void disableWithoutCheck() throws IOException {
  // creates an empty file
  try (OutputStream os = Files.newOutputStream(disableFile.toPath())) {
    os.close();
  } catch (InvalidPathException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: jenkinsci/jenkins

public static void copy(InputStream in, File out) throws IOException {
  try (OutputStream fos = Files.newOutputStream(out.toPath())) {
    org.apache.commons.io.IOUtils.copy(in, fos);
  } catch (InvalidPathException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Deprecated
public OutputStream getOutputStream() throws IOException {
  try {
    return Files.newOutputStream(file.toPath());
  } catch (InvalidPathException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Gets the OutputStream to write to the file.
 */
public OutputStream write() throws IOException {
  if(gz.exists())
    gz.delete();
  try {
    return Files.newOutputStream(file.toPath());
  } catch (InvalidPathException e) {
    throw new IOException(e);
  }
}

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

/**
 * Copy the contents of the given byte array to the given output File.
 * @param in the byte array to copy from
 * @param out the file to copy to
 * @throws IOException in case of I/O errors
 */
public static void copy(byte[] in, File out) throws IOException {
  Assert.notNull(in, "No input byte array specified");
  Assert.notNull(out, "No output File specified");
  copy(new ByteArrayInputStream(in), Files.newOutputStream(out.toPath()));
}

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

/**
 * Copy the contents of the given input File to the given output File.
 * @param in the file to copy from
 * @param out the file to copy to
 * @return the number of bytes copied
 * @throws IOException in case of I/O errors
 */
public static int copy(File in, File out) throws IOException {
  Assert.notNull(in, "No input File specified");
  Assert.notNull(out, "No output File specified");
  return copy(Files.newInputStream(in.toPath()), Files.newOutputStream(out.toPath()));
}

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

@Override
public OutputStream getOutputStream() throws IOException {
  return Files.newOutputStream(getFile().toPath());
}

代码示例来源:origin: micronaut-projects/micronaut-core

/**
 * This implementation opens a FileOutputStream for the underlying file.
 *
 * @return The FileOutputStream
 * @throws IOException if there is an error
 * @see java.io.FileOutputStream
 */
public OutputStream getOutputStream() throws IOException {
  return Files.newOutputStream(file.toPath());
}

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

private OutputStream getOutputStream() throws IOException {
    return reportFile == null ? System.out : Files.newOutputStream(reportFile.toPath());
  }
}

代码示例来源:origin: jenkinsci/jenkins

private synchronized OutputStream current() throws IOException {
  if (current == null) {
    if (!closed) {
      FileUtils.forceMkdir(out.getParentFile());
      try {
        current = Files.newOutputStream(out.toPath(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
      } catch (FileNotFoundException | NoSuchFileException | InvalidPathException e) {
        throw new IOException("Failed to open "+out,e);
      }
    }
    else {
      throw new IOException(out.getName()+" stream is closed");
    }
  }
  return current;
}

代码示例来源:origin: jenkinsci/jenkins

public void on() {
  try {
    file.getParentFile().mkdirs();
    Files.newOutputStream(file.toPath()).close();
    get();  // update state
  } catch (IOException | InvalidPathException e) {
    LOGGER.log(Level.WARNING, "Failed to touch "+file);
  }
}

代码示例来源:origin: jenkinsci/jenkins

private OutputStream createLogger() throws IOException {
  // don't do buffering so that what's written to the listener
  // gets reflected to the file immediately, which can then be
  // served to the browser immediately
  try {
    return Files.newOutputStream(getLogFile().toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
  } catch (InvalidPathException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * To assist boot failure script, record the number of boot attempts.
 * This file gets deleted in case of successful boot.
 *
 * @see BootFailure
 */
private void recordBootAttempt(File home) {
  try (OutputStream o=Files.newOutputStream(BootFailure.getBootFailureFile(home).toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
    o.write((new Date().toString() + System.getProperty("line.separator", "\n")).toString().getBytes());
  } catch (IOException | InvalidPathException e) {
    LOGGER.log(WARNING, "Failed to record boot attempts",e);
  }
}

代码示例来源:origin: org.apache.commons/commons-compress

public FileBasedScatterGatherBackingStore(final File target) throws FileNotFoundException {
  this.target = target;
  try {
    os = Files.newOutputStream(target.toPath());
  } catch (FileNotFoundException ex) {
    throw ex;
  } catch (IOException ex) {
    // must convert exception to stay backwards compatible with Compress 1.10 to 1.13
    throw new RuntimeException(ex); // NOSONAR
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Write out manifest to destfile.
 *
 * @param manifest the manifest
 * @throws IOException if error writing file
 */
private void writeManifest(final Manifest manifest) throws IOException {
  try (OutputStream output = Files.newOutputStream(destFile.toPath())) {
    manifest.write(output);
    output.flush();
  }
}

代码示例来源:origin: org.apache.commons/commons-compress

TempFileCachingStreamBridge() throws IOException {
  f = File.createTempFile("commons-compress", "packtemp");
  f.deleteOnExit();
  out = Files.newOutputStream(f.toPath());
}

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

@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
  this.part.write(dest.getPath());
  if (dest.isAbsolute() && !dest.exists()) {
    // Servlet 3.0 Part.write is not guaranteed to support absolute file paths:
    // may translate the given path to a relative location within a temp dir
    // (e.g. on Jetty whereas Tomcat and Undertow detect absolute paths).
    // At least we offloaded the file from memory storage; it'll get deleted
    // from the temp dir eventually in any case. And for our user's purposes,
    // we can manually copy it to the requested location as a fallback.
    FileCopyUtils.copy(this.part.getInputStream(), Files.newOutputStream(dest.toPath()));
  }
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Copy the contents of the given input File to the given output File.
 * @param in the file to copy from
 * @param out the file to copy to
 * @return the number of bytes copied
 * @throws IOException in case of I/O errors
 */
public static int copy(File in, File out) throws IOException {
  Assert.notNull(in, "No input File specified");
  Assert.notNull(out, "No output File specified");
  return copy(Files.newInputStream(in.toPath()), Files.newOutputStream(out.toPath()));
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Copy the contents of the given byte array to the given output File.
 * @param in the byte array to copy from
 * @param out the file to copy to
 * @throws IOException in case of I/O errors
 */
public static void copy(byte[] in, File out) throws IOException {
  Assert.notNull(in, "No input byte array specified");
  Assert.notNull(out, "No output File specified");
  copy(new ByteArrayInputStream(in), Files.newOutputStream(out.toPath()));
}

相关文章

微信公众号

最新文章

更多