本文整理汇总了Java中java.io.PipedOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java PipedOutputStream类的具体用法?Java PipedOutputStream怎么用?Java PipedOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PipedOutputStream类属于java.io包,在下文中一共展示了PipedOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: shell
import java.io.PipedOutputStream; //导入依赖的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.PipedOutputStream; //导入依赖的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: 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) {
}
}
}
示例5: testEntityMarshallingWithGZIP
import java.io.PipedOutputStream; //导入依赖的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]);
}
}
}
示例6: getHelloFromServerTest
import java.io.PipedOutputStream; //导入依赖的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);
}
示例7: verifyJobPriority
import java.io.PipedOutputStream; //导入依赖的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();
}
示例8: checkPrintAllValues
import java.io.PipedOutputStream; //导入依赖的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;
}
示例9: testJarList
import java.io.PipedOutputStream; //导入依赖的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);
}
示例10: testJarExtract
import java.io.PipedOutputStream; //导入依赖的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);
}
示例11: main
import java.io.PipedOutputStream; //导入依赖的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();
}
}
示例12: testJarList
import java.io.PipedOutputStream; //导入依赖的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);
}
示例13: testJarExtract
import java.io.PipedOutputStream; //导入依赖的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);
}
示例14: sshCall
import java.io.PipedOutputStream; //导入依赖的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());
}
}
示例15: createDataNetSocketPair
import java.io.PipedOutputStream; //导入依赖的package包/类
public static DataNetSocketPair createDataNetSocketPair()
throws IOException
{
final DataNetSocketPair result = new DataNetSocketPair();
// create stream from higher layer
final PipedInputStream fromHigherLayerIS = new PipedInputStream();
final PipedOutputStream fromHigherLayerOS = new PipedOutputStream(
fromHigherLayerIS);
// stream to higher layer
final PipedInputStream toHigherLayerIS = new PipedInputStream();
final PipedOutputStream toHigherLayerOS = new PipedOutputStream(
toHigherLayerIS);
// create socket provided to higher layer
result.setSocket(new DataNetSocketImpl(toHigherLayerIS,
fromHigherLayerOS));
result.setInvertedSocked(new DataNetSocketImpl(fromHigherLayerIS,
toHigherLayerOS));
return result;
}