当前位置: 首页>>代码示例>>Java>>正文


Java PipedInputStream.read方法代码示例

本文整理汇总了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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TestJMXGet.java

示例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;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:22,代码来源:TestJMXGet.java

示例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());
  }
 
开发者ID:CkimiHoK,项目名称:JavaWork,代码行数:26,代码来源:InputTest.java

示例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;
	}
}
 
开发者ID:rizsi,项目名称:rcom,代码行数:13,代码来源:LogFilterOutpurStream.java

示例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;
}
 
开发者ID:lorddusk,项目名称:DuskBot,代码行数:12,代码来源:ConsoleOutput.java


注:本文中的java.io.PipedInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。