java.io.PipedOutputStream Java Examples

The following examples show how to use java.io.PipedOutputStream. 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: SshdShellAutoConfigurationWithPublicKeyAndBannerImageTest.java    From sshd-shell-spring-boot with Apache License 2.0 6 votes vote down vote up
@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");
    try (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();
        verifyResponseContains(pis, "test run bob");
    }
    channel.disconnect();
    session.disconnect();
}
 
Example #2
Source File: PipeTest.java    From ipc-eventbus with Apache License 2.0 6 votes vote down vote up
@Test
public void pipe_test() throws Exception {
  ByteArrayOutputStream collected = new ByteArrayOutputStream();
  PipedInputStream in = new PipedInputStream();
  final PipedOutputStream out = new PipedOutputStream(in);
  new Thread() {
    @Override
    public void run() {
      try {
        for (int i = 1; i <= 5; i++) {
          out.write(("put-" + i + "\n").getBytes());
          ThreadUtil.minimumSleep(500);
        }
        out.close();
      } catch (Exception e) {
        e.printStackTrace();
        fail();
      }
    }
  }.start();
  Pipe pipe = new Pipe("name", in, collected);
  pipe.waitFor();
  assertEquals("put-1\nput-2\nput-3\nput-4\nput-5\n", new String(collected.toByteArray()));
}
 
Example #3
Source File: JarBackSlash.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: MicrophoneInputStream.java    From android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates a new microphone input stream.
 *
 * @param opusEncoded the opus encoded
 */
public MicrophoneInputStream(boolean opusEncoded) {
  captureThread = new MicrophoneCaptureThread(this, opusEncoded);
  if (opusEncoded == true) {
    CONTENT_TYPE = ContentType.OPUS;
  } else {
    CONTENT_TYPE = ContentType.RAW;
  }
  os = new PipedOutputStream();
  is = new PipedInputStream();
  try {
    is.connect(os);
  } catch (IOException e) {
    Log.e(TAG, e.getMessage());
  }
  captureThread.start();
}
 
Example #5
Source File: JarBackSlash.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: ProtocolTest.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * creates a proxy, delegating to a remote endpoint, forwarding to another remote endpoint, that delegates to an actual implementation.
 * @param intf
 * @param impl
 * @return
 * @throws IOException 
 */
public <T> T wrap(Class<T> intf, T impl) {
	PipedInputStream in1 = new PipedInputStream();
	PipedOutputStream out1 = new PipedOutputStream();
	Launcher<T> launcher1 = Launcher.createLauncher(impl, intf, in1, out1);
	
	PipedInputStream in2 = new PipedInputStream();
	PipedOutputStream out2 = new PipedOutputStream();
	Launcher<T> launcher2 = Launcher.createLauncher(new Object(), intf, in2, out2);
	try {
		in1.connect(out2);
		in2.connect(out1);
	} catch (IOException e) {
		throw new IllegalStateException(e);
	}
	launcher1.startListening();
	launcher2.startListening();
	return launcher2.getRemoteProxy();
}
 
Example #7
Source File: LineDisciplineTerminal.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
public LineDisciplineTerminal(String name,
                              String type,
                              OutputStream masterOutput) throws IOException {
    super(name, type);
    PipedInputStream input = new LinePipedInputStream(PIPE_SIZE);
    this.slaveInputPipe = new PipedOutputStream(input);
    // This is a hack to fix a problem in gogo where closure closes
    // streams for commands if they are instances of PipedInputStream.
    // So we need to get around and make sure it's not an instance of
    // that class by using a dumb FilterInputStream class to wrap it.
    this.slaveInput = new FilterInputStream(input) {};
    this.slaveOutput = new FilteringOutputStream();
    this.masterOutput = masterOutput;
    this.attributes = new Attributes();
    this.size = new Size(160, 50);
}
 
