List of usage examples for java.io PipedInputStream PipedInputStream
public PipedInputStream()
PipedInputStream
so that it is not yet #connect(java.io.PipedOutputStream) connected . From source file:ee.ioc.cs.vsle.util.Console.java
private Console() { // create all components and add them frame = new JFrame("Java Console"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = new Dimension((screenSize.width / 2), (screenSize.height / 2)); int x = (frameSize.width / 2); int y = (frameSize.height / 2); frame.setBounds(x, y, frameSize.width, frameSize.height); textArea = new JTextArea(); textArea.setEditable(false);// ww w .j a va 2 s . c om JButton button = new JButton("clear"); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(new JScrollPane(textArea), BorderLayout.CENTER); frame.getContentPane().add(button, BorderLayout.SOUTH); frame.setVisible(true); frame.addWindowListener(this); button.addActionListener(this); final PipedInputStream pin = new PipedInputStream(); try { PipedOutputStream pout = new PipedOutputStream(pin); System.setOut(new PrintStream(new TeeOutputStream(systemOut, pout), true)); } catch (java.io.IOException io) { textArea.append("Couldn't redirect STDOUT to this console\n" + io.getMessage()); } catch (SecurityException se) { textArea.append("Couldn't redirect STDOUT to this console\n" + se.getMessage()); } final PipedInputStream pin2 = new PipedInputStream(); try { PipedOutputStream pout2 = new PipedOutputStream(pin2); System.setErr(new PrintStream(new TeeOutputStream(systemErr, pout2), true)); } catch (java.io.IOException io) { textArea.append("Couldn't redirect STDERR to this console\n" + io.getMessage()); } catch (SecurityException se) { textArea.append("Couldn't redirect STDERR to this console\n" + se.getMessage()); } quit = false; // signals the Threads that they should exit sysOutFollower = new StreamFollower(pin, StreamRestorer.SYS_OUT, "Console_out"); sysOutFollower.start(); // sysErrFollower = new StreamFollower(pin2, StreamRestorer.SYS_ERR, "Console_err"); sysErrFollower.start(); }
From source file:com.github.brandtg.switchboard.MysqlLogPuller.java
/** * Creates an agent to listen to MySQL changes (via binlog). * * @param database/*w ww. jav a2 s .c o m*/ * The MySQL database name * @param sourceAddress * The switchboard server address from which to pull events * @param sinkAddress * The local listener port to receive raw binlog data * @param lastIndex * The last index that was processed by whoever is constructing this (if -1, processed none) */ public MysqlLogPuller(String database, InetSocketAddress sourceAddress, InetSocketAddress sinkAddress, long lastIndex) { this.database = database; this.lastIndex = lastIndex; this.sourceAddress = sourceAddress; this.sinkAddress = sinkAddress; this.inputStream = new PipedInputStream(); this.outputStream = new PipedOutputStream(); this.isStarted = new AtomicBoolean(); }
From source file:com.mycollab.vaadin.resources.StreamDownloadResourceSupportExtDrive.java
@Override public InputStream getStream() { if (resources.size() == 1) { Resource res = resources.iterator().next(); if (!(res instanceof Folder)) { if (res.isExternalResource()) { ExternalResourceService service = ResourceUtils .getExternalResourceService(ResourceUtils.getType(res)); return service.download(ResourceUtils.getExternalDrive(res), res.getPath()); } else { return resourceService.getContentStream(res.getPath()); }/* w w w . j a v a 2 s . c o m*/ } } final PipedInputStream inStream = new PipedInputStream(); final PipedOutputStream outStream; try { outStream = new PipedOutputStream(inStream); } catch (IOException ex) { LOG.error("Can not create outstream file", ex); return null; } Thread threadExport = new MyCollabThread(new Runnable() { @Override public void run() { try { ZipOutputStream zipOutStream = new ZipOutputStream(outStream); zipResource(zipOutStream, resources); zipOutStream.close(); outStream.close(); } catch (Exception e) { LOG.error("Error while saving content stream", e); } } }); threadExport.start(); return inStream; }
From source file:com.esofthead.mycollab.vaadin.resources.StreamDownloadResourceSupportExtDrive.java
@Override public InputStream getStream() { if (resources.size() == 1) { Resource res = resources.iterator().next(); if (res.isExternalResource()) { ExternalResourceService service = ResourceUtils .getExternalResourceService(ResourceUtils.getType(res)); return service.download(ResourceUtils.getExternalDrive(res), res.getPath()); } else {//from ww w . j a v a2s . c o m return resourceService.getContentStream(res.getPath()); } } final PipedInputStream inStream = new PipedInputStream(); final PipedOutputStream outStream; try { outStream = new PipedOutputStream(inStream); } catch (IOException ex) { LOG.error("Can not create outstream file", ex); return null; } Thread threadExport = new MyCollabThread(new Runnable() { @Override public void run() { try { ZipOutputStream zipOutStream = new ZipOutputStream(outStream); zipResource(zipOutStream, resources); zipOutStream.close(); outStream.close(); } catch (Exception e) { LOG.error("Error while saving content stream", e); } } }); threadExport.start(); return inStream; }
From source file:com.ibm.stocator.fs.swift.SwiftOutputStream.java
/** * Default constructor// ww w.ja v a 2s . c om * * @param account JOSS account object * @param url URL connection * @param contentType content type * @param metadata input metadata * @param connectionManager SwiftConnectionManager * @throws IOException if error */ public SwiftOutputStream(JossAccount account, URL url, final String contentType, Map<String, String> metadata, SwiftConnectionManager connectionManager) throws IOException { mUrl = url; totalWritten = 0; mAccount = account; client = connectionManager.createHttpConnection(); request = new HttpPut(mUrl.toString()); request.addHeader("X-Auth-Token", account.getAuthToken()); if (metadata != null && !metadata.isEmpty()) { for (Map.Entry<String, String> entry : metadata.entrySet()) { request.addHeader("X-Object-Meta-" + entry.getKey(), entry.getValue()); } } PipedOutputStream out = new PipedOutputStream(); final PipedInputStream in = new PipedInputStream(); out.connect(in); execService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); mOutputStream = out; Callable<Void> task = new Callable<Void>() { @Override public Void call() throws Exception { InputStreamEntity entity = new InputStreamEntity(in, -1); entity.setChunked(true); entity.setContentType(contentType); request.setEntity(entity); LOG.debug("HTTP PUT request {}", mUrl.toString()); HttpResponse response = client.execute(request); int responseCode = response.getStatusLine().getStatusCode(); LOG.debug("HTTP PUT response {}. Response code {}", mUrl.toString(), responseCode); if (responseCode == 401) { // Unauthorized error mAccount.authenticate(); request.removeHeaders("X-Auth-Token"); request.addHeader("X-Auth-Token", mAccount.getAuthToken()); LOG.warn("Token recreated for {}. Retry request", mUrl.toString()); response = client.execute(request); responseCode = response.getStatusLine().getStatusCode(); } if (responseCode >= 400) { // Code may have changed from retrying throw new IOException("HTTP Error: " + responseCode + " Reason: " + response.getStatusLine().getReasonPhrase()); } return null; } }; futureTask = execService.submit(task); }
From source file:org.hawkular.rest.ResponseUtil.java
private static <T> InputStream pageToStream(Page<T> page, ObjectMapper mapper, Runnable callback) throws IOException { final PipedOutputStream outs = new PipedOutputStream(); final PipedInputStream ins = new PipedInputStream() { @Override//from ww w. j a v a 2 s. c o m public void close() throws IOException { outs.close(); super.close(); } }; outs.connect(ins); mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); PageToStreamThreadPool.getInstance().submit(() -> { try (Page<T> closeablePage = page; PipedOutputStream out = outs; SequenceWriter sequenceWriter = mapper.writer().writeValuesAsArray(out)) { for (T element : closeablePage) { sequenceWriter.write(element); sequenceWriter.flush(); } } catch (IOException e) { throw new IllegalStateException("Unable to convert page to input stream.", e); } finally { callback.run(); } }); return ins; }
From source file:fitnesse.FitNesseExpediterTest.java
private FitNesseExpediter preparePipedFitNesseExpediter() throws Exception { PipedInputStream socketInput = new PipedInputStream(); clientOutput = new PipedOutputStream(socketInput); clientInput = new PipedInputStream(); PipedOutputStream socketOutput = new PipedOutputStream(clientInput); return new FitNesseExpediter(injector, socketInput, socketOutput, 200); }
From source file:org.taverna.server.master.soap.WrappedWorkflow.java
@Override public InputStream getInputStream() throws IOException { PipedInputStream is = new PipedInputStream(); final OutputStream os = new PipedOutputStream(is); new Worker() { @Override/*from w w w . java 2 s. c o m*/ public void doWork() throws WriterException, IOException { io.writeBundle(wf.getScufl2Workflow(), os, wf.getPreferredContentType().getContentType()); } @Override public void doneWork() { closeQuietly(os); } }; return is; }
From source file:org.bimserver.ifcengine.JvmIfcEngine.java
private void startLocal() { try {// w w w . j ava 2s.com PipedInputStream pipedInputStream = new PipedInputStream(); PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream); IfcEngineServer ifcEngineServer = new IfcEngineServer(schemaFile.getAbsolutePath(), pipedInputStream, pipedOutputStream, null); in = new DataInputStream(new BufferedInputStream(pipedInputStream)); out = new DataOutputStream(new BufferedOutputStream(pipedOutputStream)); ifcEngineServer.start(); } catch (IOException e) { LOGGER.error("", e); } }
From source file:org.nuxeo.ecm.core.opencmis.impl.client.protocol.http.HttpURLConnection.java
@Override public OutputStream getOutputStream() throws IOException { PipedOutputStream source = new PipedOutputStream(); PipedInputStream sink = new PipedInputStream(); source.connect(sink);/*from w w w. j a v a 2 s .c om*/ RequestEntity entity = new InputStreamRequestEntity(sink); ((EntityEnclosingMethod) method).setRequestEntity(entity); return source; }