Java Code Examples for java.io.PipedOutputStream#connect()

The following examples show how to use java.io.PipedOutputStream#connect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendNotificationTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
	this.client = mock(ExecuteCommandProposedClient.class);

	PipedOutputStream clientWritesTo = new PipedOutputStream();
	PipedInputStream clientReadsFrom = new PipedInputStream();
	PipedInputStream serverReadsFrom = new PipedInputStream();
	PipedOutputStream serverWritesTo = new PipedOutputStream();

	serverWritesTo.connect(clientReadsFrom);
	clientWritesTo.connect(serverReadsFrom);

	this.closeables = new Closeable[] { clientWritesTo, clientReadsFrom, serverReadsFrom, serverWritesTo };

	Launcher<JavaLanguageClient> serverLauncher = Launcher.createLauncher(new Object(), JavaLanguageClient.class, serverReadsFrom, serverWritesTo);
	serverLauncher.startListening();
	Launcher<LanguageServer> clientLauncher = Launcher.createLauncher(client, LanguageServer.class, clientReadsFrom, clientWritesTo);
	clientLauncher.startListening();

	this.clientConnection = serverLauncher.getRemoteProxy();
}
 
Example 2
Source File: LauncherTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
@Before public void setup() throws IOException {
	PipedInputStream inClient = new PipedInputStream();
	PipedOutputStream outClient = new PipedOutputStream();
	PipedInputStream inServer = new PipedInputStream();
	PipedOutputStream outServer = new PipedOutputStream();
	
	inClient.connect(outServer);
	outClient.connect(inServer);
	server = new AssertingEndpoint();
	serverLauncher = LSPLauncher.createServerLauncher(ServiceEndpoints.toServiceObject(server, LanguageServer.class), inServer, outServer);
	serverListening = serverLauncher.startListening();
	
	client = new AssertingEndpoint();
	clientLauncher = LSPLauncher.createClientLauncher(ServiceEndpoints.toServiceObject(client, LanguageClient.class), inClient, outClient);
	clientListening = clientLauncher.startListening();
	
	Logger logger = Logger.getLogger(StreamMessageProducer.class.getName());
	logLevel = logger.getLevel();
	logger.setLevel(Level.SEVERE);
}
 
Example 3
Source File: DSPLauncherTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
	PipedInputStream inClient = new PipedInputStream();
	PipedOutputStream outClient = new PipedOutputStream();
	PipedInputStream inServer = new PipedInputStream();
	PipedOutputStream outServer = new PipedOutputStream();

	inClient.connect(outServer);
	outClient.connect(inServer);
	server = new AssertingEndpoint();
	serverLauncher = DSPLauncher.createServerLauncher(
			ServiceEndpoints.toServiceObject(server, IDebugProtocolServer.class), inServer, outServer);
	serverListening = serverLauncher.startListening();

	client = new AssertingEndpoint();
	clientLauncher = DSPLauncher.createClientLauncher(
			ServiceEndpoints.toServiceObject(client, IDebugProtocolClient.class), inClient, outClient);
	clientListening = clientLauncher.startListening();

	Logger logger = Logger.getLogger(StreamMessageProducer.class.getName());
	logLevel = logger.getLevel();
	logger.setLevel(Level.SEVERE);
}
 
Example 4
Source File: SchemaParser.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes a parser and its plumbing.
 *
 * @throws java.io.IOException if a pipe cannot be formed.
 */
public synchronized void init() throws IOException
{
    parserIn = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream();
    parserIn.connect( in );
    antlrSchemaConverterLexer lexer = new antlrSchemaConverterLexer( in );
    parser = new antlrSchemaConverterParser( lexer );
}
 
Example 5
Source File: IntegrationTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBothDirectionRequests() throws Exception {
	// create client side
	PipedInputStream in = new PipedInputStream();
	PipedOutputStream out = new PipedOutputStream();
	PipedInputStream in2 = new PipedInputStream();
	PipedOutputStream out2 = new PipedOutputStream();
	
	in.connect(out2);
	out.connect(in2);
	
	MyClient client = new MyClientImpl();
	Launcher<MyServer> clientSideLauncher = Launcher.createLauncher(client, MyServer.class, in, out);
	
	// create server side
	MyServer server = new MyServerImpl();
	Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in2, out2);
	
	clientSideLauncher.startListening();
	serverSideLauncher.startListening();
	
	CompletableFuture<MyParam> fooFuture = clientSideLauncher.getRemoteProxy().askServer(new MyParam("FOO"));
	CompletableFuture<MyParam> barFuture = serverSideLauncher.getRemoteProxy().askClient(new MyParam("BAR"));
	
	Assert.assertEquals("FOO", fooFuture.get(TIMEOUT, TimeUnit.MILLISECONDS).value);
	Assert.assertEquals("BAR", barFuture.get(TIMEOUT, TimeUnit.MILLISECONDS).value);
}
 
Example 6
Source File: ExtendableConcurrentMessageProcessorTest.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test that an adopter making use of these APIs is able to 
 * identify which client is making any given request. 
 */
