org.apache.nifi.util.file.FileUtils.copy()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(121)

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

FileUtils.copy介绍

[英]Copies the given source file to the given destination file. The given destination will be overwritten if it already exists.
[中]将给定的源文件复制到给定的目标文件。如果给定目标已存在,则将覆盖该目标。

代码示例

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

@Override
public synchronized void save(final InputStream is) throws IOException {
  try (final OutputStream outStream = Files.newOutputStream(flowXmlPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
      final OutputStream gzipOut = new GZIPOutputStream(outStream)) {
    FileUtils.copy(is, gzipOut);
  }
}

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

@Override
public void overwriteFlow(final InputStream is) throws IOException {
  writeLock.lock();
  try (final OutputStream output = Files.newOutputStream(flowXml, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
      final OutputStream gzipOut = new GZIPOutputStream(output)) {
    FileUtils.copy(is, gzipOut);
  } finally {
    writeLock.unlock();
  }
}

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

@Override
public void copyCurrentFlow(final OutputStream os) throws IOException {
  readLock.lock();
  try {
    if (!Files.exists(flowXml) || Files.size(flowXml) == 0) {
      return;
    }
    try (final InputStream in = Files.newInputStream(flowXml, StandardOpenOption.READ);
        final InputStream gzipIn = new GZIPInputStream(in)) {
      FileUtils.copy(gzipIn, os);
    }
  } finally {
    readLock.unlock();
  }
}

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

@Override
public synchronized void load(final OutputStream os) throws IOException {
  if (!isFlowPresent()) {
    return;
  }
  try (final InputStream inStream = Files.newInputStream(flowXmlPath, StandardOpenOption.READ);
      final InputStream gzipIn = new GZIPInputStream(inStream)) {
    FileUtils.copy(gzipIn, os);
  }
}

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

private byte[] readFlowFromDisk() throws IOException {
  final Path flowPath = nifiProperties.getFlowConfigurationFile().toPath();
  if (!Files.exists(flowPath) || Files.size(flowPath) == 0) {
    return new byte[0];
  }
  final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (final InputStream in = Files.newInputStream(flowPath, StandardOpenOption.READ);
      final InputStream gzipIn = new GZIPInputStream(in)) {
    FileUtils.copy(gzipIn, baos);
  }
  return baos.toByteArray();
}

代码示例来源:origin: apache/nifi-minifi

/**
 * Writes a given XML Flow out to the specified path.
 *
 * @param flowDocument flowDocument of the associated XML content to write to disk
 * @param flowXmlPath  path on disk to write the flow
 * @throws IOException if there are issues in accessing the target destination for the flow
 * @throws TransformerException if there are issues in the xml transformation process
 */
public void writeFlow(final Document flowDocument, final Path flowXmlPath) throws IOException, TransformerException {
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  final Source xmlSource = new DOMSource(flowDocument);
  final Result outputTarget = new StreamResult(outputStream);
  TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
  final InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
  try (final OutputStream output = Files.newOutputStream(flowXmlPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
     final OutputStream gzipOut = new GZIPOutputStream(output);) {
    FileUtils.copy(is, gzipOut);
  }
}

代码示例来源:origin: org.apache.nifi.minifi/minifi-runtime

/**
 * Writes a given XML Flow out to the specified path.
 *
 * @param flowDocument flowDocument of the associated XML content to write to disk
 * @param flowXmlPath  path on disk to write the flow
 * @throws IOException if there are issues in accessing the target destination for the flow
 * @throws TransformerException if there are issues in the xml transformation process
 */
public void writeFlow(final Document flowDocument, final Path flowXmlPath) throws IOException, TransformerException {
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  final Source xmlSource = new DOMSource(flowDocument);
  final Result outputTarget = new StreamResult(outputStream);
  TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
  final InputStream is = new ByteArrayInputStream(outputStream.toByteArray());
  try (final OutputStream output = Files.newOutputStream(flowXmlPath, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
     final OutputStream gzipOut = new GZIPOutputStream(output);) {
    FileUtils.copy(is, gzipOut);
  }
}

相关文章