Example #8
Source File: GZipCompressInputStream.java    From datasync with MIT License 6 votes vote down vote up
public Worker(InputStream in, int pipeBufferSize) {
    setDaemon(true);
    setName("Compression thread");

    this.in = in;
    this.pipeBufferSize = pipeBufferSize;
    this.source = new PipedInputStream(pipeBufferSize);
    this.sink = new PipedOutputStream();

    try {
        sink.connect(source);
    } catch(IOException e) {
        // this can only happen if the sink is already connected.  Since we just
        // created it, we know it's not.
    }
}
 
Example #9
Source File: JarBackSlash.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: AbstractKeycloakTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected static InputStream httpsAwareConfigurationStream(InputStream input) throws IOException {
    if (!AUTH_SERVER_SSL_REQUIRED) {
        return input;
    }
    PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    try (PrintWriter pw = new PrintWriter(out)) {
        try (Scanner s = new Scanner(input)) {
            while (s.hasNextLine()) {
                String lineWithReplaces = s.nextLine().replace("http://localhost:8180/auth", AUTH_SERVER_SCHEME + "://localhost:" + AUTH_SERVER_PORT + "/auth");
                pw.println(lineWithReplaces);
            }
        }
    }
    return in;
}
 
Example #11
Source File: StreamReaderTest.java    From Ardulink-2 with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleDataNotAlreadyPresentSeparatedByComma()
		throws Exception {
	List<String> expected = Arrays.asList("a", "b", "c");

	PipedOutputStream os = new PipedOutputStream();
	PipedInputStream is = new PipedInputStream(os);

	StreamReader reader = process(is, ",", expected);

	TimeUnit.SECONDS.sleep(2);
	os.write("a,b,c,".getBytes());

	waitUntil(expected.size());
	assertThat(received, is(expected));
	reader.close();
}
 
Example #12
Source File: StreamPumperTest.java    From gocd with Apache License 2.0 6 votes vote down vote up
@Test public void shouldKnowIfPumperExpired() throws Exception {
    PipedOutputStream output = new PipedOutputStream();
    InputStream inputStream = new PipedInputStream(output);
    try {
        TestingClock clock = new TestingClock();
        StreamPumper pumper = new StreamPumper(inputStream, new TestConsumer(), "", "utf-8", clock);
        new Thread(pumper).start();

        output.write("line1\n".getBytes());
        output.flush();

        long timeoutDuration = 2L;
        assertThat(pumper.didTimeout(timeoutDuration, TimeUnit.SECONDS), is(false));
        clock.addSeconds(5);
        assertThat(pumper.didTimeout(timeoutDuration, TimeUnit.SECONDS), is(true));
    } finally {
        output.close();
    }
}
 
Example #13
Source File: JConsole.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * Update out - test failed
     */
    public void updateOut() {
//        outPipe = new PipedOutputStream();
//        try {
//            in = new PipedInputStream((PipedOutputStream) outPipe);
//        } catch (IOException e) {
//            print("Console internal error (1)...", Color.red);
//        }
        PipedOutputStream pout = new PipedOutputStream();
        out = new UnclosableOutputStream(pout);
        try {
            inPipe = new BlockingPipedInputStream(pout);
        } catch (IOException e) {
            print("Console internal error: " + e);
        }
    }
 
Example #14
Source File: JarBackSlash.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: MvsConsoleWrapper.java    From java-samples with Apache License 2.0 6 votes vote down vote up
static void redirectSystemIn() throws Exception {
	// This starts the MvsConsole listener if it's not already started (by the JZOS Batch Launcher)
	if (!MvsConsole.isListening()) {
		MvsConsole.startMvsCommandListener();
	}

	PipedOutputStream pos = new PipedOutputStream();
	final Writer writer = new OutputStreamWriter(pos);   // use default file.encoding
	
	MvsConsole.registerMvsCommandCallback(
			new MvsCommandCallback() {
				public void handleStart(String parms) {};
				public void handleModify(String cmd) {
					try {
						writer.write(cmd + "\n");
						writer.flush();
					} catch (IOException ioe) {
						ioe.printStackTrace();
					}
				}
				public boolean handleStop() { return true; } // System.exit() 
			});
	PipedInputStream pis = new PipedInputStream(pos);
	System.setIn(pis);
}
 
