Inheritance: IDisposable
Exemplo n.º 1
1
 /// <exception cref="System.IO.IOException"/>
 public override void close()
 {
     if (_out != null)
     {
         if (_outPtr > 0)
         {
             _out.write(_outBuffer, 0, _outPtr);
             _outPtr = 0;
         }
         Sharpen.OutputStream @out = _out;
         _out = null;
         byte[] buf = _outBuffer;
         if (buf != null)
         {
             _outBuffer = null;
             _context.releaseWriteEncodingBuffer(buf);
         }
         @out.close();
         /* Let's 'flush' orphan surrogate, no matter what; but only
         * after cleanly closing everything else.
         */
         int code = _surrogate;
         _surrogate = 0;
         if (code > 0)
         {
             illegalSurrogate(code);
         }
     }
 }
Exemplo n.º 2
0
 public static List<DiffEntry> diff_Raw(this API_NGit nGit, OutputStream outputStream)
 {
     var diff = nGit.Git.Diff();
     if (outputStream.notNull())
         diff.SetOutputStream(outputStream);
     return diff.Call().toList();
 }
Exemplo n.º 3
0
		/// <exception cref="System.IO.IOException"></exception>
		private static void WriteField(MinimalField field, OutputStream @out)
		{
			WriteBytes(field.GetName(), @out);
			WriteBytes(FieldSep, @out);
			WriteBytes(field.GetBody(), @out);
			WriteBytes(CrLf, @out);
		}
 /// <summary>Static method to serialize the metadata object.</summary>
 /// <remarks>
 /// Static method to serialize the metadata object. For each serialisation, a new XMPSerializer
 /// instance is created, either XMPSerializerRDF or XMPSerializerPlain so thats its possible to
 /// serialialize the same XMPMeta objects in two threads.
 /// </remarks>
 /// <param name="xmp">a metadata implementation object</param>
 /// <param name="out">the output stream to serialize to</param>
 /// <param name="options">serialization options, can be <code>null</code> for default.</param>
 /// <exception cref="Com.Adobe.Xmp.XMPException"/>
 public static void Serialize(XMPMetaImpl xmp, OutputStream @out, SerializeOptions options)
 {
     options = options != null ? options : new SerializeOptions();
     // sort the internal data model on demand
     if (options.GetSort())
     {
         xmp.Sort();
     }
     new XMPSerializerRDF().Serialize(xmp, @out, options);
 }
 /// <exception cref="System.IO.IOException"></exception>
 public static void CopyStream(InputStream @is, OutputStream os)
 {
     int n;
     byte[] buffer = new byte[16384];
     while ((n = @is.Read(buffer)) > -1)
     {
         os.Write(buffer, 0, n);
     }
     os.Close();
     @is.Close();
 }
Exemplo n.º 6
0
		public URLConnection(Uri url) : base(url)
		{
			responseInputStream = new PipedInputStream();
			try
			{
				responseOutputStream = new PipedOutputStream((PipedInputStream)responseInputStream
					);
			}
			catch (IOException e)
			{
				Log.E(Database.Tag, "Exception creating piped output stream", e);
			}
		}
Exemplo n.º 7
0
 public UTF8Writer(com.fasterxml.jackson.core.io.IOContext ctxt, Sharpen.OutputStream
     @out)
 {
     _context = ctxt;
     _out = @out;
     _outBuffer = ctxt.allocWriteEncodingBuffer();
     /* Max. expansion for a single char (in unmodified UTF-8) is
     * 4 bytes (or 3 depending on how you view it -- 4 when recombining
     * surrogate pairs)
     */
     _outBufferEnd = _outBuffer.Length - 4;
     _outPtr = 0;
 }
