本文整理汇总了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;
}
示例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: 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;
}
示例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;
}