java.io.PipedInputStream Java Examples

The following examples show how to use java.io.PipedInputStream. 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: RLPStreamTest.java    From headlong with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnrecoverable() throws Throwable {
    try (PipedOutputStream pos = new PipedOutputStream();
         PipedInputStream pis = new PipedInputStream(pos, 512);
         RLPStream stream = new RLPStream(pis)) {
        pos.write(0x81);
        pos.write(0x00);
        Iterator<RLPItem> iter = stream.iterator();
        TestUtils.assertThrown(IllegalArgumentException.class, "invalid rlp for single byte @ 0", iter::hasNext);
        try (RLPStream stream2 = new RLPStream(pis)) {
            pos.write(0xf8);
            pos.write(0x37);
            Iterator<RLPItem> iter2 = stream2.iterator();
            for (int i = 0; i < 3; i++) {
                TestUtils.assertThrown(
                        IllegalArgumentException.class,
                        "long element data length must be 56 or greater; found: 55 for element @ 0",
                        iter2::hasNext
                );
            }
        }
    }
}
 
Example #2
Source File: ProtocolTest.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@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());
}
 
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: DuplexAsync.java    From PacketProxy with Apache License 2.0 6 votes vote down vote up
public DuplexAsync(Endpoint client_endpoint, Endpoint server_endpoint) throws Exception
{
	this.client = client_endpoint;
	this.server = server_endpoint;
	client_input  = (client_endpoint != null) ? client_endpoint.getInputStream() : null;
	client_output = (client_endpoint != null) ? client_endpoint.getOutputStream() : null;
	server_input  = (server_endpoint != null) ? server_endpoint.getInputStream() : null;
	server_output = (server_endpoint != null) ? server_endpoint.getOutputStream() : null;
	
	flow_controlled_client_output = new PipedOutputStream();
	flow_controlled_client_input = new PipedInputStream(flow_controlled_client_output, 65536);

	flow_controlled_server_output = new PipedOutputStream();
	flow_controlled_server_input = new PipedInputStream(flow_controlled_server_output, 65536);

	client_to_server = createClientToServerSimplex(client_input, flow_controlled_server_output);
	server_to_client = createServerToClientSimplex(server_input, flow_controlled_client_output);
	
	disableDuplexEventListener();
}
 
Example #5
Source File: SupportBundleManager.java    From datacollector with Apache License 2.0 6 votes vote down vote up
/**
 * Return InputStream from which a new generated resource bundle can be retrieved.
 */
public SupportBundle generateNewBundle(List<String> generatorNames, BundleType bundleType) throws IOException {
  List<BundleContentGeneratorDefinition> defs = getRequestedDefinitions(generatorNames);

  PipedInputStream inputStream = new PipedInputStream();
  PipedOutputStream outputStream = new PipedOutputStream();
  inputStream.connect(outputStream);
  ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);

  executor.submit(() -> generateNewBundleInternal(defs, bundleType, zipOutputStream));

  String bundleName = generateBundleName(bundleType);
  String bundleKey = generateBundleDate(bundleType) + "/" + bundleName;

  return new SupportBundle(
    bundleKey,
    bundleName,
    inputStream
  );
}
 
Example #6
Source File: JarBackSlash.java    From openjdk-jdk9 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);

    int rc = JAR_TOOL.run(out, System.err, jarArgs);
    if (rc != 0) {
        fail("Could not list jar file.");
    }

    out.flush();
    check(pipedInput.available() > 0);
}
 
Example #7
Source File: JarBackSlash.java    From jdk8u_jdk 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 #8
Source File: S3CommonPipedOutputStream.java    From hop with Apache License 2.0 6 votes vote down vote up
public S3CommonPipedOutputStream( S3CommonFileSystem fileSystem, String bucketId, String key, int partSize ) throws IOException {
  this.pipedInputStream = new PipedInputStream();

  try {
    this.pipedInputStream.connect( this );
  } catch ( IOException e ) {
    // FATAL, unexpected
    throw new IOException( "could not connect to pipedInputStream", e );
  }

  this.s3AsyncTransferRunner = new S3AsyncTransferRunner();
  this.bucketId = bucketId;
  this.key = key;
  this.fileSystem = fileSystem;
  this.partSize = partSize;
}
 
