Example usage for org.apache.commons.io.input TeeInputStream TeeInputStream

List of usage examples for org.apache.commons.io.input TeeInputStream TeeInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.input TeeInputStream TeeInputStream.

Prototype

public TeeInputStream(InputStream input, OutputStream branch, boolean closeBranch) 

Source Link

Document

Creates a TeeInputStream that proxies the given InputStream and copies all read bytes to the given OutputStream .

Usage

From source file:org.opencastproject.workspace.impl.WorkspaceImpl.java

/**
 * {@inheritDoc}/*from w  w w . j a  v  a2 s  .  c om*/
 * 
 * @see org.opencastproject.workspace.api.Workspace#putInCollection(java.lang.String, java.lang.String,
 *      java.io.InputStream)
 */
@Override
public URI putInCollection(String collectionId, String fileName, InputStream in) throws IOException {
    String safeFileName = PathSupport.toSafeName(fileName);
    URI uri = wfr.getCollectionURI(collectionId, fileName);

    // Determine the target location in the workspace
    InputStream tee = null;
    File tempFile = null;
    FileOutputStream out = null;
    try {
        synchronized (wsRoot) {
            tempFile = getWorkspaceFile(uri, true);
            FileUtils.touch(tempFile);
            out = new FileOutputStream(tempFile);
        }

        // Try hard linking first and fall back to tee-ing to both the working file repository and the workspace
        if (linkingEnabled) {
            tee = in;
            wfr.putInCollection(collectionId, fileName, tee);
            FileUtils.forceMkdir(tempFile.getParentFile());
            File workingFileRepoDirectory = new File(PathSupport.concat(
                    new String[] { wfrRoot, WorkingFileRepository.COLLECTION_PATH_PREFIX, collectionId }));
            File workingFileRepoCopy = new File(workingFileRepoDirectory, safeFileName);
            FileSupport.link(workingFileRepoCopy, tempFile, true);
        } else {
            tee = new TeeInputStream(in, out, true);
            wfr.putInCollection(collectionId, fileName, tee);
        }
    } catch (IOException e) {
        FileUtils.deleteQuietly(tempFile);
        throw e;
    } finally {
        IoSupport.closeQuietly(tee);
        IoSupport.closeQuietly(out);
    }
    return uri;
}

From source file:org.sonar.plugins.cxx.cppcheck.CxxCppCheckSensor.java

public void analyse(Project project, SensorContext context) {
    if (dynamicAnalysis) {
        Process p;/*  w w w . ja v a  2s  .  com*/

        try {
            String cmd = EXEC + " " + ARGS + " " + project.getPom().getBuild().getSourceDirectory();
            logger.debug(cmd);
            p = Runtime.getRuntime().exec(cmd);
            p.waitFor();

            // Write result in local file
            File resultOutputFile = new File(
                    project.getFileSystem().getSonarWorkingDirectory() + "/cppcheck-result.xml");
            // resultOutputFile.createNewFile();
            logger.debug("Output result to " + resultOutputFile.getAbsolutePath());

            // Becarefull ... CppCheck print its result into Error output !
            // TeeInputStream is used to read result from stream and both
            // write it to a file
            FileOutputStream fos = new FileOutputStream(resultOutputFile);
            TeeInputStream tis = new TeeInputStream(p.getErrorStream(), fos, true);
            parseReport(project, tis, context);

        } catch (InterruptedException ex) {
            logger.error("Analysis can't wait for the end of the process", ex);
        } catch (IOException ex) {
            logger.error("IO EXCEPTION", ex);
        }

    } else {
        File reportDirectory = getReportsDirectory(project);
        if (reportDirectory != null) {
            File reports[] = getReports(project, reportDirectory);
            for (File report : reports) {
                parseReport(project, report, context);
            }
        }
    }
}