Exemplo n.º 8
0
		/// <summary>
		/// Formats the results of a merge of
		/// <see cref="NGit.Diff.RawText">NGit.Diff.RawText</see>
		/// objects in a Git
		/// conformant way. This method also assumes that the
		/// <see cref="NGit.Diff.RawText">NGit.Diff.RawText</see>
		/// objects
		/// being merged are line oriented files which use LF as delimiter. This
		/// method will also use LF to separate chunks and conflict metadata,
		/// therefore it fits only to texts that are LF-separated lines.
		/// </summary>
		/// <param name="out">the outputstream where to write the textual presentation</param>
		/// <param name="res">the merge result which should be presented</param>
		/// <param name="seqName">
		/// When a conflict is reported each conflicting range will get a
		/// name. This name is following the "<&lt;&lt;&lt;&lt;&lt;&lt; " or ">&gt;&gt;&gt;&gt;&gt;&gt; "
		/// conflict markers. The names for the sequences are given in
		/// this list
		/// </param>
		/// <param name="charsetName">
		/// the name of the characterSet used when writing conflict
		/// metadata
		/// </param>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual void FormatMerge(OutputStream @out, MergeResult<RawText> res, IList
			<string> seqName, string charsetName)
		{
			string lastConflictingName = null;
			// is set to non-null whenever we are
			// in a conflict
			bool threeWayMerge = (res.GetSequences().Count == 3);
			foreach (MergeChunk chunk in res)
			{
				RawText seq = res.GetSequences()[chunk.GetSequenceIndex()];
				if (lastConflictingName != null && chunk.GetConflictState() != MergeChunk.ConflictState
					.NEXT_CONFLICTING_RANGE)
				{
					// found the end of an conflict
					@out.Write(Sharpen.Runtime.GetBytesForString((">>>>>>> " + lastConflictingName + 
						"\n"), charsetName));
					lastConflictingName = null;
				}
				if (chunk.GetConflictState() == MergeChunk.ConflictState.FIRST_CONFLICTING_RANGE)
				{
					// found the start of an conflict
					@out.Write(Sharpen.Runtime.GetBytesForString(("<<<<<<< " + seqName[chunk.GetSequenceIndex
						()] + "\n"), charsetName));
					lastConflictingName = seqName[chunk.GetSequenceIndex()];
				}
				else
				{
					if (chunk.GetConflictState() == MergeChunk.ConflictState.NEXT_CONFLICTING_RANGE)
					{
						// found another conflicting chunk
						lastConflictingName = seqName[chunk.GetSequenceIndex()];
						@out.Write(Sharpen.Runtime.GetBytesForString((threeWayMerge ? "=======\n" : "======= "
							 + lastConflictingName + "\n"), charsetName));
					}
				}
				// the lines with conflict-metadata are written. Now write the chunk
				for (int i = chunk.GetBegin(); i < chunk.GetEnd(); i++)
				{
					seq.WriteLine(@out, i);
					@out.Write('\n');
				}
			}
			// one possible leftover: if the merge result ended with a conflict we
			// have to close the last conflict here
			if (lastConflictingName != null)
			{
				@out.Write(Sharpen.Runtime.GetBytesForString((">>>>>>> " + lastConflictingName + 
					"\n"), charsetName));
			}
		}
Exemplo n.º 9
0
 /// <summary>Serializes the XmpDirectory component of <code>Metadata</code> into an <code>OutputStream</code></summary>
 /// <param name="os">Destination for the xmp data</param>
 /// <param name="data">populated metadata</param>
 /// <returns>serialize success</returns>
 public static bool Write(OutputStream os, Com.Drew.Metadata.Metadata data)
 {
     XmpDirectory dir = data.GetFirstDirectoryOfType<XmpDirectory>();
     if (dir == null)
     {
         return false;
     }
     XMPMeta meta = dir.GetXMPMeta();
     try
     {
         SerializeOptions so = new SerializeOptions().SetOmitPacketWrapper(true);
         XMPMetaFactory.Serialize(meta, os, so);
     }
     catch (XMPException e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
         return false;
     }
     return true;
 }
Exemplo n.º 10
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void WriteTo(OutputStream @out)
		{
			if (@out == null)
			{
				throw new ArgumentException("Output stream may not be null");
			}
			try
			{
				byte[] tmp = new byte[4096];
				int l;
				while ((l = [email protected](tmp)) != -1)
				{
					@out.Write(tmp, 0, l);
				}
				@out.Flush();
			}
			finally
			{
				[email protected]();
			}
		}
Exemplo n.º 11
0
		/// <param name="out"></param>
		public AutoCRLFOutputStream(OutputStream @out)
		{
			this.@out = @out;
		}
Exemplo n.º 12
0
 public FilterOutputStream(OutputStream os)
 {
     this.@out = os;
 }
Exemplo n.º 13
0
		protected internal PackIndexWriterV2(OutputStream dst) : base(dst)
		{
		}
