@Before public void setUp() throws Exception { final InputStream input = new ByteArrayInputStream("abc".getBytes(ASCII)); output = new ByteArrayOutputStream(); tee = new TeeInputStream(input, output); }
/** * Unpack matching files from a jar. Entries inside the jar that do * not match the given pattern will be skipped. Keep also a copy * of the entire jar in the same directory for backward compatibility. * TODO remove this feature in a new release and do only unJar * * @param inputStream the jar stream to unpack * @param toDir the destination directory into which to unpack the jar * @param unpackRegex the pattern to match jar entries against * * @throws IOException if an I/O error has occurred or toDir * cannot be created and does not already exist */ @Deprecated public static void unJarAndSave(InputStream inputStream, File toDir, String name, Pattern unpackRegex) throws IOException{ File file = new File(toDir, name); ensureDirectory(toDir); try (OutputStream jar = new FileOutputStream(file); TeeInputStream teeInputStream = new TeeInputStream(inputStream, jar)) { unJar(teeInputStream, toDir, unpackRegex); } }
if (responseBodyStream != null && outputBodyToRequestAttribute && outputBodyToResponseContent) { outputStreamToRequestAttribute = new SoftLimitBoundedByteArrayOutputStream(maxAttributeSize); teeInputStream = new TeeInputStream(responseBodyStream, outputStreamToRequestAttribute);
logger.debug("Using a TeeInputStream as we need to store the source"); bos = new ByteArrayOutputStream(); inputStream = new TeeInputStream(inputStream, bos);
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } private TeeInputStream tee = new TeeInputStream(RequestWrapper.super.getInputStream(), bos); @Override public int read() throws IOException { return tee.read(); } }; }
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } private TeeInputStream tee = new TeeInputStream(BlackcatRequestWrapper.super.getInputStream(), bos); @Override public int read() throws IOException { return tee.read(); } }; }
@Override public ServletInputStream getInputStream() throws IOException { return new ServletInputStream() { @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public void setReadListener(ReadListener readListener) { } private TeeInputStream tee = new TeeInputStream(RequestWrapper.super.getInputStream(), bos); @Override public int read() throws IOException { return tee.read(); } }; }
public DelegatingServletInputStream(ServletInputStream source) { Preconditions.checkArgument(source != null , "source ServletInputStream must not be null"); this.source = source; this.target = new ByteArrayOutputStream(); this.wrapper = new TeeInputStream(source, this.target); }
private static ByteBuffer performTransformation(InputStream configIs, String configDestinationPath) throws ConfigurationChangeException, IOException { try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream(configIs, byteArrayOutputStream)) { ConfigTransformer.transformConfigFile(teeInputStream, configDestinationPath); return ByteBuffer.wrap(byteArrayOutputStream.toByteArray()); } catch (ConfigurationChangeException e){ throw e; } catch (Exception e) { throw new IOException("Unable to successfully transform the provided configuration", e); } }
private InputStream tapIntoStream(InputStream is) { return this.viewTraffic ? new TeeInputStream(is, System.out) : is; }
@Around("call(org.apache.axiom.om.OMElement org.apache.axis2.builder.Builder.processDocument(" + " java.io.InputStream, java.lang.String, org.apache.axis2.context.MessageContext))" + " && args(in, contentType, msgContext)") public Object aroundProcessDocument(ProceedingJoinPoint proceedingJoinPoint, InputStream in, String contentType, MessageContext msgContext) throws Throwable { InputStream tee; if (in == null) { tee = null; } else { OutputStream log = LogManager.INSTANCE.createLog("builder"); // Note: We can't close the log right after the method execution because the // message builder may use streaming. LogManager will take care of closing the // log for us if anything goes wrong. tee = new TeeInputStream(in, log, true); } return proceedingJoinPoint.proceed(new Object[] { tee, contentType, msgContext }); } }
public void copyStream(InputStream is, OutputStream os) { mos = new MuteableOutputStream(os); TeeInputStream tis = new TeeInputStream(is, mos); analyzer.analyze(tis); }
@Around("call(org.apache.axiom.om.OMElement org.apache.axis2.builder.Builder.processDocument(" + " java.io.InputStream, java.lang.String, org.apache.axis2.context.MessageContext))" + " && args(in, contentType, msgContext)") public Object aroundProcessDocument(ProceedingJoinPoint proceedingJoinPoint, InputStream in, String contentType, MessageContext msgContext) throws Throwable { if (LogManager.INSTANCE.isLoggingEnabled()) { InputStream tee; if (in == null) { tee = null; } else { OutputStream log = LogManager.INSTANCE.createLog("builder"); // Note: We can't close the log right after the method execution because the // message builder may use streaming. LogManager will take care of closing the // log for us if anything goes wrong. tee = new TeeInputStream(in, log, true); } return proceedingJoinPoint.proceed(new Object[] { tee, contentType, msgContext }); } else { return proceedingJoinPoint.proceed(); } } }
@Around("call(org.apache.axiom.om.OMElement org.apache.axis2.builder.Builder.processDocument(" + " java.io.InputStream, java.lang.String, org.apache.axis2.context.MessageContext))" + " && args(in, contentType, msgContext)") public Object aroundProcessDocument(ProceedingJoinPoint proceedingJoinPoint, InputStream in, String contentType, MessageContext msgContext) throws Throwable { if (LogManager.INSTANCE.isLoggingEnabled()) { InputStream tee; if (in == null) { tee = null; } else { OutputStream log = LogManager.INSTANCE.createLog("builder"); // Note: We can't close the log right after the method execution because the // message builder may use streaming. LogManager will take care of closing the // log for us if anything goes wrong. tee = new TeeInputStream(in, log, true); } return proceedingJoinPoint.proceed(new Object[] { tee, contentType, msgContext }); } else { return proceedingJoinPoint.proceed(); } } }
public CommandResponse run(final Command command) { logger.debug("Executing command {}", command); try { Process p = new ProcessBuilder(command.asList()).directory(new File(execDir)).start(); // We do this small trick to have stdout and stderr of the process on the console and // at the same time capture them to strings. ByteArrayOutputStream errors = new ByteArrayOutputStream(); ByteArrayOutputStream messages = new ByteArrayOutputStream(); Thread t1 = showProcessOutput(new TeeInputStream(p.getErrorStream(), errors), System.err); Thread t2 = showProcessOutput(new TeeInputStream(p.getInputStream(), messages), System.out); int code = p.waitFor(); t1.join(); t2.join(); CommandResponse response = new CommandResponse(code, errors.toString(), messages.toString()); if (!response.isSuccessful()) { throw new NonZeroCodeException(command, response); } return response; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException("Cannot execute " + command.toString(), e); } catch (IOException e) { throw new RuntimeException("Cannot execute " + command.toString(), e); } }
@Override public void run() { logger.debug("Checking for a change"); if (targetChanged()) { logger.debug("Target changed, checking if it's different than current flow."); try (FileInputStream configFile = new FileInputStream(configFilePath.toFile()); ByteArrayOutputStream pipedOutputStream = new ByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream(configFile, pipedOutputStream)) { if (differentiator.isNew(teeInputStream)) { logger.debug("New change, notifying listener"); // Fill the byteArrayOutputStream with the rest of the request data while (teeInputStream.available() != 0) { teeInputStream.read(); } ByteBuffer newConfig = ByteBuffer.wrap(pipedOutputStream.toByteArray()); ByteBuffer readOnlyNewConfig = newConfig.asReadOnlyBuffer(); configurationChangeNotifier.notifyListeners(readOnlyNewConfig); logger.debug("Listeners notified"); } } catch (Exception e) { logger.error("Could not successfully notify listeners.", e); } } }
/** * @param id * Short ID that indicates the log that we are watching. * @param printer * The printer to use to write the Jenkins logging statements to */ public JenkinsLogWatcher(String id, InputStream pipe, File logFile, final LogListener printer) throws FileNotFoundException { this.logFile = logFile; this.pipe = new TeeInputStream(pipe,new FileOutputStream(logFile)); splitter.addLogListener(printer); splitter.addLogListener(watcher); reader = new Thread(new LogReader(this.pipe,splitter),"Log reader: "+id); ready = watcher.watch(Pattern.compile("Jenkins is fully up and running")); portConflict = watcher.watch(Pattern.compile("java.net.BindException: Address already in use")); }
@Override public InputStream getData(String url) throws IOException { InputStream is = cache1.getData(url); if (is == null) { is = cache2.getData(url); if (is != null) { // synchronize with the first cache OutputStream os = cache1.putData(url); is = new TeeInputStream(is, os, true); } } return is; }
private InputStream cachedHttpRequest(HttpUriRequest request, HistoDbUrl url) throws IOException { InputStream is = null; if (cache != null) { is = cache.getData(url.format()); } if (is != null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Using cached data for query " + url.format()); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Using cached data for query " + url.prettyFormat()); } } else { is = httpRequest(request, url); if (cache != null && is != null) { OutputStream os = cache.putData(url.format()); is = new TeeInputStream(is, os, true); } } return is; }
private <T> T executeWithIODebug(InputStream origInputStream, Function<InputStream, T> callable) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream(origInputStream, bytes); try { return callable.apply(teeInputStream); } catch (Exception e) { Throwable root = ExceptionUtils.getRootCause(e); if (root != null) { System.err.println(root.toString()); root.printStackTrace(); } String msg = e.toString() + "\nstream contents:\n" + bytes.toString(StandardCharsets.UTF_8); throw new IOException(msg, e); } }