/// <exception cref="System.IO.IOException"></exception> private void SetupStreams() { this.inputStream = this.channel.GetInputStream(); // JSch won't let us interrupt writes when we use our InterruptTimer // to break out of a long-running write operation. To work around // that we spawn a background thread to shuttle data through a pipe, // as we can issue an interrupted write out of that. Its slower, so // we only use this route if there is a timeout. OutputStream @out = this.channel.GetOutputStream(); if (this.timeout <= 0) { this.outputStream = @out; } else { PipedInputStream pipeIn = new PipedInputStream(); StreamCopyThread copier = new StreamCopyThread(pipeIn, @out); PipedOutputStream pipeOut = new _PipedOutputStream_173(this, copier, pipeIn); // Just wake early, the thread will terminate // anyway. copier.Start(); this.outputStream = pipeOut; } this.errStream = this.channel.GetErrStream(); }
public SshHelper(string host, string username, string password) { this.host = host; JSch jsch = new JSch(); Session session = jsch.getSession(username, host, 22); session.setPassword(password); Hashtable config = new Hashtable(); config.Add("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); channel = (ChannelShell)session.openChannel("shell"); writer_po = new PipedOutputStream(); PipedInputStream writer_pi = new PipedInputStream(writer_po); PipedInputStream reader_pi = new PipedInputStream(); PipedOutputStream reader_po = new PipedOutputStream(reader_pi); reader = new StreamReader(reader_pi, Encoding.UTF8); channel.setInputStream(writer_pi); channel.setOutputStream(reader_po); channel.connect(); channel.setPtySize(132, 132, 1024, 768); }
public void GivenStreamingApp_PipedInput_IsOnlyEnumeratedWithinTheCommandMethod() { var stream = new PipedInputStream("aaa", "bbb"); new AppRunner <StreamingApp>() .AppendPipedInputToOperandList() .Configure(c => c.UseMiddleware((context, next) => { stream.EnumerationIsPremature = false; return(next(context)); }, MiddlewareStages.Invoke, -1)) .VerifyScenario(_testOutputHelper, new Scenario { Given = { PipedInput = stream }, WhenArgs = $"{nameof(StreamingApp.Stream)}", Then = { Outputs = { new List <string> { "aaa", "bbb" } } } }); }
public void TestBigWrite() { PipedInputStream pin = new PipedInputStream(); PipedOutputStream pout = new PipedOutputStream(pin); Random r = new Random(0); byte[] data = new byte [PipedInputStream.PIPE_SIZE * 3]; r.NextBytes(data); ThreadPool.QueueUserWorkItem(delegate { pout.Write(data); pout.Close(); }); int n = 0; byte[] buffer = new byte [100]; int nr; while ((nr = pin.Read(buffer)) != -1) { for (int i = 0; i < nr; i++) { Assert.AreEqual(buffer[i], data[n++], "Position " + n); } } }
public void GivenStreamingApp_PipedInput_IsOnlyEnumeratedWithinTheCommandMethod() { var stream = new PipedInputStream("aaa", "bbb"); new AppRunner <StreamingApp>() .AppendPipedInputToOperandList() .Configure(c => c.UseMiddleware((context, next) => { stream.EnumerationIsPremature = false; return(next(context)); }, MiddlewareStages.Invoke, -1)) .Verify(new Scenario { When = { Args = $"{nameof(StreamingApp.Stream)}", PipedInput = stream }, Then = { // stream is read-once so we can't evaluate it with a second time with ParamValuesShouldBe AssertContext = ctx => ctx.GetCommandInvocationInfo <StreamingApp>() .Instance.StreamedInput.Should().BeEquivalentTo(new List <string> { "aaa", "bbb" }) } }); }
public virtual void SetUp() { @out = new PipedOutputStream(); @in = new PipedInputStream(@out); timer = new InterruptTimer(); @is = new TimeoutInputStream(@in, timer); @is.SetTimeout(timeout); }
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(); }
private void CheckOutput(string[] args, string pattern, TextWriter @out, Type clazz ) { ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); try { PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(pipeOut, PipeBufferSize); if (@out == System.Console.Out) { Runtime.SetOut(new TextWriter(pipeOut)); } else { if (@out == System.Console.Error) { Runtime.SetErr(new TextWriter(pipeOut)); } } if (clazz == typeof(DelegationTokenFetcher)) { ExpectDelegationTokenFetcherExit(args); } else { if (clazz == typeof(JMXGet)) { ExpectJMXGetExit(args); } else { if (clazz == typeof(DFSAdmin)) { ExpectDfsAdminPrint(args); } } } pipeOut.Close(); ByteStreams.Copy(pipeIn, outBytes); pipeIn.Close(); NUnit.Framework.Assert.IsTrue(Sharpen.Runtime.GetStringForBytes(outBytes.ToByteArray ()).Contains(pattern)); } catch (Exception ex) { NUnit.Framework.Assert.Fail("checkOutput error " + ex); } }
/// <exception cref="NGit.Errors.TransportException"></exception> public InternalLocalFetchConnection(TransportLocal _enclosing) : base(_enclosing ) { this._enclosing = _enclosing; Repository dst; try { dst = new FileRepository(this._enclosing.remoteGitDir); } catch (IOException) { throw new TransportException(this.uri, JGitText.Get().notAGitDirectory); } PipedInputStream in_r; PipedOutputStream in_w; PipedInputStream out_r; PipedOutputStream out_w; try { in_r = new PipedInputStream(); in_w = new PipedOutputStream(in_r); out_r = new _PipedInputStream_193(); // 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. out_w = new PipedOutputStream(out_r); } catch (IOException err) { dst.Close(); throw new TransportException(this.uri, JGitText.Get().cannotConnectPipes, err); } this.worker = new _Thread_208(this, dst, out_r, in_w, "JGit-Upload-Pack"); // Client side of the pipes should report the problem. // Clients side will notice we went away, and report. // Ignore close failure, we probably crashed above. // Ignore close failure, we probably crashed above. this.worker.Start(); this.Init(in_r, out_w); this.ReadAdvertisedRefs(); }
public void GivenStreamingApp_PipedInput_IsOnlyEnumeratedWithinTheCommandMethod() { var stream = new PipedInputStream("aaa", "bbb"); AppRunner <StreamingApp>() .Configure(c => c.UseMiddleware((context, next) => { stream.EnumerationIsPremature = false; return(next(context)); }, MiddlewareStages.Invoke, -1)) .Verify(new Scenario { When = { Args = $"{nameof(StreamingApp.Stream)}", PipedInput = stream },
/// <exception cref="System.Exception"/> private static bool CheckPrintAllValues(JMXGet jmx) { int size = 0; byte[] bytes = null; string pattern = "List of all the available keys:"; PipedOutputStream pipeOut = new PipedOutputStream(); PipedInputStream pipeIn = new PipedInputStream(pipeOut); Runtime.SetErr(new TextWriter(pipeOut)); jmx.PrintAllValues(); if ((size = pipeIn.Available()) != 0) { bytes = new byte[size]; pipeIn.Read(bytes, 0, bytes.Length); } pipeOut.Close(); pipeIn.Close(); return(bytes != null?Sharpen.Runtime.GetStringForBytes(bytes).Contains(pattern) : false); }
/// <exception cref="NGit.Errors.TransportException"></exception> public InternalLocalPushConnection(TransportLocal _enclosing) : base(_enclosing ) { this._enclosing = _enclosing; Repository dst; try { dst = new FileRepository(this._enclosing.remoteGitDir); } catch (IOException) { throw new TransportException(this.uri, JGitText.Get().notAGitDirectory); } PipedInputStream in_r; PipedOutputStream in_w; PipedInputStream out_r; 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(this.uri, JGitText.Get().cannotConnectPipes, err); } this.worker = new _Thread_340(this, dst, out_r, in_w, "JGit-Receive-Pack"); // Client side of the pipes should report the problem. // Clients side will notice we went away, and report. // Ignore close failure, we probably crashed above. // Ignore close failure, we probably crashed above. this.worker.Start(); this.Init(in_r, out_w); this.ReadAdvertisedRefs(); }
/// <exception cref="System.IO.IOException"></exception> internal override OutputStream GetOutputStream() { // JSch won't let us interrupt writes when we use our InterruptTimer // to break out of a long-running write operation. To work around // that we spawn a background thread to shuttle data through a pipe, // as we can issue an interrupted write out of that. Its slower, so // we only use this route if there is a timeout. // OutputStream @out = this.channel.GetOutputStream(); if (this._enclosing.GetTimeout() <= 0) { return(@out); } PipedInputStream pipeIn = new PipedInputStream(); StreamCopyThread copier = new StreamCopyThread(pipeIn, @out); PipedOutputStream pipeOut = new _PipedOutputStream_259(this, copier, pipeIn); // Just wake early, the thread will terminate anyway. copier.Start(); return(pipeOut); }
/// <exception cref="System.Exception"/> protected internal virtual void VerifyJobPriority(string jobId, string priority, Configuration conf, CLI jc) { PipedInputStream pis = new PipedInputStream(); PipedOutputStream pos = new PipedOutputStream(pis); int exitCode = RunTool(conf, jc, new string[] { "-list", "all" }, pos); NUnit.Framework.Assert.AreEqual("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; } NUnit.Framework.Assert.IsTrue(line.Contains(priority)); break; } pis.Close(); }
/// <exception cref="System.IO.IOException"></exception> public PassiveOutputStream(Channel _enclosing, PipedInputStream @in) : base(@in) { this._enclosing = _enclosing; }
internal void Attach(PipedInputStream iss) { _ips = iss; }
public PipedOutputStream(PipedInputStream prm1) { }
public _PipedOutputStream_173(JschProcess _enclosing, StreamCopyThread copier, PipedInputStream baseArg1) : base(baseArg1) { this._enclosing = _enclosing; this.copier = copier; }
public PipedOutputStream(PipedInputStream iss) : this() { Attach(iss); }
public PipedOutputStream (PipedInputStream iss) : this() { Attach (iss); }
/// <summary> The main constructor for a ShellPanel. /// /// </summary> /// <param name="">engine /// The Jamocha engine that should be used with this GUI. /// /// </param> public ShellPanel(JamochaGui gui) : base(gui) { InitBlock(); // GUI construction // create the output area outputArea = new JTextArea(); outputArea.setEditable(false); outputArea.setLineWrap(true); outputArea.setWrapStyleWord(true); outputArea.addFocusListener(this); // set the font and the colors settingsChanged(); this.addFocusListener(this); // create a scroll pane to embedd the output area scrollPane = new JScrollPane(outputArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.VerticalScrollBar.addAdjustmentListener(this); // Assemble the GUI //UPGRADE_ISSUE: Constructor 'java.awt.BorderLayout.BorderLayout' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtBorderLayout"' setLayout(new BorderLayout()); //UPGRADE_ISSUE: Field 'java.awt.BorderLayout.CENTER' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtBorderLayout"' add(scrollPane, BorderLayout.CENTER); // create the button that clears the output area clearButton = new JButton("Clear Shell", IconLoader.getImageIcon("application_osx_terminal")); clearButton.addActionListener(this); JPanel clearButtonPanel = new JPanel(); //UPGRADE_ISSUE: Constructor 'java.awt.FlowLayout.FlowLayout' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtFlowLayout"' //UPGRADE_ISSUE: Field 'java.awt.FlowLayout.RIGHT' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtFlowLayout"' clearButtonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 1)); clearButtonPanel.add(clearButton); //UPGRADE_ISSUE: Field 'java.awt.BorderLayout' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000"' add(clearButtonPanel, BorderLayout.PAGE_END); // initialize the channel to the engine //UPGRADE_ISSUE: Constructor 'java.io.PipedOutputStream.PipedOutputStream' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioPipedOutputStreamPipedOutputStream"' System.IO.StreamWriter outStream = new PipedOutputStream(); //UPGRADE_ISSUE: Constructor 'java.io.PipedInputStream.PipedInputStream' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioPipedInputStreamPipedInputStream"' System.IO.StreamReader inStream = new PipedInputStream(); outWriter = new System.IO.StreamWriter(outStream); try { //UPGRADE_ISSUE: Method 'java.io.PipedInputStream.connect' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaioPipedInputStreamconnect_javaioPipedOutputStream"' inStream.connect(outStream); } catch (System.IO.IOException e) { SupportClass.WriteStackTrace(e, Console.Error); System.Environment.Exit(1); } channel = gui.Engine.MessageRouter.openChannel("JamochaGui", inStream); printPrompt(); moveCursorToEnd(); startTimer(); // initialize the channellistener for outputs from the engine initChannelListener(); // initialize the keylistener for key events initKeyListener(); // initialize the mouselistener for the context menu initPopupMenu(); }
internal void Attach (PipedInputStream iss) { _ips = iss; }
public PassiveOutputStream(PipedInputStream In) : base(In) { }
public _PipedOutputStream_259(JschConnection _enclosing, StreamCopyThread copier, PipedInputStream baseArg1) : base(baseArg1) { this._enclosing = _enclosing; this.copier = copier; }
public virtual void connect(PipedInputStream prm1) { }
public _Thread_340(InternalLocalPushConnection _enclosing, Repository dst, PipedInputStream out_r, PipedOutputStream in_w, string baseArg1) : base(baseArg1) { this._enclosing = _enclosing; this.dst = dst; this.out_r = out_r; this.in_w = in_w; }
public string execClass(string className) { if (TEST_IN_SAME_PROCESS) { try { ClassLoader loader = new URLClassLoader(new URL[] { new File(tmpdir).toURI().toURL() }, ClassLoader.getSystemClassLoader()); Class mainClass = (Class)loader.loadClass(className); Method mainMethod = mainClass.getDeclaredMethod("main", typeof(string[])); PipedInputStream stdoutIn = new PipedInputStream(); PipedInputStream stderrIn = new PipedInputStream(); PipedOutputStream stdoutOut = new PipedOutputStream(stdoutIn); PipedOutputStream stderrOut = new PipedOutputStream(stderrIn); StreamVacuum stdoutVacuum = new StreamVacuum(stdoutIn); StreamVacuum stderrVacuum = new StreamVacuum(stderrIn); PrintStream originalOut = Console.Out; System.setOut(new PrintStream(stdoutOut)); try { PrintStream originalErr = System.err; try { System.setErr(new PrintStream(stderrOut)); stdoutVacuum.start(); stderrVacuum.start(); mainMethod.invoke(null, (Object) new string[] { new File(tmpdir, "input").getAbsolutePath() }); } finally { System.setErr(originalErr); } } finally { System.setOut(originalOut); } stdoutOut.close(); stderrOut.close(); stdoutVacuum.join(); stderrVacuum.join(); string output = stdoutVacuum.tostring(); if (stderrVacuum.tostring().length() > 0) { this.stderrDuringParse = stderrVacuum.tostring(); Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum); } return(output); } catch (MalformedURLException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (NoSuchMethodException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, null, ex); } } try { string[] args = new string[] { "java", "-classpath", tmpdir + pathSep + CLASSPATH, className, new File(tmpdir, "input").getAbsolutePath() }; //string cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir, "input").getAbsolutePath(); //Console.WriteLine("execParser: "+cmdLine); Process process = Runtime.getRuntime().exec(args, null, new File(tmpdir)); StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream()); StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream()); stdoutVacuum.start(); stderrVacuum.start(); process.waitFor(); stdoutVacuum.join(); stderrVacuum.join(); string output = stdoutVacuum.tostring(); if (stderrVacuum.tostring().length() > 0) { this.stderrDuringParse = stderrVacuum.tostring(); Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum); } return(output); } catch (Exception e) { Console.Error.WriteLine("can't exec recognizer"); e.printStackTrace(System.err); } return(null); }
public InternalLocalPushConnection(TransportLocal transport) : base(transport) { Repository dst; try { dst = new Repository(transport.remoteGitDir); } catch (IOException) { throw new TransportException(uri, "Not a Git directory"); } PipedInputStream in_r; PipedOutputStream in_w; PipedInputStream out_r; 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 ex) { dst.Close(); throw new TransportException(uri, "Cannot connect pipes", ex); } worker = new Thread(() => { try { ReceivePack rp = new ReceivePack(dst); rp.receive(out_r, in_w, null); } catch (IOException) { // Client side of the pipes should report the problem. } catch (Exception) { // Clients side will notice we went away, and report. } finally { try { out_r.close(); } catch (IOException) { // Ignore close failure, we probably crashed above. } try { in_w.close(); } catch (IOException) { // Ignore close failure, we probably crashed above. } dst.Close(); } }); worker.Name = "JGit-Receive-Pack"; worker.Start(); init(in_r, out_w); readAdvertisedRefs(); }
internal PassiveOutputStream(PipedInputStream In) : base(In) { }
public runnable1(ChannelSftp channel, PipedInputStream pis, String _dst, SftpProgressMonitor monitor, int mode) { this.channel= channel; this.pis=pis; this._dst=_dst; this.monitor=monitor; this.mode=mode; }