Exemplo n.º 14
0
		// The hunk header is not taken into account for patch id calculation
		/// <exception cref="System.IO.IOException"></exception>
		protected internal override void FormatIndexLine(OutputStream o, DiffEntry ent)
		{
		}
 /// <summary>Constructor with providing the output stream to decorate.</summary>
 /// <param name="out">an <code>OutputStream</code></param>
 internal CountOutputStream(OutputStream @out)
 {
     this.@out = @out;
 }
Exemplo n.º 16
0
        /// <summary>Execute the receive task on the socket.</summary>
        /// <remarks>Execute the receive task on the socket.</remarks>
        /// <param name="input">
        /// raw input to read client commands and pack data from. Caller
        /// must ensure the input is buffered, otherwise read performance
        /// may suffer.
        /// </param>
        /// <param name="output">
        /// response back to the Git network client. Caller must ensure
        /// the output is buffered, otherwise write performance may
        /// suffer.
        /// </param>
        /// <param name="messages">
        /// secondary "notice" channel to send additional messages out
        /// through. When run over SSH this should be tied back to the
        /// standard error channel of the command execution. For most
        /// other network connections this should be null.
        /// </param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual void Receive(InputStream input, OutputStream output, OutputStream 
			messages)
        {
            Init(input, output, messages);
            try
            {
                Service();
            }
            finally
            {
                try
                {
                    Close();
                }
                finally
                {
                    Release();
                }
            }
        }
