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


Java PipedInputStream.available方法代码示例

本文整理汇总了Java中java.io.PipedInputStream.available方法的典型用法代码示例。如果您正苦于以下问题:Java PipedInputStream.available方法的具体用法?Java PipedInputStream.available怎么用?Java PipedInputStream.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.PipedInputStream的用法示例。


在下文中一共展示了PipedInputStream.available方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例4: TarEntrySupplicant

import java.io.PipedInputStream; //导入方法依赖的package包/类
/**
 * After instantiating a TarEntrySupplicant, the user must either invoke
 * write() or close(), to release system resources on the input
 * File/Stream.
 * <P/>
 * <B>WARNING:</B>
 * Do not use this method unless the quantity of available RAM is
 * sufficient to accommodate the specified maxBytes all at one time.
 * This constructor loads all input from the specified InputStream into
 * RAM before anything is written to disk.
 *
 * @param maxBytes This method will fail if more than maxBytes bytes
 *                 are supplied on the specified InputStream.
 *                 As the type of this parameter enforces, the max
 *                 size you can request is 2GB.
 */
public TarEntrySupplicant(String path, InputStream origStream,
                          int maxBytes, char typeFlag,
                          TarFileOutputStream tarStream)
                          throws IOException, TarMalformatException {

    /*
     * If you modify this, make sure to not intermix reading/writing of
     * the PipedInputStream and the PipedOutputStream, or you could
     * cause dead-lock.  Everything is safe if you close the
     * PipedOutputStream before reading the PipedInputStream.
     */
    this(path, typeFlag, tarStream);

    if (maxBytes < 1) {
        throw new IllegalArgumentException(
            RB.singleton.getString(RB.READ_LT_1));
    }

    int               i;
    PipedOutputStream outPipe = new PipedOutputStream();

    inputStream = new PipedInputStream(outPipe);

    /* This constructor not available until Java 1.6:
    inputStream = new PipedInputStream(outPipe, maxBytes);
    */
    try {
        while ((i =
                origStream
                    .read(tarStream.writeBuffer, 0, tarStream
                        .writeBuffer.length)) > 0) {
            outPipe.write(tarStream.writeBuffer, 0, i);
        }

        outPipe.flush();    // Do any good on a pipe?

        dataSize = inputStream.available();

        if (TarFileOutputStream.debug) {
            System.out.println(
                RB.singleton.getString(
                    RB.STREAM_BUFFER_REPORT, Long.toString(dataSize)));
        }
    } catch (IOException ioe) {
        inputStream.close();

        throw ioe;
    } finally {
        outPipe.close();
    }

    modTime = new java.util.Date().getTime() / 1000L;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:70,代码来源:TarGenerator.java


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