org.apache.commons.io.input.TeeInputStream Java Examples
The following examples show how to use
org.apache.commons.io.input.TeeInputStream.
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: RequestWrapper.java From wisp with Apache License 2.0 | 6 votes |
@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(); } }; }
Example #2
Source File: FileChangeIngestor.java From nifi-minifi with Apache License 2.0 | 5 votes |
@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); } } }
Example #3
Source File: MCRDefaultConfigurationLoader.java From mycore with GNU General Public License v3.0 | 5 votes |
private InputStream getConfigInputStream() throws IOException { MCRConfigurationInputStream configurationInputStream = MCRConfigurationInputStream .getMyCoRePropertiesInstance(); File configFile = MCRConfigurationDir.getConfigFile("mycore.active.properties"); if (configFile != null) { FileOutputStream fout = new FileOutputStream(configFile); return new TeeInputStream(configurationInputStream, fout, true); } return configurationInputStream; }
Example #4
Source File: DownloadUtils.java From TomboloDigitalConnector with MIT License | 5 votes |
public InputStream fetchInputStream(URL url, String prefix, String suffix) throws IOException { createCacheDir(prefix); File localDatasourceFile = urlToLocalFile(url, prefix, suffix); log.info("Fetching local file: {}", localDatasourceFile.getCanonicalPath()); if (!localDatasourceFile.exists()){ log.info("Local file not found: {} \nDownloading external resource: {}", localDatasourceFile.getCanonicalPath(), url.toString()); URLConnection urlConnection = url.openConnection(); urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 " + "(KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11"); if (suffix.equals(".json")) { urlConnection.setRequestProperty("Accept", "application/json"); } urlConnection.connect(); if (urlConnection instanceof HttpURLConnection) { HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection; int responseCode = httpURLConnection.getResponseCode(); if (responseCode != HttpURLConnection.HTTP_OK) { throw new IOException(String.format("Cannot get the stream from the specified URL: %s\n%d: %s", url.getPath(), responseCode, httpURLConnection.getResponseMessage())); } } return new TeeInputStream(urlConnection.getInputStream(), new FileOutputStream(localDatasourceFile)); } else { return new FileInputStream(localDatasourceFile); } }
Example #5
Source File: ResettableInputStream.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
public ResettableInputStream(InputStream in) throws IOException { InputStream unwrappedInput = EnhancedBufferedInputStream.tryUnwrap(in); if (!(unwrappedInput instanceof FileInputStream)) { tmpFile = Files.createTempFile("vlt_tmp", null); tmpOutputStream = new BufferedOutputStream(Files.newOutputStream(tmpFile)); log.debug("Caching input stream in temp file '{}' for later evaluation by another validator", tmpFile); currentInput = new TeeInputStream(in, tmpOutputStream); } else { tmpFile = null; tmpOutputStream = null; currentInput = in; } }
Example #6
Source File: CommonsIOUnitTest.java From tutorials with MIT License | 5 votes |
@SuppressWarnings("resource") @Test public void whenUsingTeeInputOutputStream_thenWriteto2OutputStreams() throws IOException { final String str = "Hello World."; ByteArrayInputStream inputStream = new ByteArrayInputStream(str.getBytes()); ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); FilterOutputStream teeOutputStream = new TeeOutputStream(outputStream1, outputStream2); new TeeInputStream(inputStream, teeOutputStream, true).read(new byte[str.length()]); Assert.assertEquals(str, String.valueOf(outputStream1)); Assert.assertEquals(str, String.valueOf(outputStream2)); }
Example #7
Source File: RestChangeIngestor.java From nifi-minifi with Apache License 2.0 | 4 votes |
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logRequest(request); baseRequest.setHandled(true); if (POST.equals(request.getMethod())) { int statusCode; String responseText; try (ByteArrayOutputStream pipedOutputStream = new ByteArrayOutputStream(); TeeInputStream teeInputStream = new TeeInputStream(request.getInputStream(), pipedOutputStream)) { if (differentiator.isNew(teeInputStream)) { // Fill the pipedOutputStream with the rest of the request data while (teeInputStream.available() != 0) { teeInputStream.read(); } ByteBuffer newConfig = ByteBuffer.wrap(pipedOutputStream.toByteArray()); ByteBuffer readOnlyNewConfig = newConfig.asReadOnlyBuffer(); Collection<ListenerHandleResult> listenerHandleResults = configurationChangeNotifier.notifyListeners(readOnlyNewConfig); statusCode = 200; for (ListenerHandleResult result : listenerHandleResults) { if (!result.succeeded()) { statusCode = 500; break; } } responseText = getPostText(listenerHandleResults); } else { statusCode = 409; responseText = "Request received but instance is already running this config."; } writeOutput(response, responseText, statusCode); } } else if (GET.equals(request.getMethod())) { writeOutput(response, GET_TEXT, 200); } else { writeOutput(response, OTHER_TEXT, 404); } }
Example #8
Source File: ParsecServletRequestWrapper.java From parsec-libraries with Apache License 2.0 | 4 votes |
DelegatedInputStream(ServletInputStream servletStream) { this.servletStream = servletStream; this.teeStream = new TeeInputStream(servletStream, contentStream); }
Example #9
Source File: TelnetClient.java From Android-Telnet-Client with Apache License 2.0 | 4 votes |
private InputStreamReader spawnSpy(InputStream in, PipedOutputStream pipeout) throws InterruptedException { return new InputStreamReader(new TeeInputStream(in,pipeout)); }