Exemplo n.º 17
0
		/// <exception cref="NSch.JSchException"></exception>
		public virtual void Connect(int connectTimeout)
		{
			if (isConnected)
			{
				throw new JSchException("session is already connected");
			}
			io = new IO();
			if (random == null)
			{
				try
				{
					Type c = Sharpen.Runtime.GetType(GetConfig("random"));
					random = (Random)(System.Activator.CreateInstance(c));
				}
				catch (Exception e)
				{
					throw new JSchException(e.ToString(), e);
				}
			}
			Packet.SetRandom(random);
			if (JSch.GetLogger().IsEnabled(Logger.INFO))
			{
				JSch.GetLogger().Log(Logger.INFO, "Connecting to " + host + " port " + port);
			}
			try
			{
				int i;
				int j;
				if (proxy == null)
				{
					InputStream @in;
					OutputStream @out;
					if (socket_factory == null)
					{
						socket = Util.CreateSocket(host, port, connectTimeout);
						@in = socket.GetInputStream();
						@out = socket.GetOutputStream();
					}
					else
					{
						socket = socket_factory.CreateSocket(host, port);
						@in = socket_factory.GetInputStream(socket);
						@out = socket_factory.GetOutputStream(socket);
					}
					//if(timeout>0){ socket.setSoTimeout(timeout); }
					socket.NoDelay = true;
					io.SetInputStream(@in);
					io.SetOutputStream(@out);
				}
				else
				{
					lock (proxy)
					{
						proxy.Connect(socket_factory, host, port, connectTimeout);
						io.SetInputStream(proxy.GetInputStream());
						io.SetOutputStream(proxy.GetOutputStream());
						socket = proxy.GetSocket();
					}
				}
				if (connectTimeout > 0 && socket != null)
				{
					socket.ReceiveTimeout = connectTimeout;
				}
				isConnected = true;
				if (JSch.GetLogger().IsEnabled(Logger.INFO))
				{
					JSch.GetLogger().Log(Logger.INFO, "Connection established");
				}
				jsch.AddSession(this);
				{
					// Some Cisco devices will miss to read '\n' if it is sent separately.
					byte[] foo = new byte[V_C.Length + 1];
					System.Array.Copy(V_C, 0, foo, 0, V_C.Length);
					foo[foo.Length - 1] = unchecked((byte)(byte)('\n'));
					io.Put(foo, 0, foo.Length);
				}
				while (true)
				{
					i = 0;
					j = 0;
					while (i < buf.buffer.Length)
					{
						j = io.GetByte();
						if (j < 0)
						{
							break;
						}
						buf.buffer[i] = unchecked((byte)j);
						i++;
						if (j == 10)
						{
							break;
						}
					}
					if (j < 0)
					{
						throw new JSchException("connection is closed by foreign host");
					}
					if (buf.buffer[i - 1] == 10)
					{
						// 0x0a
						i--;
						if (i > 0 && buf.buffer[i - 1] == 13)
						{
							// 0x0d
							i--;
						}
					}
					if (i <= 3 || ((i != buf.buffer.Length) && (buf.buffer[0] != 'S' || buf.buffer[1]
						 != 'S' || buf.buffer[2] != 'H' || buf.buffer[3] != '-')))
					{
						// It must not start with 'SSH-'
						//System.err.println(new String(buf.buffer, 0, i);
						continue;
					}
					if (i == buf.buffer.Length || i < 7 || (buf.buffer[4] == '1' && buf.buffer[6] != 
						'9'))
					{
						// SSH-1.99 or SSH-2.0
						// SSH-1.5
						throw new JSchException("invalid server's version string");
					}
					break;
				}
				V_S = new byte[i];
				System.Array.Copy(buf.buffer, 0, V_S, 0, i);
				//System.err.println("V_S: ("+i+") ["+new String(V_S)+"]");
				if (JSch.GetLogger().IsEnabled(Logger.INFO))
				{
					JSch.GetLogger().Log(Logger.INFO, "Remote version string: " + Util.Byte2str(V_S));
					JSch.GetLogger().Log(Logger.INFO, "Local version string: " + Util.Byte2str(V_C));
				}
				Send_kexinit();
				buf = Read(buf);
				if (buf.GetCommand() != SSH_MSG_KEXINIT)
				{
					in_kex = false;
					throw new JSchException("invalid protocol: " + buf.GetCommand());
				}
				if (JSch.GetLogger().IsEnabled(Logger.INFO))
				{
					JSch.GetLogger().Log(Logger.INFO, "SSH_MSG_KEXINIT received");
				}
				KeyExchange kex = Receive_kexinit(buf);
				while (true)
				{
					buf = Read(buf);
					if (kex.GetState() == buf.GetCommand())
					{
						kex_start_time = Runtime.CurrentTimeMillis();
						bool result = kex.Next(buf);
						if (!result)
						{
							//System.err.println("verify: "+result);
							in_kex = false;
							throw new JSchException("verify: " + result);
						}
					}
					else
					{
						in_kex = false;
						throw new JSchException("invalid protocol(kex): " + buf.GetCommand());
					}
					if (kex.GetState() == KeyExchange.STATE_END)
					{
						break;
					}
				}
				try
				{
					CheckHost(host, port, kex);
				}
				catch (JSchException ee)
				{
					in_kex = false;
					throw;
				}
				Send_newkeys();
				// receive SSH_MSG_NEWKEYS(21)
				buf = Read(buf);
				//System.err.println("read: 21 ? "+buf.getCommand());
				if (buf.GetCommand() == SSH_MSG_NEWKEYS)
				{
					if (JSch.GetLogger().IsEnabled(Logger.INFO))
					{
						JSch.GetLogger().Log(Logger.INFO, "SSH_MSG_NEWKEYS received");
					}
					Receive_newkeys(buf, kex);
				}
				else
				{
					in_kex = false;
					throw new JSchException("invalid protocol(newkyes): " + buf.GetCommand());
				}
				bool auth = false;
				bool auth_cancel = false;
				UserAuth ua = null;
				try
				{
					Type c = Sharpen.Runtime.GetType(GetConfig("userauth.none"));
					ua = (UserAuth)(System.Activator.CreateInstance(c));
				}
				catch (Exception e)
				{
					throw new JSchException(e.ToString(), e);
				}
				auth = ua.Start(this);
				string cmethods = GetConfig("PreferredAuthentications");
				string[] cmethoda = Util.Split(cmethods, ",");
				string smethods = null;
				if (!auth)
				{
					smethods = ((UserAuthNone)ua).GetMethods();
					if (smethods != null)
					{
						smethods = smethods.ToLower();
					}
					else
					{
						// methods: publickey,password,keyboard-interactive
						//smethods="publickey,password,keyboard-interactive";
						smethods = cmethods;
					}
				}
				string[] smethoda = Util.Split(smethods, ",");
				int methodi = 0;
				while (true)
				{
					//System.err.println("methods: "+methods);
					while (!auth && cmethoda != null && methodi < cmethoda.Length)
					{
						string method = cmethoda[methodi++];
						bool acceptable = false;
						for (int k = 0; k < smethoda.Length; k++)
						{
							if (smethoda[k].Equals(method))
							{
								acceptable = true;
								break;
							}
						}
						if (!acceptable)
						{
							continue;
						}
						//System.err.println("  method: "+method);
						if (JSch.GetLogger().IsEnabled(Logger.INFO))
						{
							string str = "Authentications that can continue: ";
							for (int k_1 = methodi - 1; k_1 < cmethoda.Length; k_1++)
							{
								str += cmethoda[k_1];
								if (k_1 + 1 < cmethoda.Length)
								{
									str += ",";
								}
							}
							JSch.GetLogger().Log(Logger.INFO, str);
							JSch.GetLogger().Log(Logger.INFO, "Next authentication method: " + method);
						}
						ua = null;
						try
						{
							Type c = null;
							if (GetConfig("userauth." + method) != null)
							{
								c = Sharpen.Runtime.GetType(GetConfig("userauth." + method));
								ua = (UserAuth)(System.Activator.CreateInstance(c));
							}
						}
						catch (Exception)
						{
							if (JSch.GetLogger().IsEnabled(Logger.WARN))
							{
								JSch.GetLogger().Log(Logger.WARN, "failed to load " + method + " method");
							}
						}
						if (ua != null)
						{
							auth_cancel = false;
							try
							{
								auth = ua.Start(this);
								if (auth && JSch.GetLogger().IsEnabled(Logger.INFO))
								{
									JSch.GetLogger().Log(Logger.INFO, "Authentication succeeded (" + method + ").");
								}
							}
							catch (JSchAuthCancelException)
							{
								auth_cancel = true;
							}
							catch (JSchPartialAuthException ee)
							{
								string tmp = smethods;
								smethods = ee.GetMethods();
								smethoda = Util.Split(smethods, ",");
								if (!tmp.Equals(smethods))
								{
									methodi = 0;
								}
								//System.err.println("PartialAuth: "+methods);
								auth_cancel = false;
								goto loop_continue;
							}
							catch (RuntimeException ee)
							{
								throw;
							}
							catch (Exception)
							{
								//System.err.println("ee: "+ee); // SSH_MSG_DISCONNECT: 2 Too many authentication failures
								goto loop_break;
							}
						}
					}
					break;
loop_continue: ;
				}
loop_break: ;
				if (!auth)
				{
					if (auth_cancel)
					{
						throw new JSchException("Auth cancel");
					}
					throw new JSchException("Auth fail");
				}
				if (connectTimeout > 0 || timeout > 0)
				{
					socket.ReceiveTimeout = timeout;
				}
				isAuthed = true;
				lock (Lock)
				{
					if (isConnected)
					{
						connectThread = new Sharpen.Thread(this);
						connectThread.SetName("Connect thread " + host + " session");
						if (daemon_thread)
						{
							connectThread.SetDaemon(daemon_thread);
						}
						connectThread.Start();
					}
				}
			}
			catch (Exception e)
			{
				// The session has been already down and
				// we don't have to start new thread.
				in_kex = false;
				if (isConnected)
				{
					try
					{
						packet.Reset();
						buf.PutByte(unchecked((byte)SSH_MSG_DISCONNECT));
						buf.PutInt(3);
						buf.PutString(Util.Str2byte(e.ToString()));
						buf.PutString(Util.Str2byte("en"));
						Write(packet);
						Disconnect();
					}
					catch (Exception)
					{
					}
				}
				isConnected = false;
				//e.printStackTrace();
				if (e is RuntimeException)
				{
					throw (RuntimeException)e;
				}
				if (e is JSchException)
				{
					throw (JSchException)e;
				}
				throw new JSchException("Session.connect: " + e);
			}
			finally
			{
				Util.Bzero(this.password);
				this.password = null;
			}
		}
