private static String getScriptTrace(Exception e) { try { PipedReader reader = new PipedReader(8192); PrintWriter writer = new PrintWriter(new PipedWriter(reader)); e.printStackTrace(writer); writer.close(); BufferedReader bufferedReader = new BufferedReader(reader); String line; StringBuilder scriptTrace = new StringBuilder(e.getMessage()); while ((line = bufferedReader.readLine()) != null) { if (line.trim().startsWith("at script")) scriptTrace.append("\n").append(line); } return scriptTrace.toString(); } catch (IOException e1) { e1.printStackTrace(); return e.getMessage(); } }
private static String getScriptTrace(Exception e) { try { PipedReader reader = new PipedReader(8192); PrintWriter writer = new PrintWriter(new PipedWriter(reader)); e.printStackTrace(writer); writer.close(); BufferedReader bufferedReader = new BufferedReader(reader); String line; StringBuilder scriptTrace = new StringBuilder(TextUtils.toEmptyIfNull(e.getMessage())); while ((line = bufferedReader.readLine()) != null) { if (line.trim().startsWith("at script")) scriptTrace.append("\n").append(line); } return scriptTrace.toString(); } catch (IOException e1) { e1.printStackTrace(); return e.getMessage(); } }
/** * The constructor * * @param resourceId the resource identifier, must not be null * @param context the owner context for the pipe, must not be null * @throws IOException it will be thrown if there will be any transport errors */ public ProlMemoryPipe(final String resourceId, final ProlContext context) throws IOException { if (resourceId == null) { throw new IllegalArgumentException("Resource identifier must not be null"); } if (context == null) { throw new IllegalArgumentException("Context must not be null"); } this.resourceId = resourceId; this.context = context; final PipedWriter pipeWriter = new PipedWriter(); final PipedReader pipeReader = new PipedReader(pipeWriter); reader = new ProlTextInputStream(pipeReader, context); writer = new ProlTextOutputStream(pipeWriter, context, false); }
/** * @tests java.io.PipedWriter#close() */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "close", args = {} ) public void test_close() throws Exception { PipedReader rd = new PipedReader(); pw = new PipedWriter(rd); reader = new PReader(rd); try { pw.close(); } catch (IOException e) { fail("Test 1: Unexpected IOException: " + e.getMessage()); } }
/** * @tests java.io.PipedReader#connect(java.io.PipedWriter) */ public void test_connectLjava_io_PipedWriter() throws Exception { char[] c = null; preader = new PipedReader(); t = new Thread(pwriter = new PWriter(), ""); preader.connect(pwriter.pw); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; preader.read(c, 0, 11); assertEquals("Read incorrect chars", "Hello World", new String(c)); try { preader.connect(pwriter.pw); fail("Failed to throw exception connecting to pre-connected reader"); } catch (IOException e) { // Expected } }
/** * @tests java.io.PipedReader#read(char[], int, int) */ public void test_read$CII() throws Exception { char[] c = null; preader = new PipedReader(); t = new Thread(new PWriter(preader), ""); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; int n = 0; int x = n; while (x < 11) { n = preader.read(c, x, 11 - x); x = x + n; } assertEquals("Read incorrect chars", "Hello World", new String(c)); try { preader.close(); preader.read(c, 8, 7); fail("Failed to throw exception reading from closed reader"); } catch (IOException e) { // Expected } }
/** * @tests java.io.PipedWriter#close() */ public void test_close() throws Exception { // Test for method void java.io.PipedWriter.close() char[] buf = new char[10]; "HelloWorld".getChars(0, 10, buf, 0); PipedReader rd = new PipedReader(); pw = new PipedWriter(rd); reader = new PReader(rd); pw.close(); try { pw.write(buf); fail("Should have thrown exception when attempting to write to closed writer."); } catch (Exception e) { // correct } }
/** * @tests java.io.PipedWriter#connect(java.io.PipedReader) */ public void test_connectLjava_io_PipedReader() throws Exception { // Test for method void java.io.PipedWriter.connect(java.io.PipedReader) char[] buf = new char[10]; "HelloWorld".getChars(0, 10, buf, 0); PipedReader rd = new PipedReader(); pw = new PipedWriter(); pw.connect(rd); rdrThread = new Thread(reader = new PReader(rd), "connect"); rdrThread.start(); pw.write(buf); pw.close(); rdrThread.join(500); assertEquals("Failed to write correct chars", "HelloWorld", new String( reader.buf)); }
public Writer create() throws IOException { final PipedReader in = new PipedReader(); PipedWriter out = new PipedWriter(in); executor = Executors.newSingleThreadExecutor(); future = executor.submit(new Callable<char[]>() { final CharArrayWriter chars = new CharArrayWriter(); public char[] call() throws Exception { char[] buffer = new char[256]; int count; while ((count = in.read(buffer)) != -1) { chars.write(buffer, 0, count); } return chars.toCharArray(); } }); return out; }
/** * @tests java.io.PipedReader#connect(java.io.PipedWriter) */ public void test_connectLjava_io_PipedWriter() throws Exception { // Test for method void java.io.PipedReader.connect(java.io.PipedWriter) char[] c = null; preader = new PipedReader(); t = new Thread(pwriter = new PWriter(), ""); preader.connect(pwriter.pw); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; preader.read(c, 0, 11); assertEquals("Read incorrect chars", "Hello World", new String(c)); try { preader.connect(pwriter.pw); fail("Failed to throw exception connecting to pre-connected reader"); } catch (Exception e) { // Correct } }
/** * @tests java.io.PipedReader#read(char[], int, int) */ public void test_read$CII() throws Exception { // Test for method int java.io.PipedReader.read(char [], int, int) char[] c = null; preader = new PipedReader(); t = new Thread(new PWriter(preader), ""); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; int n = 0; int x = n; while (x < 11) { n = preader.read(c, x, 11 - x); x = x + n; } assertEquals("Read incorrect chars", "Hello World", new String(c)); try { preader.close(); preader.read(c, 8, 7); fail("Failed to throw exception reading from closed reader"); } catch (Exception e) { // Correct } }
/** * Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110]. * * @throws IOException */ @Test public void testGetOneLineOneParser() throws IOException { final CSVFormat format = CSVFormat.DEFAULT; try (final PipedWriter writer = new PipedWriter(); final CSVParser parser = new CSVParser(new PipedReader(writer), format)) { writer.append(CSV_INPUT_1); writer.append(format.getRecordSeparator()); final CSVRecord record1 = parser.nextRecord(); assertArrayEquals(RESULT[0], record1.values()); writer.append(CSV_INPUT_2); writer.append(format.getRecordSeparator()); final CSVRecord record2 = parser.nextRecord(); assertArrayEquals(RESULT[1], record2.values()); } }
private static PipedReader newPipedReader(String contents) { try (PipedWriter w = new PipedWriter()) { PipedReader r = new PipedReader(w); w.write(contents); return r; } catch (IOException e) { throw new UncheckedIOException(e); } }
/** * Run the org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents createComponents(String,Reader) * method test. * * @throws Exception * * @generatedBy CodePro at 9/10/14 10:27 AM */ @Test public void testCreateComponents_1() throws Exception { TankAnalyzer fixture = new TankAnalyzer(Version.LUCENE_20); String fieldName = ""; Reader reader = new PipedReader(); org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents result = fixture.createComponents( fieldName, reader); assertNotNull(result); }
private void testInterruptReader(final PipedReader reader) throws Exception { Thread thread = interruptMeLater(); try { reader.read(); fail(); } catch (InterruptedIOException expected) { } finally { confirmInterrupted(thread); } }
public PReader(PipedWriter pw) { try { pr = new PipedReader(pw); } catch (IOException e) { System.out.println("Exception setting up reader: " + e.toString()); } }
public void test_close() throws Exception { PipedReader rd = new PipedReader(); pw = new PipedWriter(rd); reader = new PReader(rd); try { pw.close(); } catch (IOException e) { fail("Test 1: Unexpected IOException: " + e.getMessage()); } }
@Test public void testCheckWrittenResult() throws Exception { final PipedWriter writer = new PipedWriter(); final BufferedReader reader = new BufferedReader(new PipedReader(writer)); resultWriter.writeTo(writer); final String resultString = reader.readLine(); assertThat("Case #1: 2", is(equalTo(resultString))); }
public PWriter(PipedReader reader) { try { pw = new PipedWriter(reader); } catch (Exception e) { System.out.println("Couldn't create writer"); } }
/** * @tests java.io.PipedReader#close() */ public void test_close() throws Exception { char[] c = null; preader = new PipedReader(); t = new Thread(new PWriter(preader), ""); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; preader.read(c, 0, 11); preader.close(); assertEquals("Read incorrect chars", "Hello World", new String(c)); }
/** * @tests java.io.PipedReader#read() */ public void test_read() throws Exception { char[] c = null; preader = new PipedReader(); t = new Thread(new PWriter(preader), ""); t.start(); Thread.sleep(500); // Allow writer to start c = new char[11]; for (int i = 0; i < c.length; i++) { c[i] = (char) preader.read(); } assertEquals("Read incorrect chars", "Hello World", new String(c)); }
/** * @tests java.io.PipedReader#ready() */ public void test_ready() throws Exception { char[] c = null; preader = new PipedReader(); t = new Thread(new PWriter(preader), ""); t.start(); Thread.sleep(500); // Allow writer to start assertTrue("Reader should be ready", preader.ready()); c = new char[11]; for (int i = 0; i < c.length; i++) c[i] = (char) preader.read(); assertFalse("Reader should not be ready after reading all chars", preader.ready()); }
/** Play jump61. ARGS0 may consist of the single string * '--display' to indicate that the game is played using a GUI. Prints * a usage message if the arguments are wrong. */ public static void main(String[] args0) { CommandArgs args = new CommandArgs("--display{0,1}", args0); if (!args.ok()) { usage(); return; } Game game; if (args.contains("--display")) { try { Writer trash = new FileWriter("/dev/null"); PipedWriter commandWriter = new PipedWriter(); PipedReader commandReader = new PipedReader(commandWriter, COMMAND_BUFFER_SIZE); game = new Game(commandReader, trash, trash, trash); Display display = new Display("Jump61", game, commandWriter); game.play(); } catch (IOException excp) { game = null; System.err.println("Internal error"); System.exit(1); } } else { Writer output = new OutputStreamWriter(System.out); game = new Game(new InputStreamReader(System.in), output, output, new OutputStreamWriter(System.err)); System.exit(game.play()); } }
/** has someone created a reader? **/ protected void enableIO() { if (this.readEnd == null) { this.readEnd = new PipedReader(); this.writeEnd = new PipedWriter(); try { readEnd.connect(writeEnd); } catch (IOException e) { e.printStackTrace(); } }}
/** * @tests java.io.PipedWriter#PipedWriter(java.io.PipedReader) */ public void test_ConstructorLjava_io_PipedReader() throws Exception { // Test for method java.io.PipedWriter(java.io.PipedReader) char[] buf = new char[10]; "HelloWorld".getChars(0, 10, buf, 0); PipedReader rd = new PipedReader(); pw = new PipedWriter(rd); rdrThread = new Thread(reader = new PReader(rd), "Constructor(Reader)"); rdrThread.start(); pw.write(buf); pw.close(); rdrThread.join(500); assertEquals("Failed to construct writer", "HelloWorld", new String( reader.buf)); }
/** * @tests java.io.PipedWriter#write(char[], int, int) Regression for * HARMONY-387 */ public void test_write$CII_2() throws IOException { PipedReader pr = new PipedReader(); PipedWriter obj = null; try { obj = new java.io.PipedWriter(pr); obj.write(new char[0], (int) 0, (int) -1); fail("IndexOutOfBoundsException expected"); } catch (IndexOutOfBoundsException t) { assertEquals( "IndexOutOfBoundsException rather than a subclass expected", IndexOutOfBoundsException.class, t.getClass()); } }