Example #16
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 #17
Source File: TestMRJobClient.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #18
Source File: TestTerminalConnection.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
@Test
public void testRead() throws IOException, InterruptedException {
    PipedOutputStream outputStream = new PipedOutputStream();
    PipedInputStream pipedInputStream = new PipedInputStream(outputStream);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    TerminalConnection connection = new TerminalConnection(Charset.defaultCharset(), pipedInputStream, byteArrayOutputStream);

    final ArrayList<int[]> result = new ArrayList<>();
    connection.setStdinHandler(result::add);

    outputStream.write(("FOO").getBytes());
    outputStream.flush();
    outputStream.close();
    Thread.sleep(150);
    connection.openBlocking();

    assertArrayEquals(result.get(0), new int[] {70,79,79});
}
 
Example #19
Source File: JarBackSlash.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #20
Source File: JarBackSlash.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #21
Source File: RdfEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
@Override
public XmlObject encode(RDF rdf, EncodingContext additionalValues) throws EncodingException {
    try (PipedInputStream pis = new PipedInputStream(); PipedOutputStream pos = new PipedOutputStream()) {
        pis.connect(pos);
        encode(rdf, pos);
        return XmlObject.Factory.parse(pis);
    } catch (Exception e) {
        throw new EncodingException("Error while encoding element!", e);
    }
}
 
Example #22
Source File: RecordITCase.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
	PipedInputStream pipedInput = new PipedInputStream(32*1024*1024);
	this.in = new DataInputStream(pipedInput);
	this.out = new DataOutputStream(new PipedOutputStream(pipedInput));
}
 
Example #23
Source File: TestTools.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private void checkOutput(String[] args, String pattern, PrintStream out,
    Class<?> clazz) {       
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  try {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut, PIPE_BUFFER_SIZE);
    if (out == System.out) {
      System.setOut(new PrintStream(pipeOut));
    } else if (out == System.err) {
      System.setErr(new PrintStream(pipeOut));
    }

    if (clazz == DelegationTokenFetcher.class) {
      expectDelegationTokenFetcherExit(args);
    } else if (clazz == JMXGet.class) {
      expectJMXGetExit(args);
    } else if (clazz == DFSAdmin.class) {
      expectDfsAdminPrint(args);
    }
    pipeOut.close();
    ByteStreams.copy(pipeIn, outBytes);      
    pipeIn.close();
    assertTrue(new String(outBytes.toByteArray()).contains(pattern));            
  } catch (Exception ex) {
    fail("checkOutput error " + ex);
  }
}
 
Example #24
Source File: RtcpDeinterleaver.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
public RtcpDeinterleaver(InputStream inputStream) {
	mInputStream = inputStream;
	mPipedInputStream = new PipedInputStream(4096);
	try {
		mPipedOutputStream = new PipedOutputStream(mPipedInputStream);
	} catch (IOException e) {}
	mBuffer = new byte[1024];
	new Thread(this).start();
}
 
Example #25
Source File: ProcessIOTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Create an instance of process IO data generator.
 * <p/>
 * @param in      Process standard input (second side of pipe
 *                to connect).
 * @param out     Process standard output (second side of pipe
 *                to connect).
 * @param dataOut Content of process standard output to be sent trough
 *                the pipe.
 * @throws IOException When there is an issue with connecting pipes
 *         or opening local {@link Reader}s and {@link Writer}s.
 */
private DataSrc(final PipedOutputStream in, final PipedInputStream out,
        final String[] dataOut) throws IOException {
    try {
        srcIn = new InputStreamReader(new PipedInputStream(in));
        srcOut = new OutputStreamWriter(new PipedOutputStream(out));
        this.dataOut = dataOut != null ? dataOut : new String[0];
    } catch (IOException ex) {
        close();
        throw ex;
    }
    
}
 