Exemplo n.º 18
0
 public OutputStreamWriter(OutputStream stream, Encoding encoding) : base(stream.GetWrappedStream(), encoding)
 {
 }
Exemplo n.º 19
0
		public override void Close()
		{
			if (@out != null)
			{
				try
				{
					if (outNeedsEnd)
					{
						outNeedsEnd = false;
						pckOut.End();
					}
					@out.Close();
				}
				catch (IOException)
				{
				}
				finally
				{
					// Ignore any close errors.
					@out = null;
					pckOut = null;
				}
			}
			if (@in != null)
			{
				try
				{
					@in.Close();
				}
				catch (IOException)
				{
				}
				finally
				{
					// Ignore any close errors.
					@in = null;
					pckIn = null;
				}
			}
			if (myTimer != null)
			{
				try
				{
					myTimer.Terminate();
				}
				finally
				{
					myTimer = null;
					timeoutIn = null;
					timeoutOut = null;
				}
			}
		}
Exemplo n.º 20
0
 public static OutputStream GetOutputStream(this Process p)
 {
     return(OutputStream.Wrap(p.StandardInput.BaseStream));
 }
Exemplo n.º 21
0
 public OutputStreamWriter(OutputStream stream) : base(stream.GetWrappedStream())
 {
 }
Exemplo n.º 22
0
 public ObjectOutputStream(OutputStream os)
 {
     this.bw = new BinaryWriter(os.GetWrappedStream());
 }
 public BufferedOutputStream(OutputStream outs, int bufferSize)
 {
     base.Wrapped = new BufferedStream(outs.GetWrappedStream(), bufferSize);
 }
 public BufferedOutputStream(OutputStream outs)
 {
     base.Wrapped = new BufferedStream(outs == null ? new MemoryStream() : outs.GetWrappedStream());
 }
