@Before public void setUp() throws Exception { final InputStream input = new ByteArrayInputStream("abc".getBytes(ASCII)); output = new ByteArrayOutputStream(); tee = new TeeInputStream(input, output); }
if (responseBodyStream != null && outputBodyToRequestAttribute && outputBodyToResponseContent) { outputStreamToRequestAttribute = new SoftLimitBoundedByteArrayOutputStream(maxAttributeSize); teeInputStream = new TeeInputStream(responseBodyStream, outputStreamToRequestAttribute); teeInputStream.close(); teeInputStream = null; } else if(responseBodyStream != null){
@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); } } }
TeeInputStream tmpMsgIn = new TeeInputStream(msgIn, out); BodyOffsetInputStream bIn = new BodyOffsetInputStream(tmpMsgIn)) { while (tmpMsgIn.read(discard) != -1) {
@Override public int read() throws IOException { return tee.read(); } };
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); TeeInputStream is = new TeeInputStream(getDataUrl(...), bytes); try { // Pass is to parser here. parser.setInput(new InputStreamReader(is, "UTF-8")); // Note: please specify an encoding with InputStreamReader, maybe based on // the headers from getDataUrl. ... } finally { is.close(); } // After parsing finishes, convert the bytes to a String. String parsed = bytes.toString("UTF-8"); // If UTF-8 is not appropriate, use the encoding specified in headers from URL.
String responseText; try (ByteArrayOutputStream pipedOutputStream = new ByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream(request.getInputStream(), pipedOutputStream)) { while (teeInputStream.available() != 0) { teeInputStream.read();
@Override public int read() throws IOException { return tee.read(); } };
/** * 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); teeInputStream.close(); teeInputStream = null; } else if(responseBodyStream != null){
@Override public int read() throws IOException { return tee.read(); } };
logger.debug("Using a TeeInputStream as we need to store the source"); bos = new ByteArrayOutputStream(); inputStream = new TeeInputStream(inputStream, bos);
@Override public int read() throws IOException { return this.wrapper.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(); } }; }
@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 }); } }