Package java.io

Examples of java.io.PipedOutputStream


      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
      final PipedOutputStream in_w;

      final PipedInputStream out_r;
      final PipedOutputStream out_w;
      try {
        in_r = new PipedInputStream();
        in_w = new PipedOutputStream(in_r);

        out_r = new PipedInputStream() {
          // The client (BasePackFetchConnection) can write
          // a huge burst before it reads again. We need to
          // force the buffer to be big enough, otherwise it
          // will deadlock both threads.
          {
            buffer = new byte[MIN_CLIENT_BUFFER];
          }
        };
        out_w = new PipedOutputStream(out_r);
      } catch (IOException err) {
        dst.close();
        throw new TransportException(uri, JGitText.get().cannotConnectPipes, err);
      }
View Full Code Here


      } catch (IOException err) {
        throw new TransportException(uri, JGitText.get().notAGitDirectory);
      }

      final PipedInputStream in_r;
      final PipedOutputStream in_w;

      final PipedInputStream out_r;
      final PipedOutputStream out_w;
      try {
        in_r = new PipedInputStream();
        in_w = new PipedOutputStream(in_r);

        out_r = new PipedInputStream();
        out_w = new PipedOutputStream(out_r);
      } catch (IOException err) {
        dst.close();
        throw new TransportException(uri, JGitText.get().cannotConnectPipes, err);
      }
