List of usage examples for java.io PipedInputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(); // connect input and output in.connect(out);// ww w . jav a2 s . c o m // write something out.write(70); out.write(71); // read what we wrote for (int i = 0; i < 2; i++) { System.out.println("" + (char) in.read()); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(); // connect input and output in.connect(out);/*w w w .j av a2s .c o m*/ // write something out.write(70); out.write(71); // read what we wrote for (int i = 0; i < 2; i++) { System.out.println("" + (char) in.read()); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(); // connect input and output in.connect(out);/*from www. j ava 2 s .co m*/ // write something out.write(70); out.write(71); // read what we wrote for (int i = 0; i < 2; i++) { System.out.println("" + (char) in.read()); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(200); // connect input and output in.connect(out);/*from ww w. ja v a 2 s . com*/ // write something out.write(70); out.write(71); // read what we wrote for (int i = 0; i < 2; i++) { System.out.println("" + (char) in.read()); } in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(); // connect input and output in.connect(out);//from w ww .jav a 2 s . com // write something out.write(70); out.write(71); // read what we wrote into an array of bytes byte[] b = new byte[2]; in.read(b, 0, 2); System.out.println(new String(b)); in.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(); // connect input and output in.connect(out);//from w ww . jav a2s. c o m // write something out.write(70); out.write(71); // print how many bytes are available System.out.println(in.available()); // read what we wrote for (int i = 0; i < 2; i++) { System.out.println("" + (char) in.read()); } in.close(); }
From source file:Main.java
public static void consumeData(PipedInputStream pis) { try {//from ww w .j av a 2 s . co m int num = -1; while ((num = pis.read()) != -1) { System.out.println("Reading: " + num); } pis.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:de.upb.wdqa.wdvd.processors.output.CsvFeatureWriter.java
private static OutputStream getPipedOutputStreamStream(final OutputStream outputStream) throws IOException { final int BUFFER_SIZE = 1 * 1024 * 1024; final PipedOutputStream pipedOutputStream = new PipedOutputStream(); final PipedInputStream pipedInputStream = new PipedInputStream(pipedOutputStream, BUFFER_SIZE); new Thread("Label Writer Output Stream") { @Override/* w ww . ja v a2s.c o m*/ public void run() { try { IOUtils.copy(pipedInputStream, outputStream); pipedInputStream.close(); outputStream.close(); } catch (Throwable t) { logger.error("", t); } } }.start(); return pipedOutputStream; }
From source file:com.heliosapm.tsdblite.json.JSON.java
/** * Serializes the passed object and pipes back the results in an InputStream to read it back. * Spawns a thread to run the pipe out so the calling thread only needs to read the returned input stream. * If the serialization fails, the worker thread will close the inoput stream to signal the failure. * @param obj The object to serialize//from ww w .j a v a 2 s. c o m * @return an InputStream to read back the JSON serialized object */ public static InputStream serializeLoopBack(final Object obj) { if (obj == null) throw new IllegalArgumentException("The passed object was null"); try { final PipedInputStream pin = new PipedInputStream(2048); final PipedOutputStream pout = new PipedOutputStream(pin); final Thread t = new Thread("serializeLoopBackThread") { @Override public void run() { try { serialize(obj, pout); } catch (Exception ex) { try { pin.close(); } catch (Exception x) { /* No Op */} } } }; t.setDaemon(true); t.start(); return pin; } catch (Exception ex) { throw new RuntimeException("Failed to pipe serialized object", ex); } }
From source file:edu.cornell.mannlib.vitro.webapp.utils.jena.SesameSyncUtils.java
public void writeModelToSesameContext(Model jenaModel, String serverURI, String repositoryId, String contextId) throws RepositoryException, IOException, RDFParseException { Repository myRepository = new HTTPRepository(serverURI, repositoryId); myRepository.initialize();/*from ww w. j av a 2 s. c o m*/ RepositoryConnection myConn = myRepository.getConnection(); myConn.setAutoCommit(false); try { Resource contextRes = (contextId != null) ? new URIImpl(contextId) : null; if (contextRes != null) { myConn.clear(contextRes); } else { myConn.clear(); } PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(in); try { new Thread(new JenaOutputter(jenaModel, out, myConn), "SesameSyncUtilities.JenaOutputter").start(); if (contextRes != null) { myConn.add(in, "http://example.org/base/", RDFFormat.NTRIPLES, contextRes); } else { myConn.add(in, "http://example.org/base/", RDFFormat.NTRIPLES); } } finally { in.close(); } myConn.commit(); } catch (Throwable e) { myConn.rollback(); e.printStackTrace(); log.error("Error writing to Sesame repository", e); throw new RuntimeException("Error writing to Sesame repository", e); } finally { myConn.close(); } }