本文整理匯總了Java中java.io.PipedOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java PipedOutputStream.flush方法的具體用法?Java PipedOutputStream.flush怎麽用?Java PipedOutputStream.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io.PipedOutputStream
的用法示例。
在下文中一共展示了PipedOutputStream.flush方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testTestCommand
import java.io.PipedOutputStream; //導入方法依賴的package包/類
@Test
public void testTestCommand() throws JSchException, IOException {
JSch jsch = new JSch();
Session session = jsch.getSession("admin", "localhost", properties.getShell().getPort());
jsch.addIdentity("src/test/resources/id_rsa");
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
ChannelShell channel = (ChannelShell) session.openChannel("shell");
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream();
channel.setInputStream(new PipedInputStream(pos));
channel.setOutputStream(new PipedOutputStream(pis));
channel.connect();
pos.write("test run bob\r".getBytes(StandardCharsets.UTF_8));
pos.flush();
verifyResponse(pis, "test run bob");
pis.close();
pos.close();
channel.disconnect();
session.disconnect();
}
開發者ID:anand1st,項目名稱:sshd-shell-spring-boot,代碼行數:24,代碼來源:SshdShellAutoConfigurationWithPublicKeyAndBannerImageTest.java
示例2: tupleWriter
import java.io.PipedOutputStream; //導入方法依賴的package包/類
private void tupleWriter(PipedOutputStream pipeOut, Set<String> tuples) throws BiremeException {
byte[] data = null;
try {
Iterator<String> iterator = tuples.iterator();
while (iterator.hasNext() && !cxt.stop) {
data = iterator.next().getBytes("UTF-8");
pipeOut.write(data);
}
pipeOut.flush();
} catch (IOException e) {
throw new BiremeException("I/O error occurs while write to pipe.", e);
} finally {
try {
pipeOut.close();
} catch (IOException ignore) {
}
}
}
示例3: ArduinoDouble
import java.io.PipedOutputStream; //導入方法依賴的package包/類
public ArduinoDouble(final Protocol protocol) throws IOException {
this.protocol = protocol;
PipedInputStream is1 = new PipedInputStream();
os1 = new PipedOutputStream(is1);
is2 = new PipedInputStream();
os2 = new PipedOutputStream(is2);
streamReader = new StreamReader(is1) {
@Override
protected void received(byte[] bytes) throws Exception {
String received = new String(bytes);
logger.info("Received {}", received);
for (ReponseGenerator generator : data) {
if (generator.matches(received)) {
String response = generator.getResponse();
logger.info("Responding {}", response);
send(response);
os2.flush();
} else {
logger.warn("No responder for {}", received);
}
}
}
};
streamReader.runReaderThread(protocol.getSeparator());
}
示例4: getInputStream
import java.io.PipedOutputStream; //導入方法依賴的package包/類
/**
* @param length
* The length of the stream content.
* @return An InputStream.
* @throws IOException
* Exception.
*/
private PipedInputStream getInputStream(long length) throws IOException {
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream(outputStream);
for (int i = 0; i < length; i++) {
outputStream.write(Byte.MIN_VALUE);
}
outputStream.flush();
outputStream.close();
return inputStream;
}
示例5: TarEntrySupplicant
import java.io.PipedOutputStream; //導入方法依賴的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.
* </P>
*
* @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, 0100000000000L);
if (maxBytes < 1) {
throw new IllegalArgumentException(RB.read_lt_1.getString());
}
int i;
PipedOutputStream outPipe = new PipedOutputStream();
/*
* This constructor not available until Java 1.6:
* inputStream = new PipedInputStream(outPipe, maxBytes);
*/
try {
inputStream =
new InputStreamWrapper(new PipedInputStream(outPipe));
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.stream_buffer_report.getString(
Long.toString(dataSize)));
}
} catch (IOException ioe) {
close();
throw ioe;
} finally {
try {
outPipe.close();
} finally {
outPipe = null; // Encourage buffer GC
}
}
modTime = new java.util.Date().getTime() / 1000L;
}
示例6: getPifData
import java.io.PipedOutputStream; //導入方法依賴的package包/類
protected PIFData getPifData(TarEntryHeader header)
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.
*/
long dataSize = header.getDataSize();
if (dataSize < 1) {
throw new TarMalformatException(
RB.singleton.getString(RB.PIF_UNKNOWN_DATASIZE));
}
if (dataSize > Integer.MAX_VALUE) {
throw new TarMalformatException(
RB.singleton.getString(
RB.PIF_DATA_TOOBIG, Long.toString(dataSize),
Integer.MAX_VALUE));
}
int readNow;
int readBlocks = (int) (dataSize / 512L);
int modulus = (int) (dataSize % 512L);
// Couldn't care less about the entry "name" field.
PipedOutputStream outPipe = new PipedOutputStream();
PipedInputStream inPipe = new PipedInputStream(outPipe);
/* This constructor not available until Java 1.6:
new PipedInputStream(outPipe, (int) dataSize);
*/
try {
while (readBlocks > 0) {
readNow = (readBlocks > archive.getReadBufferBlocks())
? archive.getReadBufferBlocks()
: readBlocks;
archive.readBlocks(readNow);
readBlocks -= readNow;
outPipe.write(archive.readBuffer, 0, readNow * 512);
}
if (modulus != 0) {
archive.readBlock();
outPipe.write(archive.readBuffer, 0, modulus);
}
outPipe.flush(); // Do any good on a pipe?
} catch (IOException ioe) {
inPipe.close();
throw ioe;
} finally {
outPipe.close();
}
return new PIFData(inPipe);
}
示例7: TarEntrySupplicant
import java.io.PipedOutputStream; //導入方法依賴的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;
}