org.apache.http.nio.IOControl#java.io.PipedInputStream源码实例Demo

下面列出了org.apache.http.nio.IOControl#java.io.PipedInputStream 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: PacketProxy   文件: DuplexAsync.java
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();
}
 
源代码2 项目: datacollector   文件: SupportBundleManager.java
/**
 * 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
  );
}
 
源代码3 项目: cachecloud   文件: ProtocolTest.java
@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 项目: jdk8u-jdk   文件: JarBackSlash.java
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);
}
 
源代码5 项目: hop   文件: S3CommonPipedOutputStream.java
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;
}
 
源代码6 项目: dragonwell8_jdk   文件: JarBackSlash.java
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);
}
 
源代码7 项目: jdk8u_jdk   文件: JarBackSlash.java
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);
}
 
源代码8 项目: java-samples   文件: MvsConsoleWrapper.java
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);
}
 
源代码9 项目: jdk8u60   文件: JarBackSlash.java
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);
}
 
源代码10 项目: headlong   文件: RLPStreamTest.java
@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
                );
            }
        }
    }
}
 
源代码11 项目: Ardulink-2   文件: StreamReaderTest.java
@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();
}
 
源代码12 项目: aesh-readline   文件: LineDisciplineTerminal.java
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);
}
 
源代码13 项目: activiti6-boot2   文件: BarURLHandler.java
@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;
}
 
源代码14 项目: openjdk-jdk8u   文件: JarBackSlash.java
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);
}
 
源代码15 项目: openjdk-8-source   文件: JarBackSlash.java
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);
}
 
源代码16 项目: android-sdk   文件: MicrophoneInputStream.java
/**
 * 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();
}
 
源代码17 项目: jdk8u-jdk   文件: JarBackSlash.java
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);
}
 
源代码18 项目: openjdk-8   文件: JarBackSlash.java
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);
}
 
源代码19 项目: openjdk-jdk9   文件: JarBackSlash.java
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);
}
 
源代码20 项目: stratosphere   文件: RecordTest.java
@Before
public void setUp() throws Exception
{
	PipedInputStream pipedInput = new PipedInputStream(1024*1024);
	this.in = new DataInputStream(pipedInput);
	this.out = new DataOutputStream(new PipedOutputStream(pipedInput));
}
 
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();
}
 
源代码22 项目: Flink-CEPplus   文件: PrimitiveDataTypeTest.java
@Before
public void setup() throws Exception {
	in = new PipedInputStream(1000);
	out = new PipedOutputStream(in);
	mIn = new DataInputViewStreamWrapper(in);
	mOut = new DataOutputViewStreamWrapper(out);
}
 
源代码23 项目: aesh-readline   文件: AbstractWindowsTerminal.java
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);
}
 
源代码24 项目: flink   文件: PrimitiveDataTypeTest.java
@Before
public void setup() throws Exception {
	in = new PipedInputStream(1000);
	out = new PipedOutputStream(in);
	mIn = new DataInputViewStreamWrapper(in);
	mOut = new DataOutputViewStreamWrapper(out);
}
 
源代码25 项目: KeePassJava2   文件: XmlOutputStreamFilter.java
public XmlOutputStreamFilter(final OutputStream outputStream, final XmlEventTransformer eventTransformer) throws IOException {

        super();
        pipedInputStream = new PipedInputStream(this);

        Callable<Boolean> output = new Callable<Boolean>() {
            public Boolean call() {
                try {
                    XMLEventReader eventReader = new com.fasterxml.aalto.stax.InputFactoryImpl()
                            .createXMLEventReader(pipedInputStream);
                    XMLEventWriter eventWriter = new com.fasterxml.aalto.stax.OutputFactoryImpl()
                            .createXMLEventWriter(outputStream);

                    XMLEvent event = null;
                    while (eventReader.hasNext()) {
                        event = eventReader.nextEvent();
                        event = eventTransformer.transform(event);
                        eventWriter.add(event);
                        eventWriter.flush();
                    }

                    eventReader.close();
                    eventWriter.flush();
                    eventWriter.close();
                    outputStream.flush();
                    outputStream.close();
                } catch (XMLStreamException | IOException e) {
                    throw new IllegalStateException(e);
                }
                return true;
            }
        };
        future = Executors.newSingleThreadExecutor().submit(output);
    }
 
源代码26 项目: whiskey   文件: HttpUrlConnectionImpl.java
@Override
public OutputStream getOutputStream() throws IOException {

    PipedOutputStream out = new PipedOutputStream();
    PipedInputStream in = new PipedInputStream();
    in.connect(out);
    requestBuilder.body(in);
    return out;
}
 
源代码27 项目: bither-desktop-java   文件: UEntropyCollector.java
public void start() throws IOException {
    if (shouldCollectData) {
        return;
    }
    shouldCollectData = true;
    in = new PipedInputStream(POOL_SIZE);
    out = new PipedOutputStream(in);
}
 
源代码28 项目: Javacord   文件: FileContainer.java
/**
 * Gets the input stream for the file.
 *
 * @param api The discord api instance.
 * @return The input stream for the file.
 * @throws IOException If an IO error occurs.
 */
public InputStream asInputStream(DiscordApi api) throws IOException {
    if (fileAsBufferedImage != null) {
        PipedOutputStream pos = new PipedOutputStream();
        PipedInputStream pis = new PipedInputStream(pos);
        api.getThreadPool().getExecutorService().submit(() -> {
            try {
                ImageIO.write(fileAsBufferedImage, getFileType(), pos);
                pos.close();
            } catch (Throwable t) {
                logger.error("Failed to process buffered image file!", t);
            }
        });
        return pis;
    }
    if (fileAsFile != null) {
        return new FileInputStream(fileAsFile);
    }
    if (fileAsIcon != null || fileAsUrl != null) {
        URL url = fileAsUrl == null ? fileAsIcon.getUrl() : fileAsUrl;
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        conn.setRequestProperty("User-Agent", Javacord.USER_AGENT);
        return conn.getInputStream();
    }
    if (fileAsByteArray != null) {
        return new ByteArrayInputStream(fileAsByteArray);
    }
    if (fileAsInputStream != null) {
        return fileAsInputStream;
    }
    throw new IllegalStateException("No file variant is set");
}
 
private static InputStream getInputStream(final AwContentsClient contentClient)
        throws IOException {
    final PipedInputStream inputStream = new PipedInputStream();
    final PipedOutputStream outputStream = new PipedOutputStream(inputStream);

    // Send the request to UI thread to callback to the client, and if it provides a
    // valid bitmap bounce on to the worker thread pool to compress it into the piped
    // input/output stream.
    ThreadUtils.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final Bitmap defaultVideoPoster = contentClient.getDefaultVideoPoster();
            if (defaultVideoPoster == null) {
                closeOutputStream(outputStream);
                return;
            }
            AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        defaultVideoPoster.compress(Bitmap.CompressFormat.PNG, 100,
                                outputStream);
                        outputStream.flush();
                    } catch (IOException e) {
                        Log.e(TAG, null, e);
                    } finally {
                        closeOutputStream(outputStream);
                    }
                }
            });
        }
    });
    return inputStream;
}
 
源代码30 项目: libstreaming   文件: RtcpDeinterleaver.java
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();
}