Exemplo n.º 25
0
 public BufferedOutputStream(OutputStream outs, int bufferSize)
 {
     base.Wrapped = new BufferedStream (outs.GetWrappedStream (), bufferSize);
 }
Exemplo n.º 26
0
 public WrappedSystemStream(OutputStream ost)
 {
     this.ost = ost;
 }
Exemplo n.º 27
0
 public BufferedOutputStream(OutputStream outs)
 {
     base.Wrapped = new BufferedStream (outs.GetWrappedStream ());
 }
Exemplo n.º 28
0
 public OutputStreamWriter(OutputStream stream, string encoding) : base(stream.GetWrappedStream(), Extensions.GetEncoding(encoding))
 {
 }
Exemplo n.º 29
0
		public virtual void SetOutputStream(OutputStream @out)
		{
			this.@out = @out;
		}
Exemplo n.º 30
0
		/// <summary>Execute the upload task on the socket.</summary>
		/// <remarks>Execute the upload task on the socket.</remarks>
		/// <param name="input">
		/// raw input to read client commands from. Caller must ensure the
		/// input is buffered, otherwise read performance may suffer.
		/// </param>
		/// <param name="output">
		/// response back to the Git network client, to write the pack
		/// data onto. Caller must ensure the output is buffered,
		/// otherwise write performance may suffer.
		/// </param>
		/// <param name="messages">
		/// secondary "notice" channel to send additional messages out
		/// through. When run over SSH this should be tied back to the
		/// standard error channel of the command execution. For most
		/// other network connections this should be null.
		/// </param>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual void Upload(InputStream input, OutputStream output, OutputStream messages
			)
		{
			try
			{
				rawIn = input;
				rawOut = output;
				if (timeout > 0)
				{
					Sharpen.Thread caller = Sharpen.Thread.CurrentThread();
					timer = new InterruptTimer(caller.GetName() + "-Timer");
					TimeoutInputStream i = new TimeoutInputStream(rawIn, timer);
					TimeoutOutputStream o = new TimeoutOutputStream(rawOut, timer);
					i.SetTimeout(timeout * 1000);
					o.SetTimeout(timeout * 1000);
					rawIn = i;
					rawOut = o;
				}
				pckIn = new PacketLineIn(rawIn);
				pckOut = new PacketLineOut(rawOut);
				Service();
			}
			finally
			{
				walk.Release();
				if (timer != null)
				{
					try
					{
						timer.Terminate();
					}
					finally
					{
						timer = null;
					}
				}
			}
		}
Exemplo n.º 31
0
 public _OutputStream_323(LockFile _enclosing, OutputStream @out)
 {
     this._enclosing = _enclosing;
     this.@out = @out;
 }
