本文整理汇总了Java中java.io.PipedInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java PipedInputStream.read方法的具体用法?Java PipedInputStream.read怎么用?Java PipedInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.PipedInputStream
的用法示例。
在下文中一共展示了PipedInputStream.read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkPrintAllValues
import java.io.PipedInputStream; //导入方法依赖的package包/类
private static boolean checkPrintAllValues(JMXGet jmx) throws Exception {
int size = 0;
byte[] bytes = null;
String pattern = "List of all the available keys:";
PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut);
System.setErr(new PrintStream(pipeOut));
jmx.printAllValues();
if ((size = pipeIn.available()) != 0) {
bytes = new byte[size];
pipeIn.read(bytes, 0, bytes.length);
}
pipeOut.close();
pipeIn.close();
return bytes != null ? new String(bytes).contains(pattern) : false;
}
示例2: checkPrintAllValues
import java.io.PipedInputStream; //导入方法依赖的package包/类
private static boolean checkPrintAllValues(JMXGet jmx) throws Exception {
int size = 0;
byte[] bytes = null;
String pattern = "List of all the available keys:";
PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut);
PrintStream oldErr = System.err;
System.setErr(new PrintStream(pipeOut));
try {
jmx.printAllValues();
if ((size = pipeIn.available()) != 0) {
bytes = new byte[size];
pipeIn.read(bytes, 0, bytes.length);
}
pipeOut.close();
pipeIn.close();
} finally {
System.setErr(oldErr);
}
return bytes != null ? new String(bytes).contains(pattern) : false;
}
示例3: testReadParamOutput
import java.io.PipedInputStream; //导入方法依赖的package包/类
/**
* Проверим выходные данные метода readParam(String message)
*/
@Test
public void testReadParamOutput() throws IOException {
//assign
InputStream is = System.in;
PrintStream ps = System.out;
PipedInputStream pin = new PipedInputStream();
PipedOutputStream pout = new PipedOutputStream(pin);
InputStream bis = new ByteArrayInputStream("\n".getBytes());
System.setIn(bis);
System.setOut(new PrintStream(pout));
Input input = new Input();
byte[] b = new byte[1000];
String result;
//action
input.readParam("print message");
pin.read(b);
result = new String(b).trim();
System.setIn(is);
System.setOut(ps);
//assert
assertArrayEquals("print message".getBytes(),result.getBytes());
}
示例4: readFully
import java.io.PipedInputStream; //导入方法依赖的package包/类
private void readFully(byte[] bs, PipedInputStream i) throws IOException {
int at=0;
while(at<bs.length)
{
int n=i.read(bs, at, bs.length-at);
if(n<0)
{
throw new EOFException();
}
at+=n;
}
}
示例5: readLine
import java.io.PipedInputStream; //导入方法依赖的package包/类
private synchronized String readLine(PipedInputStream in) throws IOException {
String input = "";
do {
int available = in.available();
if (available == 0) break;
byte b[] = new byte[available];
in.read(b);
input = input + new String(b, 0, b.length);
} while (!input.endsWith("\n") && !input.endsWith("\r\n") && !quit);
return input;
}