本文整理匯總了Java中java.io.PipedWriter類的典型用法代碼示例。如果您正苦於以下問題:Java PipedWriter類的具體用法?Java PipedWriter怎麽用?Java PipedWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PipedWriter類屬於java.io包,在下文中一共展示了PipedWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getScriptTrace
import java.io.PipedWriter; //導入依賴的package包/類
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();
}
}
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:20,代碼來源:ScriptEngineService.java
示例2: getScriptTrace
import java.io.PipedWriter; //導入依賴的package包/類
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();
}
}
示例3: ProlMemoryPipe
import java.io.PipedWriter; //導入依賴的package包/類
/**
* 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);
}
示例4: test_writeI
import java.io.PipedWriter; //導入依賴的package包/類
public void test_writeI() throws Exception {
// Test for method void java.io.PipedWriter.write(int)
pw = new PipedWriter();
try {
pw.write(42);
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
readerThread = new Thread(reader = new PReader(pw), "writeI");
readerThread.start();
pw.write(1);
pw.write(2);
pw.write(3);
pw.close();
reader.read(3);
assertTrue("Test 2: The charaacters read do not match the characters written: " +
(int) reader.buf[0] + " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
}
示例5: test_Constructor
import java.io.PipedWriter; //導入依賴的package包/類
/**
* @tests java.io.PipedWriter#PipedWriter()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "PipedWriter",
args = {}
)
public void test_Constructor() {
pw = new PipedWriter();
assertNotNull(pw);
try {
pw.close();
} catch (IOException e) {
fail("Unexpeceted IOException.");
}
}
示例6: test_close
import java.io.PipedWriter; //導入依賴的package包/類
/**
* @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());
}
}
示例7: test_flush
import java.io.PipedWriter; //導入依賴的package包/類
/**
* @tests java.io.PipedWriter#flush()
*/
@TestTargetNew(
level = TestLevel.SUFFICIENT,
notes = "No IOException checking because it is never thrown in the source code.",
method = "flush",
args = {}
)
public void test_flush() throws Exception {
// Test for method void java.io.PipedWriter.flush()
pw = new PipedWriter();
readerThread = new Thread(reader = new PReader(pw), "flush");
readerThread.start();
pw.write(testBuf);
pw.flush();
assertEquals("Test 1: Flush failed. ", testString,
reader.read(testLength));
}
示例8: test_close
import java.io.PipedWriter; //導入依賴的package包/類
/**
* @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
}
}
示例9: test_connectLjava_io_PipedReader
import java.io.PipedWriter; //導入依賴的package包/類
/**
* @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));
}
示例10: test_writeI
import java.io.PipedWriter; //導入依賴的package包/類
/**
* @tests java.io.PipedWriter#write(int)
*/
public void test_writeI() throws Exception {
// Test for method void java.io.PipedWriter.write(int)
pw = new PipedWriter();
rdrThread = new Thread(reader = new PReader(pw), "writeI");
rdrThread.start();
pw.write(1);
pw.write(2);
pw.write(3);
pw.close();
rdrThread.join(1000);
assertTrue("Failed to write correct chars: " + (int) reader.buf[0]
+ " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
}
示例11: create
import java.io.PipedWriter; //導入依賴的package包/類
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;
}
示例12: testGetOneLineOneParser
import java.io.PipedWriter; //導入依賴的package包/類
/**
* 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());
}
}
示例13: newPipedReader
import java.io.PipedWriter; //導入依賴的package包/類
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);
}
}
示例14: testInterruptWriter
import java.io.PipedWriter; //導入依賴的package包/類
private void testInterruptWriter(final PipedWriter writer) throws Exception {
Thread thread = interruptMeLater();
try {
// this will block when the receiving buffer fills up
while (true) {
writer.write(new char[BUFFER_SIZE]);
}
} catch (InterruptedIOException expected) {
} finally {
confirmInterrupted(thread);
}
}
示例15: PReader
import java.io.PipedWriter; //導入依賴的package包/類
public PReader(PipedWriter pw) {
try {
pr = new PipedReader(pw);
} catch (IOException e) {
System.out.println("Exception setting up reader: "
+ e.toString());
}
}