Example #9
Source File: JarBackSlash.java    From dragonwell8_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 #10
Source File: MvsConsoleWrapper.java    From java-samples with Apache License 2.0 6 votes vote down vote up
static void redirectSystemOut() throws Exception {
	PipedOutputStream pos = new PipedOutputStream();
	PrintStream ps = new PrintStream(pos);
	PipedInputStream pis = new PipedInputStream(pos);
	final BufferedReader reader = new BufferedReader(new InputStreamReader(pis));

	new Thread() {
		public void run() {
			try {
				String line = null;
				while ((line = reader.readLine()) != null) {
					MvsConsole.wto(line, 
									MvsConsole.ROUTCDE_SYSPROG_INFORMATION,
									MvsConsole.DESC_JOB_STATUS);
				}
			} catch(IOException ioe) {
				// Pipe breaks when shutting down; ignore
			}
		}
	}.start();
	System.setOut(ps);
}
 
Example #11
Source File: JarBackSlash.java    From openjdk-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 #12
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 #13
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 #14
Source File: JarBackSlash.java    From jdk8u60 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: JarBackSlash.java    From openjdk-8-source 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 #16
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 #17
Source File: BarURLHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
public InputStream getInputStream() throws IOException {
  final PipedInputStream pin = new PipedInputStream();
  final PipedOutputStream pout = new PipedOutputStream(pin);
  new Thread() {
    public void run() {
      try {
        BarTransformer.transform(barXmlURL, pout);
      } catch (Exception e) {
        LOGGER.warn("Bundle cannot be generated");
      } finally {
        try {
          pout.close();
        } catch (IOException ignore) {
          // if we get here something is very wrong
          LOGGER.error("Bundle cannot be generated", ignore);
        }
      }
    }
  }.start();
  return pin;
}
 
Example #18
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 #19
Source File: StreamReaderTest.java    From Ardulink-2 with Apache License 2.0 6 votes vote down vote up
@Test
public void canHandleDataNotAlreadyPresentSeparatedByNewline()
		throws Exception {
	List<String> expected = Arrays.asList("a", "b", "c");

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

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

	TimeUnit.SECONDS.sleep(2);
	os.write("a\nb\nc\n".getBytes());

	waitUntil(expected.size());
	assertThat(received, is(expected));
	reader.close();
}
 
Example #20
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 #21
Source File: StreamGobblerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testGobbleMultiLineBlockingStream() throws Exception {
    PipedOutputStream pipedOutputStream = new PipedOutputStream();
    PipedInputStream stream = new PipedInputStream(pipedOutputStream);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StreamGobbler gobbler = new StreamGobbler(stream, out, null);
    gobbler.start();
    try {
        pipedOutputStream.write("line1\n".getBytes());
        pipedOutputStream.flush();
        assertEqualsEventually(out, "line1" + NL);

        pipedOutputStream.write("line2\n".getBytes());
        pipedOutputStream.flush();
        assertEqualsEventually(out, "line1" + NL + "line2" + NL);

        pipedOutputStream.write("line".getBytes());
        pipedOutputStream.write("3\n".getBytes());
        pipedOutputStream.flush();
        assertEqualsEventually(out, "line1" + NL + "line2" + NL + "line3" + NL);

        pipedOutputStream.close();
        
        gobbler.join(10*1000);
        assertFalse(gobbler.isAlive());
        assertEquals(new String(out.toByteArray()), "line1" + NL + "line2" + NL + "line3" + NL);
    } finally {
        gobbler.close();
        gobbler.interrupt();
    }
}
 
Example #22
Source File: DockerMultiplexedInputStreamTest.java    From docker-plugin with MIT License 5 votes vote down vote up
public DemuxTester() throws IOException {
    feeder = new PipedOutputStream();

    feeder_input_stream = new PipedInputStream();
    feeder_input_stream.connect(feeder);
    
    stream = new DockerMultiplexedInputStream(feeder_input_stream);
    sink = new ByteArrayOutputStream();
    eof = false;
    exc = null;

    thread = new Thread(this);
    thread.start();
}
 
Example #23
Source File: GunzippingOutputStream.java    From Dream-Catcher with MIT License 5 votes vote down vote up
public static GunzippingOutputStream create(OutputStream finalOut) throws IOException {
  PipedInputStream pipeIn = new PipedInputStream();
  PipedOutputStream pipeOut = new PipedOutputStream(pipeIn);

  Future<Void> copyFuture = sExecutor.submit(
      new GunzippingCallable(pipeIn, finalOut));

  return new GunzippingOutputStream(pipeOut, copyFuture);
}
 
