本文整理匯總了Java中java.io.PipedInputStream類的典型用法代碼示例。如果您正苦於以下問題:Java PipedInputStream類的具體用法?Java PipedInputStream怎麽用?Java PipedInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PipedInputStream類屬於java.io包,在下文中一共展示了PipedInputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testTestCommand
import java.io.PipedInputStream; //導入依賴的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: shell
import java.io.PipedInputStream; //導入依賴的package包/類
/**
* Open an SSH shell session and execute the specified script, using the provided stream for output.
*
* <pre><code> shell("ssh://user:[email protected]/work/dir/path", "ls", System.out);</code></pre>
*
* @param connectUri SSH connection URI
* @param script shell command string
* @param out output stream object
*/
public static void shell(String connectUri, String script, OutputStream out) {
try (SessionHolder<ChannelShell> session = new SessionHolder<>(ChannelType.SHELL, URI.create(connectUri));
PipedOutputStream pipe = new PipedOutputStream();
PipedInputStream in = new PipedInputStream(pipe);
PrintWriter pw = new PrintWriter(pipe)) {
if (session.getWorkDir() != null) {
pw.println("cd " + session.getWorkDir());
}
pw.println(script);
pw.println("exit");
pw.flush();
shell(session, in, out);
} catch (IOException e) {
throw new RemoteInputStreamInstantiationException(e);
}
}
示例3: buildACommand
import java.io.PipedInputStream; //導入依賴的package包/類
@Test
public void buildACommand() throws IOException {
PipedInputStream pis = new PipedInputStream();
BufferedInputStream bis = new BufferedInputStream(pis);
PipedOutputStream pos = new PipedOutputStream(pis);
RedisOutputStream ros = new RedisOutputStream(pos);
Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
ros.flush();
pos.close();
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
int b;
StringBuilder sb = new StringBuilder();
while ((b = bis.read()) != -1) {
sb.append((char) b);
}
assertEquals(expectedCommand, sb.toString());
}
示例4: getInputStream
import java.io.PipedInputStream; //導入依賴的package包/類
public InputStream getInputStream() throws IOException {
int max_input_buffer_size = 32*1024;
try {
max_input_buffer_size =
Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
}
catch(Exception e){}
PipedInputStream in =
new MyPipedInputStream(
32*1024, // this value should be customizable.
max_input_buffer_size
);
boolean resizable = 32*1024<max_input_buffer_size;
io.setOutputStream(new PassiveOutputStream(in, resizable), false);
return in;
}
示例5: getExtInputStream
import java.io.PipedInputStream; //導入依賴的package包/類
public InputStream getExtInputStream() throws IOException {
int max_input_buffer_size = 32*1024;
try {
max_input_buffer_size =
Integer.parseInt(getSession().getConfig("max_input_buffer_size"));
}
catch(Exception e){}
PipedInputStream in =
new MyPipedInputStream(
32*1024, // this value should be customizable.
max_input_buffer_size
);
boolean resizable = 32*1024<max_input_buffer_size;
io.setExtOutputStream(new PassiveOutputStream(in, resizable), false);
return in;
}
示例6: testEntityMarshallingWithGZIP
import java.io.PipedInputStream; //導入依賴的package包/類
@Test
public void testEntityMarshallingWithGZIP() throws Exception {
for (int numDataPoints = 1; numDataPoints <= 10; numDataPoints++) {
ArrayList<DataPoint> dataPoints = createDataPoints(numDataPoints);
DatapointsHttpEntity entity = new DatapointsHttpEntity(dataPoints, globalTags, true);
PipedInputStream pis = new PipedInputStream();
entity.writeTo(new PipedOutputStream(pis));
String jsonText = streamToString(pis);
DataPoint[] unmarshalledDPs = Util.jsonToDataPoints(jsonText);
assertEquals(numDataPoints, unmarshalledDPs.length);
for (int i = 0; i < numDataPoints; i++) {
assertEquals(getExpectedDataPoint(dataPoints.get(i), globalTags), unmarshalledDPs[i]);
}
}
}
示例7: getHelloFromServerTest
import java.io.PipedInputStream; //導入依賴的package包/類
@Test
public void getHelloFromServerTest() throws IOException{
//preparing remote connection Socket First parameter for ArticlePuller
//and pipeline fot testing
PipedInputStream inForOut = new PipedInputStream();
PipedOutputStream outForIn = new PipedOutputStream();
BufferedReader rIn = new BufferedReader(new InputStreamReader(inForOut, "UTF-8"));
PrintWriter rOut = new PrintWriter(new OutputStreamWriter(outForIn, "UTF-8"));
when(rSocket.getOutputStream()).thenReturn(new PipedOutputStream(inForOut));
when(rSocket.getInputStream()).thenReturn(new PipedInputStream(outForIn));
rOut.println("200 hello");
rOut.flush();
Socket socket = FeedManager.getHelloFromServer(rSocket, false, "testhost", Charset.forName("UTF-8"));
assertTrue (socket != null);
}
示例8: verifyJobPriority
import java.io.PipedInputStream; //導入依賴的package包/類
protected void verifyJobPriority(String jobId, String priority,
Configuration conf, CLI jc) throws Exception {
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream(pis);
int exitCode = runTool(conf, jc, new String[] { "-list", "all" }, pos);
assertEquals("Exit code", 0, exitCode);
BufferedReader br = new BufferedReader(new InputStreamReader(pis));
String line;
while ((line = br.readLine()) != null) {
LOG.info("line = " + line);
if (!line.contains(jobId)) {
continue;
}
assertTrue(line.contains(priority));
break;
}
pis.close();
}
示例9: 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;
}
示例10: testJarList
import java.io.PipedInputStream; //導入依賴的package包/類
private static void testJarList(String jarFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-tvf");
argList.add(jarFile);
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
String jarArgs[] = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
PipedOutputStream pipedOutput = new PipedOutputStream();
PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
PrintStream out = new PrintStream(pipedOutput);
Main jarTool = new Main(out, System.err, "jar");
if (!jarTool.run(jarArgs)) {
fail("Could not list jar file.");
}
out.flush();
check(pipedInput.available() > 0);
}
示例11: testJarExtract
import java.io.PipedInputStream; //導入依賴的package包/類
private static void testJarExtract(String jarFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-xvf");
argList.add(jarFile);
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
String jarArgs[] = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
PipedOutputStream pipedOutput = new PipedOutputStream();
PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
PrintStream out = new PrintStream(pipedOutput);
Main jarTool = new Main(out, System.err, "jar");
if (!jarTool.run(jarArgs)) {
fail("Could not list jar file.");
}
out.flush();
check(pipedInput.available() > 0);
}
示例12: main
import java.io.PipedInputStream; //導入依賴的package包/類
public static void main(String[] args) {
/**
* 流程
* 1 建立輸入輸出流
* 2 綁定輸入輸出流
* 3 向緩衝區寫數據
* 4 讀取緩衝區數據
*/
PipedOutputStream out = new PipedOutputStream();
PipedInputStream in = new PipedInputStream();
Producer producer = new Producer(out);
Consumer consumer = new Consumer(in);
try {
out.connect(in);
producer.start();
consumer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: testJarList
import java.io.PipedInputStream; //導入依賴的package包/類
private static void testJarList(String jarFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-tvf");
argList.add(jarFile);
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
String jarArgs[] = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
PipedOutputStream pipedOutput = new PipedOutputStream();
PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
PrintStream out = new PrintStream(pipedOutput);
int rc = JAR_TOOL.run(out, System.err, jarArgs);
if (rc != 0) {
fail("Could not list jar file.");
}
out.flush();
check(pipedInput.available() > 0);
}
示例14: testJarExtract
import java.io.PipedInputStream; //導入依賴的package包/類
private static void testJarExtract(String jarFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-xvf");
argList.add(jarFile);
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
String jarArgs[] = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
PipedOutputStream pipedOutput = new PipedOutputStream();
PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
PrintStream out = new PrintStream(pipedOutput);
int rc = JAR_TOOL.run(out, System.err, jarArgs);
if (rc != 0) {
fail("Could not list jar file.");
}
out.flush();
check(pipedInput.available() > 0);
}
示例15: sshCall
import java.io.PipedInputStream; //導入依賴的package包/類
protected void sshCall(String username, String password, SshExecutor executor, String channelType) {
try {
JSch jsch = new JSch();
Session session = jsch.getSession(username, props.getShell().getHost(), props.getShell().getPort());
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel = session.openChannel(channelType);
PipedInputStream pis = new PipedInputStream();
PipedOutputStream pos = new PipedOutputStream();
channel.setInputStream(new PipedInputStream(pos));
channel.setOutputStream(new PipedOutputStream(pis));
channel.connect();
try {
executor.execute(pis, pos);
} finally {
pis.close();
pos.close();
channel.disconnect();
session.disconnect();
}
} catch(JSchException | IOException ex) {
fail(ex.toString());
}
}