Search in sources :

Example 6 with TeeOutputStream

use of org.apache.commons.io.output.TeeOutputStream in project gradle by gradle.

the class InProcessGradleExecuter method createLoggingManager.

private LoggingManagerInternal createLoggingManager(StartParameter startParameter, OutputStream outputStream, OutputStream errorStream) {
    LoggingManagerInternal loggingManager = GLOBAL_SERVICES.getFactory(LoggingManagerInternal.class).create();
    loggingManager.captureSystemSources();
    ConsoleOutput consoleOutput = startParameter.getConsoleOutput();
    loggingManager.attachConsole(new TeeOutputStream(System.out, outputStream), new TeeOutputStream(System.err, errorStream), consoleOutput, consoleAttachment.getConsoleMetaData());
    return loggingManager;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream)

Example 7 with TeeOutputStream

use of org.apache.commons.io.output.TeeOutputStream in project wso2-axis2-transports by wso2.

the class LogAspect method aroundWriteTo.

@Around("call(void org.apache.axis2.transport.MessageFormatter.writeTo(" + "       org.apache.axis2.context.MessageContext, org.apache.axiom.om.OMOutputFormat," + "       java.io.OutputStream, boolean))" + " && args(msgContext, format, out, preserve)")
public void aroundWriteTo(ProceedingJoinPoint proceedingJoinPoint, MessageContext msgContext, OMOutputFormat format, OutputStream out, boolean preserve) throws Throwable {
    OutputStream log = LogManager.INSTANCE.createLog("formatter");
    try {
        OutputStream tee = new TeeOutputStream(out, log);
        proceedingJoinPoint.proceed(new Object[] { msgContext, format, tee, preserve });
    } finally {
        log.close();
    }
}
Also used : TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) OutputStream(java.io.OutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) Around(org.aspectj.lang.annotation.Around)

Example 8 with TeeOutputStream

use of org.apache.commons.io.output.TeeOutputStream in project pcgen by PCGen.

the class BatchExporter method exportPartyToPDF.

/**
	 * Write a PDF party sheet for the characters in the party to the output 
	 * file. The party sheet will be built according to the template file. If  
	 * the output file exists it will be overwritten.
	 *    
	 * @param party The already loaded party of characters to be output.
	 * @param outFile The file to which the party sheet is to be written. 
	 * @param templateFile The file that has the export template definition.  
	 * @return true if the export was successful, false if it failed in some way.
	 */
public static boolean exportPartyToPDF(PartyFacade party, File outFile, File templateFile) {
    // We want the non pdf extension here for the intermediate file.
    String templateExtension = ExportUtilities.getOutputExtension(templateFile.getName(), false);
    boolean isTransformTemplate = "xslt".equalsIgnoreCase(templateExtension) || "xsl".equalsIgnoreCase(templateExtension);
    boolean useTempFile = PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_GENERATE_TEMP_FILE_WITH_PDF, false);
    String outFileName = FilenameUtils.removeExtension(outFile.getAbsolutePath());
    File tempFile = new File(outFileName + (isTransformTemplate ? ".xml" : ".fo"));
    try (BufferedOutputStream fileStream = new BufferedOutputStream(new FileOutputStream(outFile));
        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        OutputStream exportOutput = useTempFile ? //Output to both the byte stream and to the temp file.
        new TeeOutputStream(byteOutputStream, new FileOutputStream(tempFile)) : byteOutputStream) {
        FopTask task;
        if (isTransformTemplate) {
            exportParty(party, exportOutput);
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
            task = FopTask.newFopTask(inputStream, templateFile, fileStream);
        } else {
            SettingsHandler.setSelectedPartyPDFOutputSheet(templateFile.getAbsolutePath());
            exportParty(party, templateFile, exportOutput);
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
            task = FopTask.newFopTask(inputStream, null, fileStream);
        }
        task.run();
    } catch (final IOException e) {
        Logging.errorPrint("BatchExporter.exportPartyToPDF failed", e);
        return false;
    } catch (final ExportException e) {
        Logging.errorPrint("BatchExporter.exportPartyToPDF failed", e);
        return false;
    }
    return true;
}
Also used : TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FopTask(pcgen.util.fop.FopTask) PCGFile(pcgen.io.PCGFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) ExportException(pcgen.io.ExportException)