View Full Code Here

        }

        final WinRmClient winRmClient = createWinrmClient();
        try {
            final PipedInputStream fromCallersStdin = new PipedInputStream();
            final PipedOutputStream callersStdin = new PipedOutputStream(fromCallersStdin);
            final PipedInputStream callersStdout = new PipedInputStream();
            final PipedOutputStream toCallersStdout = new PipedOutputStream(callersStdout);
            final PipedInputStream callersStderr = new PipedInputStream();
            final PipedOutputStream toCallersStderr = new PipedOutputStream(callersStderr);

            winRmClient.createShell();
            final String commandId = winRmClient.executeCommand(cmdString);

            final Exception inputReaderTheaException[] = new Exception[1];
View Full Code Here

            logger.info("Connecting to telnet://{}@{}", username, address);
            tc.connect(address, port);
            final InputStream stdout = tc.getInputStream();
            final OutputStream stdin = tc.getOutputStream();
            final PipedInputStream callersStdout = new PipedInputStream();
            final PipedOutputStream toCallersStdout = new PipedOutputStream(callersStdout);
            final ByteArrayOutputStream outputBuf = new ByteArrayOutputStream();
            final int[] exitValue = new int[1];
            exitValue[0] = -1;

            final Thread outputReaderThread = new Thread("Telnet output reader") {
View Full Code Here

    * @return content wrapped into stream
    * @throws IOException {@link IOException}
    */
   public InputStream getContentAsStream(final String rootHref) throws IOException
   {
      final PipedOutputStream po = new PipedOutputStream();
      final PipedInputStream pi = new PipedInputStream(po);
      new Thread()
      {
         @Override
         public void run()
         {
            try
            {
               XMLOutputFactory factory = XMLOutputFactory.newInstance();
               XMLStreamWriter writer = factory.createXMLStreamWriter(po, Constants.DEFAULT_ENCODING);

               writer.writeStartDocument(Constants.DEFAULT_ENCODING, "1.0");
               writer.writeStartElement(XML_NODE);
               writer.writeAttribute(PREFIX_XMLNS, PREFIX_LINK);
               writer.writeAttribute(XLINK_XMLNS, XLINK_LINK);
               writer.writeAttribute(XML_NAME, node.getName());
               writer.writeAttribute(XML_HREF, rootHref + TextUtil.escape(node.getPath(), '%', true));


               if (!node.getPath().equals("/"))
               {
                  // this is added to fix EXOJCR-1379
                  // XSLT string operations with actual node href, (which are used during XSLT transformation
                  // to receive parent href) produce wrong parent-href if node path containes non-latin symbols,
                  // so instead we simply add one more attribute which already contains parent-href
                  // as result: no XLST processor string manipulation is needed
                  String nodeParentHref = rootHref + TextUtil.escape(node.getParent().getPath(), '%', true);
                  writer.writeAttribute(XML_PARENT_HREF, nodeParentHref);
               }


               // add properties
               for (PropertyIterator pi = node.getProperties(); pi.hasNext();)
               {
                  Property curProperty = pi.nextProperty();
                  writer.writeStartElement(XML_PROPERTY);
                  writer.writeAttribute(XML_NAME, curProperty.getName());
                  String propertyHref = rootHref + curProperty.getPath();
                  writer.writeAttribute(XML_HREF, propertyHref);
                  writer.writeEndElement();
               }
               // add subnodes
               for (NodeIterator ni = node.getNodes(); ni.hasNext();)
               {
                  Node childNode = ni.nextNode();
                  writer.writeStartElement(XML_NODE);
                  writer.writeAttribute(XML_NAME, childNode.getName());
                  String childNodeHref = rootHref + TextUtil.escape(childNode.getPath(), '%', true);
                  writer.writeAttribute(XML_HREF, childNodeHref);
                  writer.writeEndElement();
               }
               writer.writeEndElement();
               writer.writeEndDocument();
            }
            catch (RepositoryException e)
            {
               LOG.error("Error has occured : ", e);
            }
            catch (XMLStreamException e)
            {
               LOG.error("Error has occured while xml processing : ", e);
            }
            finally
            {
               try
               {
                  po.flush();
                  po.close();
               }
               catch (IOException e)
               {
                  LOG.error(e.getMessage(), e);
               }
View Full Code Here

        int nosStages = descs.size();
        try {
            // Create all the threads for the pipeline, wiring up their input
            // and output streams.
            int stageNo = 0;
            PipedOutputStream pipeOut = null;
            for (CommandDescriptor desc : descs) {
                CommandIO in = CommandLine.DEFAULT_STDIN;
                CommandIO out = CommandLine.DEFAULT_STDOUT;
                CommandIO err = CommandLine.DEFAULT_STDERR;
                desc.openedStreams = new ArrayList<CommandIO>(2);
                try {
                    // redirect from
                    if (desc.fromFileName != null) {
                        in = new CommandInput(new FileInputStream(desc.fromFileName.text));
                        desc.openedStreams.add(in);
                    }
                } catch (IOException ex) {
                    throw new ShellInvocationException("cannot open '" +
                            desc.fromFileName.text + "': " + ex.getMessage());
                }
                try {
                    // redirect to
                    if (desc.toFileName != null) {
                        out = new CommandOutput(new FileOutputStream(desc.toFileName.text));
                        desc.openedStreams.add(out);
                    }
                } catch (IOException ex) {
                    throw new ShellInvocationException("cannot open '" +
                            desc.toFileName + "': " + ex.getMessage());
                }
                if (stageNo > 0) {
                    // pipe from
                    if (pipeOut != null) {
                        // the previous stage is sending stdout to the pipe
                        if (in == CommandLine.DEFAULT_STDIN) {
                            // this stage is going to read from the pipe
                            PipedInputStream pipeIn = new PipedInputStream();
                            try {
                                pipeIn.connect(pipeOut);
                            } catch (IOException ex) {
                                throw new ShellInvocationException(
                                        "Problem connecting pipe", ex);
                            }
                            in = new CommandInput(pipeIn);
                            desc.openedStreams.add(in);
                        } else {
                            // this stage has redirected stdin from a file ...
                            // so go back and replace the previous stage's
                            // pipeOut with devnull
                            CommandDescriptor prev = descs.get(stageNo - 1);
                            CommandIO[] prevIOs = prev.commandLine.getStreams();
                            try {
                                pipeOut.close();
                            } catch (IOException ex) {
                                // squash
                            }
                            prevIOs[Command.STD_OUT] = CommandLine.DEVNULL;
                        }
                    } else {
                        // the previous stage has explicitly redirected stdout
                        if (in == CommandLine.DEFAULT_STDIN) {
                            // this stage hasn't redirected stdin, so we need to
                            // give it a NullInputStream to suck on.
                            in = CommandLine.DEVNULL;
                        }
                    }
                }
                if (stageNo < nosStages - 1) {
                    // this stage is not the last one, and it hasn't redirected
                    // its stdout, so it will write to a pipe
                    if (out == CommandLine.DEFAULT_STDOUT) {
                        pipeOut = new PipedOutputStream();
                        out = new CommandOutput(new PrintStream(pipeOut));
                        desc.openedStreams.add(out);
                    }
                }
                desc.commandLine.setStreams(new CommandIO[] {in, out, err, CommandLine.DEFAULT_STDERR});
View Full Code Here

    * @return content wrapped into stream
    * @throws IOException {@link IOException}
    */
   public InputStream getContentAsStream(final String rootHref) throws IOException
   {
      final PipedOutputStream po = new PipedOutputStream();
      final PipedInputStream pi = new PipedInputStream(po);
      new Thread()
      {
         @Override
         public void run()
         {
            try
            {
               XMLOutputFactory factory = XMLOutputFactory.newInstance();
               XMLStreamWriter writer = factory.createXMLStreamWriter(po, Constants.DEFAULT_ENCODING);

               writer.writeStartDocument(Constants.DEFAULT_ENCODING, "1.0");
               writer.writeStartElement(XML_NODE);
               writer.writeAttribute(PREFIX_XMLNS, PREFIX_LINK);
               writer.writeAttribute(XLINK_XMLNS, XLINK_LINK);
               writer.writeAttribute(XML_NAME, node.getName());
               writer.writeAttribute(XML_HREF, rootHref + TextUtil.escape(node.getPath(), '%', true));
               // add properties
               for (PropertyIterator pi = node.getProperties(); pi.hasNext();)
               {
                  Property curProperty = pi.nextProperty();
                  writer.writeStartElement(XML_PROPERTY);
                  writer.writeAttribute(XML_NAME, curProperty.getName());
                  String propertyHref = rootHref + curProperty.getPath();
                  writer.writeAttribute(XML_HREF, propertyHref);
                  writer.writeEndElement();
               }
               // add subnodes
               for (NodeIterator ni = node.getNodes(); ni.hasNext();)
               {
                  Node childNode = ni.nextNode();
                  writer.writeStartElement(XML_NODE);
                  writer.writeAttribute(XML_NAME, childNode.getName());
                  String childNodeHref = rootHref + TextUtil.escape(childNode.getPath(), '%', true);
                  writer.writeAttribute(XML_HREF, childNodeHref);
                  writer.writeEndElement();
               }
               writer.writeEndElement();
               writer.writeEndDocument();
            }
            catch (RepositoryException e)
            {
               LOG.error("Error has occured : ", e);
            }
            catch (XMLStreamException e)
            {
               LOG.error("Error has occured while xml processing : ", e);
            }
            finally
            {
               try
               {
                  po.flush();
                  po.close();
               }
               catch (IOException e)
               {
                  LOG.error(e.getMessage(), e);
               }
View Full Code Here

   {
      final LargeMessageControllerImpl outBuffer = new LargeMessageControllerImpl(new FakeConsumerInternal(),
                                                                          1024 * 11 + 123,
                                                                          1);

      final PipedOutputStream output = new PipedOutputStream();
      final PipedInputStream input = new PipedInputStream(output);

      final AtomicInteger errors = new AtomicInteger(0);

      // Done reading 3 elements
View Full Code Here

    private Settings settings;
    private AeshConsole aeshConsole;
    private CommandRegistry registry;

    public AeshTestCommons() {
        pos = new PipedOutputStream();
        try {
            pis = new PipedInputStream(pos);
        }
        catch (IOException e) {
            e.printStackTrace();
View Full Code Here

  public OutputStream getOutputStream()
  {
    if (os == null)
    {
      os = new PipedOutputStream();
      mote.connectDataSource(os);
    }
    return os;
  }
View Full Code Here

TOP

Related Classes of java.io.PipedOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.