Example #26
Source File: DownloadSchema.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@ApiResponses({@ApiResponse(code = 200, response = File.class, message = "")})
@GetMapping(path = "/slowInputStream")
public ResponseEntity<InputStream> slowInputStream() throws IOException {
  PipedInputStream in = new PipedInputStream();
  PipedOutputStream out = new PipedOutputStream();
  in.connect(out);

  slowInputStreamThread = new Thread(() -> {
    Thread.currentThread().setName("download thread");
    byte[] bytes = "1".getBytes();
    for (; ; ) {
      try {
        out.write(bytes);
        out.flush();
        Thread.sleep(1000);
      } catch (Throwable e) {
        break;
      }
    }
    try {
      out.close();
    } catch (final IOException ioe) {
      // ignore
    }
  });
  slowInputStreamThread.start();

  ResponseEntity<InputStream> responseEntity = ResponseEntity
      .ok()
      .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE)
      .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=slowInputStream.txt")
      .body(in);
  return responseEntity;
}
 
Example #27
Source File: ClientConnectionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private PipedOutputStream createPipedConnection(final boolean[] success,
                                                final ClientConnection.Listener listener)
                                                throws IOException {
    final boolean[] closed = new boolean[] { false };
    PipedOutputStream pos = new PipedOutputStream() {
        @Override public void close() throws IOException {
            closed[0] = true;
            super.close();
        }
    };
    PipedInputStream pis = new PipedInputStream(pos);
    OutputStream dummyOS = new OutputStream() {
        @Override
        public void write(int b) throws IOException {}
    };
    final ClientConnection cc = new ClientConnection(pis, dummyOS);
    Thread t = new Thread() {
        @Override public void run() {
            try {
                cc.runEventLoop(listener);
            } catch (IOException ex) {
                if (!closed[0]) {
                    ex.printStackTrace();
                    success[0] = false;
                }
            }
        }
    };
    t.start();
    pos.write("Protocol-Version: 1\r\n".getBytes());
    return pos;
}
 
Example #28
Source File: ControllerImageSession.java    From CXTouch with GNU General Public License v3.0 5 votes vote down vote up
public ControllerImageSession(String deviceId) {
    super(new ImageSessionID(ImageSessionID.TYPE_CONTROLLER, deviceId));
    deviceConnection = Application.getInstance().getDeviceConnection(deviceId);
    if (deviceConnection == null) {
        throw new RuntimeException("The device connection doesn't exist: " + deviceId);
    }

    outputStream = new PipedOutputStream();
    parserThread = new ImageParserThread();
    parserThread.start();
}
 
Example #29
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 #30
Source File: AbstractWindowsTerminal.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
public AbstractWindowsTerminal(boolean consumeCP, OutputStream output, String name, boolean nativeSignals, SignalHandler signalHandler) throws IOException {
    super(name, "windows", signalHandler);
    PipedInputStream input = new PipedInputStream(PIPE_SIZE);
    this.slaveInputPipe = new PipedOutputStream(input);
    this.input = new FilterInputStream(input) {};
    this.cpConsumer = consumeCP ? new ConsoleOutput() : null;
    this.output = output;
    String encoding = getConsoleEncoding();
    if (encoding == null) {
        encoding = Charset.defaultCharset().name();
    }
    this.writer = new PrintWriter(new OutputStreamWriter(this.output, encoding));
    // Attributes
    attributes.setLocalFlag(Attributes.LocalFlag.ISIG, true);
    attributes.setControlChar(Attributes.ControlChar.VINTR, ctrl('C'));
    attributes.setControlChar(Attributes.ControlChar.VEOF,  ctrl('D'));
    attributes.setControlChar(Attributes.ControlChar.VSUSP, ctrl('Z'));
    // Handle signals
    if (nativeSignals) {
        for (final Signal signal : Signal.values()) {
            nativeHandlers.put(signal,
                    Signals.register(signal.name(), () -> raise(signal)));
        }
    }
    pump = new Thread(this::pump, "WindowsStreamPump");
    pump.setDaemon(true);
    pump.start();
    closer = this::close;
    ShutdownHooks.add(closer);
}