Example 9 with TeeOutputStream

use of org.apache.commons.io.output.TeeOutputStream in project pcgen by PCGen.

the class BatchExporter method exportCharacterToPDF.

/**
	 * Write a PDF character sheet for the character to the output file. The 
	 * character sheet will be built according to the template file. If the 
	 * output file exists it will be overwritten.
	 *    
	 * @param character The already loaded character to be output.
	 * @param outFile The file to which the character sheet is to be written. 
	 * @param templateFile The file that has the export template definition.  
	 * @return true if the export was successful, false if it failed in some way.
	 */
public static boolean exportCharacterToPDF(CharacterFacade character, File outFile, File templateFile) {
    String templateExtension = FilenameUtils.getExtension(templateFile.getName());
    boolean isTransformTemplate = "xslt".equalsIgnoreCase(templateExtension) || "xsl".equalsIgnoreCase(templateExtension);
    boolean useTempFile = PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_GENERATE_TEMP_FILE_WITH_PDF, false);
    String outFileName = FilenameUtils.removeExtension(outFile.getAbsolutePath());
    File tempFile = new File(outFileName + (isTransformTemplate ? ".xml" : ".fo"));
    try (BufferedOutputStream fileStream = new BufferedOutputStream(new FileOutputStream(outFile));
        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        OutputStream exportOutput = useTempFile ? //Output to both the byte stream and to the temp file.
        new TeeOutputStream(byteOutputStream, new FileOutputStream(tempFile)) : byteOutputStream) {
        FopTask task;
        if (isTransformTemplate) {
            exportCharacter(character, exportOutput);
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
            task = FopTask.newFopTask(inputStream, templateFile, fileStream);
        } else {
            exportCharacter(character, templateFile, exportOutput);
            ByteArrayInputStream inputStream = new ByteArrayInputStream(byteOutputStream.toByteArray());
            task = FopTask.newFopTask(inputStream, null, fileStream);
        }
        character.setDefaultOutputSheet(true, templateFile);
        task.run();
        if (StringUtils.isNotBlank(task.getErrorMessages())) {
            Logging.errorPrint(//$NON-NLS-1$
            "BatchExporter.exportCharacterToPDF failed: " + task.getErrorMessages());
            return false;
        }
    } catch (final IOException e) {
        //$NON-NLS-1$
        Logging.errorPrint("BatchExporter.exportCharacterToPDF failed", e);
        return false;
    } catch (final ExportException e) {
        //$NON-NLS-1$
        Logging.errorPrint("BatchExporter.exportCharacterToPDF failed", e);
        return false;
    }
    return true;
}
Also used : TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FopTask(pcgen.util.fop.FopTask) PCGFile(pcgen.io.PCGFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) ExportException(pcgen.io.ExportException)

Example 10 with TeeOutputStream

use of org.apache.commons.io.output.TeeOutputStream in project jackrabbit-oak by apache.

the class PrinterDumper method dump.

public void dump() throws IOException {
    try (OutputStream os = newOutput()) {
        OutputStream writerStream = dumpToSysOut ? new TeeOutputStream(os, System.out) : os;
        PrintWriter pw = new PrintWriter(writerStream);
        printer.print(pw, format, false);
        pw.flush();
    }
}
Also used : TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) OutputStream(java.io.OutputStream) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)19 OutputStream (java.io.OutputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 FileOutputStream (java.io.FileOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 File (java.io.File)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)4 JsonParser (com.fasterxml.jackson.core.JsonParser)3 BufferedOutputStream (java.io.BufferedOutputStream)3 InputStreamReader (java.io.InputStreamReader)3 PrintStream (java.io.PrintStream)3 MalformedURLException (java.net.MalformedURLException)2 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)2 List (java.util.List)2 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)2 NullOutputStream (org.apache.commons.io.output.NullOutputStream)2 DataSet (org.talend.dataprep.api.dataset.DataSet)2 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)2