@Test
public void testIdentifyClientRequest() throws Exception {
	// create client side
	PipedInputStream in = new PipedInputStream();
	PipedOutputStream out = new PipedOutputStream();
	PipedInputStream in2 = new PipedInputStream();
	PipedOutputStream out2 = new PipedOutputStream();
	
	in.connect(out2);
	out.connect(in2);
	
	MyClient client = new MyClientImpl();
	Launcher<MyServer> clientSideLauncher = Launcher.createLauncher(client, MyServer.class, in, out);
	
	// create server side
	MyServer server = new MyServerImpl();
	MessageContextStore<MyClient> contextStore = new MessageContextStore<>();
	Launcher<MyClient> serverSideLauncher = createLauncher(createBuilder(contextStore), server, MyClient.class, in2, out2);
	
	TestContextWrapper.setMap(contextStore);
	
	clientSideLauncher.startListening();
	serverSideLauncher.startListening();
	
	CompletableFuture<MyParam> fooFuture = clientSideLauncher.getRemoteProxy().askServer(new MyParam("FOO"));
	CompletableFuture<MyParam> barFuture = serverSideLauncher.getRemoteProxy().askClient(new MyParam("BAR"));
	
	Assert.assertEquals("FOO", fooFuture.get(TIMEOUT, TimeUnit.MILLISECONDS).value);
	Assert.assertEquals("BAR", barFuture.get(TIMEOUT, TimeUnit.MILLISECONDS).value);
	Assert.assertFalse(TestContextWrapper.error);
}
 
Example 7
Source File: PipedStream.java    From banyan with MIT License 5 votes vote down vote up
public static void main(String... args) throws IOException {
    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream();

    out.connect(in);
    Thread thread = new Thread(new Print(in), "PrintThread");
    thread.start();

    int receive = 0;
    while ((receive = System.in.read()) != -1) {
        out.write(receive);
    }
}
 
Example 8
Source File: MiLiProfile.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public boolean init()
{
    Debug.TRACE();
    m_DataSourceInputStream = new PipedInputStream();
    m_DataSourceOutputStream = new PipedOutputStream();
    boolean flag;
    try
    {
        m_DataSourceOutputStream.connect(m_DataSourceInputStream);
    }
    catch (IOException ioexception)
    {
        ioexception.printStackTrace();
    }
    flag = initCharacteristics();
    Debug.ASSERT_TRUE(flag);
    if (flag);
    if (flag)
    {
        Debug.INFO("=================================================");
        Debug.INFO("============= INITIALIZATION SUCCESS ============");
        Debug.INFO("=================================================");
        m_ProfileState = 1;
        Intent intent1 = new Intent(INTENT_ACTION_INITIALIZATION_SUCCESS);
        intent1.putExtra(BLEService.INTENT_EXTRA_DEVICE, getDevice());
        BLEService.getBroadcastManager().sendBroadcast(intent1);
        return true;
    } else
    {
        Debug.ERROR("=================================================");
        Debug.ERROR("============= INITIALIZATION FAILED =============");
        Debug.ERROR("=================================================");
        m_ProfileState = 2;
        Intent intent = new Intent(INTENT_ACTION_INITIALIZATION_FAILED);
        intent.putExtra(BLEService.INTENT_EXTRA_DEVICE, getDevice());
        BLEService.getBroadcastManager().sendBroadcast(intent);
        return false;
    }
}
 
Example 9
Source File: BinaryChannelConnectionTest.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException {
  PipedOutputStream aliceOut = new PipedOutputStream();
  PipedInputStream aliceIn = new PipedInputStream(PIPE_BUFFER_SIZE);

  PipedOutputStream bobOut = new PipedOutputStream();
  PipedInputStream bobIn = new PipedInputStream(PIPE_BUFFER_SIZE);

  aliceOut.connect(bobIn);
  aliceIn.connect(bobOut);

  aliceStream = new PipedBytestreamSession(aliceIn, aliceOut);
  bobStream = new PipedBytestreamSession(bobIn, bobOut);
}
 
Example 10
Source File: SSHShellUtil.java    From mcg-helper with Apache License 2.0 4 votes vote down vote up
public static String execute(String ip, int port, String userName, String password, String secretKey, String shell) throws JSchException, IOException {
		String response = null;
		JSch.setLogger(new ShellLogger());
		JSch jsch = new JSch();
		Session session = jsch.getSession(userName, ip, port);
		UserInfo ui = null;
		if(StringUtils.isEmpty(secretKey)) {
			ui = new SSHUserInfo(password);
		} else {
			ui = new SSHGoogleAuthUserInfo(secretKey, password);
		}
		session.setUserInfo(ui);
		session.connect(6000);

		Channel channel = session.openChannel("shell");
		PipedInputStream pipedInputStream = new PipedInputStream();
		PipedOutputStream pipedOutputStream = new PipedOutputStream();
		pipedOutputStream.connect(pipedInputStream);
		
		Thread thread = new Thread(new MonitorShellUser(channel, shell, pipedOutputStream));
		thread.start();
		
		channel.setInputStream(pipedInputStream);
		
		PipedOutputStream shellPipedOutputStream = new PipedOutputStream();
		PipedInputStream receiveStream = new PipedInputStream(); 
		shellPipedOutputStream.connect(receiveStream);
		
		channel.setOutputStream(shellPipedOutputStream);
		((ChannelShell)channel).setPtyType("vt100", 160, 24, 1000, 480);   // dumb
		//((ChannelShell)channel).setTerminalMode("binary".getBytes(Constants.CHARSET));
	//	((ChannelShell)channel).setEnv("LANG", "zh_CN.UTF-8");
		try {
			channel.connect();
			response = IOUtils.toString(receiveStream, "UTF-8");
		}finally {
//			if(channel.isClosed()) {
				pipedOutputStream.close();
				pipedInputStream.close();
				shellPipedOutputStream.close();
				receiveStream.close();
				channel.disconnect();
				session.disconnect();
			}
//		}
			
		return response;
	}