Exemplo n.º 32
0
 /// <summary>Create a new stream to write side band packets.</summary>
 /// <remarks>Create a new stream to write side band packets.</remarks>
 /// <param name="chan">
 /// channel number to prefix all packets with, so the remote side
 /// can demultiplex the stream and get back the original data.
 /// Must be in the range [0, 255].
 /// </param>
 /// <param name="sz">
 /// maximum size of a data packet within the stream. The remote
 /// side needs to agree to the packet size to prevent buffer
 /// overflows. Must be in the range [HDR_SIZE + 1, MAX_BUF).
 /// </param>
 /// <param name="os">
 /// stream that the packets are written onto. This stream should
 /// be attached to a SideBandInputStream on the remote side.
 /// </param>
 public SideBandOutputStream(int chan, int sz, OutputStream os)
 {
     if (chan <= 0 || chan > 255)
     {
         throw new ArgumentException(MessageFormat.Format(JGitText.Get().channelMustBeInRange0_255
             , chan));
     }
     if (sz <= HDR_SIZE)
     {
         throw new ArgumentException(MessageFormat.Format(JGitText.Get().packetSizeMustBeAtLeast
             , sz, HDR_SIZE));
     }
     else
     {
         if (MAX_BUF < sz)
         {
             throw new ArgumentException(MessageFormat.Format(JGitText.Get().packetSizeMustBeAtMost
                 , sz, MAX_BUF));
         }
     }
     @out = os;
     buffer = new byte[sz];
     buffer[4] = unchecked((byte)chan);
     cnt = HDR_SIZE;
 }
Exemplo n.º 33
0
		/// <summary>Write a specific line to the output stream, without its trailing LF.</summary>
		/// <remarks>
		/// Write a specific line to the output stream, without its trailing LF.
		/// <p>
		/// The specified line is copied as-is, with no character encoding
		/// translation performed.
		/// <p>
		/// If the specified line ends with an LF ('\n'), the LF is <b>not</b>
		/// copied. It is up to the caller to write the LF, if desired, between
		/// output lines.
		/// </remarks>
		/// <param name="out">stream to copy the line data onto.</param>
		/// <param name="i">
		/// index of the line to extract. Note this is 0-based, so line
		/// number 1 is actually index 0.
		/// </param>
		/// <exception cref="System.IO.IOException">the stream write operation failed.</exception>
		public virtual void WriteLine(OutputStream @out, int i)
		{
			int start = GetStart(i);
			int end = GetEnd(i);
			if (content[end - 1] == '\n')
			{
				end--;
			}
			@out.Write(content, start, end - start);
		}
Exemplo n.º 34
0
		public override void SetOutputStream(OutputStream @out)
		{
			io.SetOutputStream(@out);
		}
Exemplo n.º 35
0
		/// <summary>Configure this connection with the directional pipes.</summary>
		/// <remarks>Configure this connection with the directional pipes.</remarks>
		/// <param name="myIn">
		/// input stream to receive data from the peer. Caller must ensure
		/// the input is buffered, otherwise read performance may suffer.
		/// </param>
		/// <param name="myOut">
		/// output stream to transmit data to the peer. Caller must ensure
		/// the output is buffered, otherwise write performance may
		/// suffer.
		/// </param>
		protected internal void Init(InputStream myIn, OutputStream myOut)
		{
			int timeout = transport.GetTimeout();
			if (timeout > 0)
			{
				Sharpen.Thread caller = Sharpen.Thread.CurrentThread();
				myTimer = new InterruptTimer(caller.GetName() + "-Timer");
				timeoutIn = new TimeoutInputStream(myIn, myTimer);
				timeoutOut = new TimeoutOutputStream(myOut, myTimer);
				timeoutIn.SetTimeout(timeout * 1000);
				timeoutOut.SetTimeout(timeout * 1000);
				myIn = timeoutIn;
				myOut = timeoutOut;
			}
			@in = myIn;
			@out = myOut;
			pckIn = new PacketLineIn(@in);
			pckOut = new PacketLineOut(@out);
			outNeedsEnd = true;
		}
Exemplo n.º 36
0
 public WrappedSystemStream(OutputStream ost)
 {
     this.ost = ost;
 }