Example #24
Source File: UploadFileHandler.java    From viritin with Apache License 2.0 5 votes vote down vote up
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
    try {
        final PipedInputStream in = new PipedInputStream();
        final PipedOutputStream out = new PipedOutputStream(in);
        writeResponce(in, filename, mimeType);
        return out;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #25
Source File: StopExecutionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void testStopDetectingInputBufferWaitStop() throws Exception {
    Runnable shouldNotHappenRun =
            () -> { throw new AssertionError("Should not happen."); };
    Consumer<Exception> shouldNotHappenExc =
            exc -> { throw new AssertionError("Should not happen.", exc); };
    StopDetectingInputStream sd = new StopDetectingInputStream(shouldNotHappenRun, shouldNotHappenExc);
    CountDownLatch reading = new CountDownLatch(1);
    PipedInputStream is = new PipedInputStream() {
        @Override
        public int read() throws IOException {
            reading.countDown();
            return super.read();
        }
    };
    PipedOutputStream os = new PipedOutputStream(is);

    sd.setInputStream(is);
    sd.setState(State.BUFFER);
    reading.await();
    sd.setState(State.WAIT);
    os.write(3);
    int value = sd.read();

    if (value != 3) {
        throw new AssertionError();
    }
}
 
Example #26
Source File: AdxPipedImporter.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public AdxPipedImporter( DataValueSetService dataValueSetService, ImportOptions importOptions,
    JobConfiguration id, PipedOutputStream pipeOut, SessionFactory sessionFactory ) throws IOException
{
    this.dataValueSetService = dataValueSetService;
    this.pipeIn = new PipedInputStream( pipeOut, PIPE_BUFFER_SIZE );
    this.importOptions = importOptions;
    this.id = id;
    this.sessionFactory = sessionFactory;
    this.authentication = SecurityContextHolder.getContext().getAuthentication();
}
 
Example #27
Source File: PressUtilityTestCase.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testFactory() throws Exception {
	String left = "message";
	ByteArrayInputStream bufferInput = new ByteArrayInputStream(left.getBytes(StringUtility.CHARSET));
	PipedOutputStream pipeOutput = new PipedOutputStream();
	PipedInputStream pipeInput = new PipedInputStream(pipeOutput);
	ByteArrayOutputStream bufferOutput = new ByteArrayOutputStream();

	PressUtility.compress("gz", bufferInput, pipeOutput);
	PressUtility.decompress("gz", pipeInput, bufferOutput);

	String right = bufferOutput.toString(StringUtility.CHARSET.name());
	Assert.assertEquals(left, right);
}
 
Example #28
Source File: ContentHandlerOutputStream.java    From iaf with Apache License 2.0 5 votes vote down vote up
public ContentHandlerOutputStream(ContentHandler handler, ThreadConnector threadConnector) throws StreamingException {
	this.handler=handler;
	this.threadConnector=threadConnector;
	try {
		pipedInputStream=new PipedInputStream();
		connect(pipedInputStream);
		pipeReader.setUncaughtExceptionHandler(this);
		pipeReader.start();
	} catch (IOException e) {
		throw new StreamingException(e);
	}
}
 
Example #29
Source File: GZipUncompressorOutputStream.java    From rawhttp with Apache License 2.0 5 votes vote down vote up
GZipUncompressorOutputStream(OutputStream out, int bufferSize) {
    super(out);
    this.bufferSize = bufferSize;
    this.encodedBytesReceiver = new PipedInputStream();
    this.encodedBytesSink = new PipedOutputStream();
    this.executorService = Executors.newSingleThreadExecutor();
}
 
Example #30
Source File: XMLDumpTableInputStream.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
/**
 * Decorator for InputStream, which allows to convert an XML input stream to
 * SQL
 *
 * @param inputStream
 *            XML input stream
 * @throws IOException
 */
@Override
   public void initialize(InputStream inputStream, DumpTableEnum table)
		throws IOException {

	unbufferedResult = new PipedInputStream();
	decodedStream = new PipedOutputStream(unbufferedResult);
	result = new BufferedInputStream(unbufferedResult, BUFFERSIZE);

	xmlInputThread = new XMLDumpTableInputStreamThread(inputStream,
			decodedStream, table);
	xmlInputThread.start();

}