Java Code Examples for org.apache.nifi.util.file.FileUtils#copy()

The following examples show how to use org.apache.nifi.util.file.FileUtils#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardFlowService.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 2
Source File: StandardFlowService.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 3
Source File: StandardXMLFlowConfigurationDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 4
Source File: StandardXMLFlowConfigurationDAO.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: StandardFlowSynchronizer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 6
Source File: StandardFlowService.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 7
Source File: FlowParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 8
Source File: StandardXMLFlowConfigurationDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 9
Source File: StandardXMLFlowConfigurationDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: StandardFlowSynchronizer.java    From nifi with Apache License 2.0 5 votes vote down vote up
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();
}