Exemplo n.º 37
0
		/// <summary>Tell the peer we are disconnecting, if it cares to know.</summary>
		/// <remarks>Tell the peer we are disconnecting, if it cares to know.</remarks>
		protected internal virtual void EndOut()
		{
			if (outNeedsEnd && @out != null)
			{
				try
				{
					outNeedsEnd = false;
					pckOut.End();
				}
				catch (IOException)
				{
					try
					{
						@out.Close();
					}
					catch (IOException)
					{
					}
					finally
					{
						// Ignore any close errors.
						@out = null;
						pckOut = null;
					}
				}
			}
		}
Exemplo n.º 38
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void ExtractFileLines(OutputStream[] @out)
        {
            byte[] buf = file.buf;
            int ptr = startOffset;
            int eol = RawParseUtils.NextLF(buf, ptr);
            if (endOffset <= eol)
            {
                return;
            }
            // Treat the hunk header as though it were from the ancestor,
            // as it may have a function header appearing after it which
            // was copied out of the ancestor file.
            //
            @out[0].Write(buf, ptr, eol - ptr);
            for (ptr = eol; ptr < endOffset; ptr = eol)
            {
                eol = RawParseUtils.NextLF(buf, ptr);
                switch (buf[ptr])
                {
                    case (byte)(' '):
                    case (byte)('\n'):
                    case (byte)('\\'):
                    {
                        @out[0].Write(buf, ptr, eol - ptr);
                        @out[1].Write(buf, ptr, eol - ptr);
                        break;
                    }

                    case (byte)('-'):
                    {
                        @out[0].Write(buf, ptr, eol - ptr);
                        break;
                    }

                    case (byte)('+'):
                    {
                        @out[1].Write(buf, ptr, eol - ptr);
                        break;
                    }

                    default:
                    {
                        goto SCAN_break;
                        break;
                    }
                }
            SCAN_continue: ;
            }
            SCAN_break: ;
        }
Exemplo n.º 39
0
		/// <summary>Generate and write the bundle to the output stream.</summary>
		/// <remarks>
		/// Generate and write the bundle to the output stream.
		/// <p>
		/// This method can only be called once per BundleWriter instance.
		/// </remarks>
		/// <param name="monitor">progress monitor to report bundle writing status to.</param>
		/// <param name="os">
		/// the stream the bundle is written to. The stream should be
		/// buffered by the caller. The caller is responsible for closing
		/// the stream.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// an error occurred reading a local object's data to include in
		/// the bundle, or writing compressed object data to the output
		/// stream.
		/// </exception>
		public virtual void WriteBundle(ProgressMonitor monitor, OutputStream os)
		{
			PackConfig pc = packConfig;
			if (pc == null)
			{
				pc = new PackConfig(db);
			}
			PackWriter packWriter = new PackWriter(pc, db.NewObjectReader());
			try
			{
				HashSet<ObjectId> inc = new HashSet<ObjectId>();
				HashSet<ObjectId> exc = new HashSet<ObjectId>();
				Sharpen.Collections.AddAll(inc, include.Values);
				foreach (RevCommit r in assume)
				{
					exc.AddItem(r.Id);
				}
				packWriter.SetDeltaBaseAsOffset(true);
				packWriter.SetThin(exc.Count > 0);
				packWriter.SetReuseValidatingObjects(false);
				if (exc.Count == 0)
				{
					packWriter.SetTagTargets(tagTargets);
				}
				packWriter.PreparePack(monitor, inc, exc);
				TextWriter w = new OutputStreamWriter(os, Constants.CHARSET);
				w.Write(NGit.Transport.TransportBundleConstants.V2_BUNDLE_SIGNATURE);
				w.Write('\n');
				char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
				foreach (RevCommit a in assume)
				{
					w.Write('-');
					a.CopyTo(tmp, w);
					if (a.RawBuffer != null)
					{
						w.Write(' ');
						w.Write(a.GetShortMessage());
					}
					w.Write('\n');
				}
				foreach (KeyValuePair<string, ObjectId> e in include.EntrySet())
				{
					e.Value.CopyTo(tmp, w);
					w.Write(' ');
					w.Write(e.Key);
					w.Write('\n');
				}
				w.Write('\n');
				w.Flush();
				packWriter.WritePack(monitor, monitor, os);
			}
			finally
			{
				packWriter.Release();
			}
		}
Exemplo n.º 40
0
 public GZIPOutputStream(OutputStream os)
 {
     Wrapped = new GZipStream(os, CompressionMode.Compress);
 }