List of usage examples for java.io PipedOutputStream connect
public synchronized void connect(PipedInputStream snk) throws IOException
From source file:org.modelio.vbasic.net.ApacheUriConnection.java
/** * Same as {@link java.net.URLConnection#getOutputStream()}. * <p>/* w w w . j av a 2 s.c o m*/ * This implementation creates a {@link PipedOutputStream} to the Apache entity input stream. * It is strongly advised to <b>write to the returned stream in another thread</b>. * @see PipedOutputStream * @see PipedInputStream * @return an output stream that writes to this connection. * @throws java.io.IOException if an I/O error occurs while creating the output stream. */ @objid("79282b13-7e13-42d5-9917-892c78a155bd") @Override public OutputStream getOutputStream() throws IOException { if (!this.dooutput) throw new IllegalStateException("This is not an output connection"); if (this.req != null && !(this.req instanceof HttpPut)) throw new IllegalStateException("This is not an output connection"); PipedOutputStream outPipe = new PipedOutputStream(); PipedInputStream snk = new PipedInputStream(outPipe); outPipe.connect(snk); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(snk); HttpPut pr = (HttpPut) getRequest(); pr.setEntity(entity); return outPipe; }
From source file:eu.scape_project.service.ConnectorService.java
private void addMetadata(final Session session, final Object metadata, final String path) throws RepositoryException { final StringBuilder sparql = new StringBuilder("PREFIX scape: <" + SCAPE_NAMESPACE + "> "); try {/*from w w w. j a va 2 s . c om*/ /* use piped streams to copy the data to the repo */ final PipedInputStream dcSrc = new PipedInputStream(); final PipedOutputStream dcSink = new PipedOutputStream(); dcSink.connect(dcSrc); new Thread(new Runnable() { @Override public void run() { try { ConnectorService.this.marshaller.getJaxbMarshaller().marshal(metadata, dcSink); dcSink.flush(); dcSink.close(); } catch (JAXBException e) { LOG.error(e.getLocalizedMessage(), e); } catch (IOException e) { LOG.error(e.getLocalizedMessage(), e); } } }).start(); final Datastream ds = datastreamService.createDatastream(session, path, "text/xml", null, dcSrc); final Node desc = ds.getNode(); desc.addMixin("scape:metadata"); final IdentifierTranslator subjects = new DefaultIdentifierTranslator(); final String dsUri = subjects.getSubject(desc.getPath()).getURI(); /* get the type of the metadata */ String type = "unknown"; String schema = ""; if (metadata.getClass() == ElementContainer.class) { type = "dublin-core"; schema = "http://purl.org/dc/elements/1.1/"; } else if (metadata.getClass() == GbsType.class) { type = "gbs"; schema = "http://books.google.com/gbs"; } else if (metadata.getClass() == Fits.class) { type = "fits"; schema = "http://hul.harvard.edu/ois/xml/ns/fits/fits_output"; } else if (metadata.getClass() == AudioType.class) { type = "audiomd"; schema = "http://www.loc.gov/audioMD/"; } else if (metadata.getClass() == RecordType.class) { type = "marc21"; schema = "http://www.loc.gov/MARC21/slim"; } else if (metadata.getClass() == Mix.class) { type = "mix"; schema = "http://www.loc.gov/mix/v20"; } else if (metadata.getClass() == VideoType.class) { type = "videomd"; schema = "http://www.loc.gov/videoMD/"; } else if (metadata.getClass() == PremisComplexType.class) { type = "premis-provenance"; schema = "info:lc/xmlns/premis-v2"; } else if (metadata.getClass() == RightsComplexType.class) { type = "premis-rights"; schema = "info:lc/xmlns/premis-v2"; } else if (metadata.getClass() == TextMD.class) { type = "textmd"; schema = "info:lc/xmlns/textmd-v3"; } /* add a sparql query to set the type of this object */ sparql.append("INSERT DATA {<" + dsUri + "> " + prefix(HAS_TYPE) + " '" + type + "'};"); sparql.append("INSERT DATA {<" + dsUri + "> " + prefix(HAS_SCHEMA) + " '" + schema + "'};"); ds.updatePropertiesDataset(subjects, sparql.toString()); } catch (IOException e) { throw new RepositoryException(e); } catch (InvalidChecksumException e) { throw new RepositoryException(e); } }
From source file:com.actuate.development.tool.task.InstallBRDPro.java
private void interruptOutput(final IProgressMonitor monitor, final int[] currentStep, final DefaultLogger consoleLogger, final boolean[] flag, final String[] defaultTaskName) { String threadName = "Monitor Output"; if (current[0] != null && current[0].getName() != null) { linkBuffer.append(current[0].getName()).append("\n"); threadName += (": " + current[0].getName()); }/*from w w w .j a v a 2s.c o m*/ outputThread = new Thread(threadName) { public void run() { try { final Module module = current[0]; final int step = currentStep[0]; PipedInputStream pipedIS = new PipedInputStream(); PipedOutputStream pipedOS = new PipedOutputStream(); pipedOS.connect(pipedIS); BufferedReader input = new BufferedReader(new InputStreamReader(pipedIS)); PrintStream ps = new PrintStream(pipedOS); consoleLogger.setOutputPrintStream(ps); final String[] line = new String[1]; String extactingStr = "[exec] Extracting"; int length = "[exec]".length(); while ((line[0] = input.readLine()) != null) { if (module != current[0]) break; if (!flag[0]) { int index = line[0].indexOf(extactingStr); if (index != -1) { String file = line[0].substring(index + length); monitor.subTask("[Step " + step + "]" + file); if (module == null) { if (data.isInstallShield()) { file = file.trim().replaceAll("Extracting\\s+", ""); if (file.toLowerCase().indexOf("eclipse") > -1) { file = ("\\" + file); installBuffer.append(file + "\n"); } } else { file = file.trim().replaceAll("Extracting\\s+BRDPro", ""); installBuffer.insert(0, file + "\n"); } } else if (module.getType() == ModuleType.source && file.indexOf("eclipse\\plugins") > -1 && file.indexOf("source") > -1) { String prefix = "\\eclipse\\dropins"; file = (prefix + "\\" + file.trim().replaceAll("Extracting\\s+", "")); sourceBuffer.append(file).append("\n"); } } else { monitor.subTask(defaultTaskName[0]); } System.out.println(line[0]); } } input.close(); pipedIS.close(); consoleLogger.setOutputPrintStream(System.out); } catch (IOException e) { } } }; outputThread.start(); }
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); RequestEntity entity = new InputStreamRequestEntity(sink); ((EntityEnclosingMethod) method).setRequestEntity(entity); return source; }