List of usage examples for java.io PipedReader PipedReader
public PipedReader()
PipedReader
so that it is not yet #connect(java.io.PipedWriter) connected . From source file:Main.java
public static void main(String[] args) { char[] c = { 'h', 'e', 'l', 'l', 'o' }; PipedWriter writer = new PipedWriter(); PipedReader reader = new PipedReader(); try {//from w w w.ja v a2 s . c om // connect the reader and the writer writer.connect(reader); writer.write(c, 0, 3); // print what we wrote for (int i = 0; i < 3; i++) { System.out.println((char) reader.read()); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.willwinder.universalgcodesender.BufferedCommunicatorTest.java
@Test public void testSimpleRawStreamStream() throws Exception { String[] inputs = { "input1", "input2" }; for (String i : inputs) { mockScl.messageForConsole(EasyMock.anyString()); EasyMock.expect(EasyMock.expectLastCall()); mockConnection.sendStringToComm(i + "\n"); EasyMock.expect(EasyMock.expectLastCall()); mockScl.commandSent(EasyMock.<GcodeCommand>anyObject()); EasyMock.expect(EasyMock.expectLastCall()); }// ww w. j a va2s . c o m EasyMock.replay(mockConnection, mockScl); PipedReader in = new PipedReader(); try (PipedWriter out = new PipedWriter(in)) { for (String i : inputs) { out.append(i + "\n"); } } instance.queueRawStreamForComm(in); instance.streamCommands(); EasyMock.verify(mockConnection, mockScl); }
From source file:com.willwinder.universalgcodesender.AbstractControllerTest.java
/** * Test of queueRawStream method, of class AbstractController. *//*from www . j av a 2 s. com*/ @Test public void testQueueRawStreamForComm() throws Exception { System.out.println("queueStream"); String command = "command"; Collection<String> commands = Arrays.asList(command, command); String port = "/some/port"; int rate = 1234; PipedReader in = new PipedReader(); PipedWriter out = new PipedWriter(in); for (String i : commands) { out.append(i); } openInstanceExpectUtility(port, rate); streamInstanceExpectUtility(); // TODO Fix this // Making sure the commands get queued. mockCommunicator.queueRawStreamForComm(in); EasyMock.expect(EasyMock.expectLastCall()).times(1); EasyMock.replay(instance, mockCommunicator); // Open port, send some commands, make sure they are streamed. instance.openCommPort(port, rate); instance.queueRawStream(in); instance.beginStreaming(); EasyMock.verify(mockCommunicator, instance); }
From source file:ome.services.fulltext.PdfParser.java
PdfThread(File file) throws IOException { this.file = file; reader = new PipedReader(); writer = new PipedWriter(reader); }
From source file:org.apache.rat.Report.java
/** * //from w ww . j ava 2s . c om * Output a report that is styled using a defined stylesheet. * * @param out the writer to write the report to * @param base the files or directories to report on * @param style an input stream representing the stylesheet to use for styling the report * @param pConfiguration current report configuration. * * @throws FileNotFoundException in case of I/O errors. * @throws IOException in case of I/O errors. * @throws TransformerConfigurationException in case of XML errors. * @throws InterruptedException in case of threading errors. * @throws RatException in case of internal errors. * * @return the currently collected numerical statistics. */ public static ClaimStatistic report(Writer out, IReportable base, final InputStream style, ReportConfiguration pConfiguration) throws IOException, TransformerConfigurationException, FileNotFoundException, InterruptedException, RatException { PipedReader reader = new PipedReader(); PipedWriter writer = new PipedWriter(reader); ReportTransformer transformer = new ReportTransformer(out, style, reader); Thread transformerThread = new Thread(transformer); transformerThread.start(); final ClaimStatistic statistic = report(base, writer, pConfiguration); writer.flush(); writer.close(); transformerThread.join(); return statistic; }
From source file:org.lexgrid.valuesets.helper.VSDServiceHelper.java
/** * This method exports the data in LexGRID XML format to a PipedWriter which * can be read using Reader as it writes. * /*from w ww. j a va2 s .c o m*/ * @throws LBException */ private InputStream marshalToXml(final Object obj, final CodedNodeGraph cng, final CodedNodeSet cns, final int pageSize, final boolean useStreaming, final boolean validate, final LgMessageDirectorIF messager) throws LBException { final PipedReader in = new PipedReader(); final Marshaller marshaller = ns_marshaller; try { new Thread(new Runnable() { PipedWriter out = new PipedWriter(in); public void run() { try { MarshalListener listener = null; if (useStreaming == true) { listener = new StreamingLexGridMarshalListener(marshaller, cng, cns, pageSize, messager); } else { listener = new LexGridMarshalListener(marshaller, cng, cns, pageSize); } marshaller.setValidation(validate); marshaller.setMarshalListener(listener); marshaller.setWriter(out); marshaller.marshal(obj); out.close(); // close the writer after the marshaling // job done } catch (Exception e) { throw new RuntimeException(e); } } }).start(); } catch (IOException e) { messager.error("Problem marshalling value set resolution : " + e.getMessage()); throw new LBException("Problem marshalling value set resolution : " + e.getMessage()); } InputStream is = null; if (in != null) is = new ReaderInputStream(in); return is; }
From source file:org.springframework.integration.support.json.BoonJsonObjectMapper.java
@Override @SuppressWarnings("unchecked") public Map<String, Object> toJsonNode(final Object value) throws Exception { PipedReader in = new PipedReader(); final PipedWriter out = new PipedWriter(in); Executors.newSingleThreadExecutor().execute(() -> toJson(value, out)); return (Map<String, Object>) this.slurper.parse(in); }
From source file:org.wymiwyg.commons.prevamodel.PrevaGraph.java
/** * /*from w w w. j a va 2 s . c o m*/ */ private void read() throws IOException { final Set triples = new HashSet(); File defaultStore = new File(directory, "store.rdf"); File newStore = new File(directory, "store-new.rdf"); if (defaultStore.exists()) { if (newStore.exists()) { newStore.delete(); } BufferedReader in = new BufferedReader(new FileReader(defaultStore)); String line = in.readLine(); while (line != null) { triples.add(line); line = in.readLine(); } in.close(); } else { if (newStore.exists()) { newStore.renameTo(defaultStore); } } String[] logFiles = directory.list(new FilenameFilter() { /** * @see java.io.FilenameFilter#accept(java.io.File, * java.lang.String) */ public boolean accept(File dir, String name) { return name.startsWith("log-"); } }); Arrays.sort(logFiles, new Comparator() { public int compare(Object arg0, Object arg1) { return getLogNumber((String) arg0) - getLogNumber((String) arg1); } private int getLogNumber(String string) { String substring = string.substring(4); int endOfNumer = substring.indexOf('-'); String numberString = substring.substring(0, endOfNumer); return Integer.parseInt(numberString); } }); for (int i = 0; i < logFiles.length; i++) { File log = new File(directory, logFiles[i]); BufferedReader logIn = new BufferedReader(new FileReader(log)); String entry = logIn.readLine(); String nextLine = logIn.readLine(); if (nextLine != null) { throw new RuntimeException(log + " is multiline"); } if (entry == null) { logger.warn(log + " is empty, ignoring"); continue; } logIn.close(); if (logFiles[i].indexOf("add") != -1) { triples.add(entry); } else { triples.remove(entry); } } //Model model = ModelFactory.createModelForGraph(this); PipedReader pipedIn = new PipedReader(); final PipedWriter pipedOut = new PipedWriter(pipedIn); new Thread() { public void run() { PrintWriter printOut = new PrintWriter(new BufferedWriter(pipedOut)); Iterator iter = triples.iterator(); while (iter.hasNext()) { String element = (String) iter.next(); printOut.println(element); } printOut.close(); } }.start(); ModelFactory.createModelForGraph(this).read(pipedIn, "", "N-TRIPLE"); }