public override void Write(int b) { if (@on) { digest.Update((byte)b); } os.Write(b); }
/// <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(); }
/// <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](); } }
/// <exception cref="System.IO.IOException"></exception> internal virtual void Write(OutputStream os) { int len = IsExtended ? INFO_LEN_EXTENDED : INFO_LEN; int pathLen = path.Length; os.Write(info, infoOffset, len); os.Write(path, 0, pathLen); // Index records are padded out to the next 8 byte alignment // for historical reasons related to how C Git read the files. // int actLen = len + pathLen; int expLen = (actLen + 8) & ~7; if (actLen != expLen) { os.Write(nullpad, 0, expLen - actLen); } }
/// <exception cref="System.IO.IOException"></exception> public override void WriteTo(OutputStream @out) { @out.Write(data); }
/// <exception cref="NSch.SftpException"></exception> private void _get(string src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip) { //System.err.println("_get: "+src+", "+dst); byte[] srcb = Util.Str2byte(src, fEncoding); try { SendOPENR(srcb); ChannelHeader header = new ChannelHeader(this); header = Header(buf, header); int length = header.length; int type = header.type; Fill(buf, length); if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE) { throw new SftpException(SSH_FX_FAILURE, string.Empty); } if (type == SSH_FXP_STATUS) { int i = buf.GetInt(); ThrowStatusError(buf, i); } byte[] handle = buf.GetString(); // filename long offset = 0; if (mode == RESUME) { offset += skip; } int request_len = 0; while (true) { request_len = buf.buffer.Length - 13; if (server_version == 0) { request_len = 1024; } SendREAD(handle, offset, request_len); header = Header(buf, header); length = header.length; type = header.type; if (type == SSH_FXP_STATUS) { Fill(buf, length); int i = buf.GetInt(); if (i == SSH_FX_EOF) { goto loop_break; } ThrowStatusError(buf, i); } if (type != SSH_FXP_DATA) { goto loop_break; } buf.Rewind(); Fill(buf.buffer, 0, 4); length -= 4; int i_1 = buf.GetInt(); // length of data int foo = i_1; while (foo > 0) { int bar = foo; if (bar > buf.buffer.Length) { bar = buf.buffer.Length; } i_1 = io_in.Read(buf.buffer, 0, bar); if (i_1 < 0) { goto loop_break; } int data_len = i_1; dst.Write(buf.buffer, 0, data_len); offset += data_len; foo -= data_len; if (monitor != null) { if (!monitor.Count(data_len)) { while (foo > 0) { i_1 = io_in.Read(buf.buffer, 0, (buf.buffer.Length < foo ? buf.buffer.Length : foo )); if (i_1 <= 0) { break; } foo -= i_1; } goto loop_break; } } } loop_continue: ; } loop_break: ; //System.err.println("length: "+length); // length should be 0 dst.Flush(); if (monitor != null) { monitor.End(); } _sendCLOSE(handle, header); } catch (Exception e) { if (e is SftpException) { throw (SftpException)e; } if (e is Exception) { throw new SftpException(SSH_FX_FAILURE, string.Empty, (Exception)e); } throw new SftpException(SSH_FX_FAILURE, string.Empty); } }
/// <exception cref="System.IO.IOException"></exception> internal virtual void Dump(OutputStream @out) { try { HostKey hk; lock (pool) { for (int i = 0; i < pool.Count; i++) { hk = (HostKey)(pool[i]); //hk.dump(out); string host = hk.GetHost(); string type = hk.GetType(); if (type.Equals("UNKNOWN")) { @out.Write(Util.Str2byte(host)); @out.Write(cr); continue; } @out.Write(Util.Str2byte(host)); @out.Write(space); @out.Write(Util.Str2byte(type)); @out.Write(space); @out.Write(Util.Str2byte(hk.GetKey())); @out.Write(cr); } } } catch (Exception e) { System.Console.Error.WriteLine(e); } }
/// <exception cref="System.IO.IOException"></exception> public override void WriteTo(OutputStream os, ProgressMonitor pm) { if (onDiskFile == null) { base.WriteTo(os, pm); return; } if (pm == null) { pm = NullProgressMonitor.INSTANCE; } FileInputStream @in = new FileInputStream(onDiskFile); try { int cnt; byte[] buf = new byte[TemporaryBuffer.Block.SZ]; while ((cnt = @in.Read(buf)) >= 0) { os.Write(buf, 0, cnt); pm.Update(cnt / 1024); } } finally { @in.Close(); } }
/// <summary>Send this buffer to an output stream.</summary> /// <remarks> /// Send this buffer to an output stream. /// <p> /// This method may only be invoked after /// <see cref="Close()">Close()</see> /// has completed /// normally, to ensure all data is completely transferred. /// </remarks> /// <param name="os">stream to send this buffer's complete content to.</param> /// <param name="pm"> /// if not null progress updates are sent here. Caller should /// initialize the task and the number of work units to <code> /// <see cref="Length()">Length()</see> /// /1024</code>. /// </param> /// <exception cref="System.IO.IOException"> /// an error occurred reading from a temporary file on the local /// system, or writing to the output stream. /// </exception> public virtual void WriteTo(OutputStream os, ProgressMonitor pm) { if (pm == null) { pm = NullProgressMonitor.INSTANCE; } foreach (TemporaryBuffer.Block b in blocks) { os.Write(b.buffer, 0, b.count); pm.Update(b.count / 1024); } }
/// <exception cref="System.IO.IOException"></exception> private static void WriteBytes(ByteArrayBuffer b, OutputStream @out) { @out.Write(b.Buffer(), 0, b.Length()); }
/// <summary>Copy this mode as a sequence of octal US-ASCII bytes.</summary> /// <remarks> /// Copy this mode as a sequence of octal US-ASCII bytes. /// <p/> /// The mode is copied as a sequence of octal digits using the US-ASCII /// character encoding. The sequence does not use a leading '0' prefix to /// indicate octal notation. This method is suitable for generation of a mode /// string within a GIT tree object. /// </p> /// </remarks> /// <param name="os">stream to copy the mode to.</param> /// <exception cref="System.IO.IOException">the stream encountered an error during the copy. /// </exception> public virtual void CopyTo(OutputStream os) { os.Write(octalBytes); }
/// <exception cref="System.IO.IOException"></exception> private static void WriteRawInt(OutputStream w, int v) { w.Write((int)(((uint)v) >> 24)); w.Write((int)(((uint)v) >> 16)); w.Write((int)(((uint)v) >> 8)); w.Write(v); }
/// <summary>Copy this ObjectId to an output writer in hex format.</summary> /// <remarks>Copy this ObjectId to an output writer in hex format.</remarks> /// <param name="w">the stream to copy to.</param> /// <exception cref="System.IO.IOException">the stream writing failed.</exception> public virtual void CopyTo(OutputStream w) { w.Write(ToHexByteArray()); }
/// <summary>Copy this object to the output stream.</summary> /// <remarks> /// Copy this object to the output stream. /// <p/> /// For some object store implementations, this method may be more efficient /// than reading from /// <see cref="OpenStream()">OpenStream()</see> /// into a temporary byte array, then /// writing to the destination stream. /// <p/> /// The default implementation of this method is to copy with a temporary /// byte array for large objects, or to pass through the cached byte array /// for small objects. /// </remarks> /// <param name="out"> /// stream to receive the complete copy of this object's data. /// Caller is responsible for flushing or closing this stream /// after this method returns. /// </param> /// <exception cref="NGit.Errors.MissingObjectException">the object no longer exists. /// </exception> /// <exception cref="System.IO.IOException"> /// the object store cannot be accessed, or the stream cannot be /// written to. /// </exception> public virtual void CopyTo(OutputStream @out) { if (IsLarge()) { ObjectStream @in = OpenStream(); try { long sz = @in.GetSize(); byte[] tmp = new byte[8192]; long copied = 0; while (copied < sz) { int n = @in.Read(tmp); if (n < 0) { throw new EOFException(); } @out.Write(tmp, 0, n); copied += n; } if (0 <= @in.Read()) { throw new EOFException(); } } finally { @in.Close(); } } else { @out.Write(GetCachedBytes()); } }
/// <exception cref="System.IO.IOException"></exception> internal virtual void WriteHeader(OutputStream @out, int type, long len) { @out.Write(Constants.EncodedTypeString(type)); @out.Write(unchecked((byte)' ')); @out.Write(Constants.EncodeASCII(len)); @out.Write(unchecked((byte)0)); }
/// <exception cref="NSch.SftpException"></exception> private void _get(string src, OutputStream dst, SftpProgressMonitor monitor, int mode, long skip) { //System.err.println("_get: "+src+", "+dst); byte[] srcb = Util.Str2byte(src, fEncoding); try { SendOPENR(srcb); ChannelHeader header = new ChannelHeader(this); header = Header(buf, header); int length = header.length; int type = header.type; Fill(buf, length); if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE) { throw new SftpException(SSH_FX_FAILURE, string.Empty); } if (type == SSH_FXP_STATUS) { int i = buf.GetInt(); ThrowStatusError(buf, i); } byte[] handle = buf.GetString(); // filename long offset = 0; if (mode == RESUME) { offset += skip; } int request_max = 1; rq.Init(); long request_offset = offset; int request_len = buf.buffer.Length - 13; if (server_version == 0) { request_len = 1024; } while (true) { while (rq.Count() < request_max) { SendREAD(handle, request_offset, request_len, rq); request_offset += request_len; } header = Header(buf, header); length = header.length; type = header.type; ChannelSftp.RequestQueue.Request rr = rq.Get(header.rid); if (type == SSH_FXP_STATUS) { Fill(buf, length); int i = buf.GetInt(); if (i == SSH_FX_EOF) { goto loop_break; } ThrowStatusError(buf, i); } if (type != SSH_FXP_DATA) { goto loop_break; } buf.Rewind(); Fill(buf.buffer, 0, 4); length -= 4; int length_of_data = buf.GetInt(); // length of data int optional_data = length - length_of_data; int foo = length_of_data; while (foo > 0) { int bar = foo; if (bar > buf.buffer.Length) { bar = buf.buffer.Length; } int data_len = io_in.Read(buf.buffer, 0, bar); if (data_len < 0) { goto loop_break; } dst.Write(buf.buffer, 0, data_len); offset += data_len; foo -= data_len; if (monitor != null) { if (!monitor.Count(data_len)) { Skip(foo); if (optional_data > 0) { Skip(optional_data); } goto loop_break; } } } //System.err.println("length: "+length); // length should be 0 if (optional_data > 0) { Skip(optional_data); } if (length_of_data < rr.length) { // rq.Cancel(header, buf); SendREAD(handle, rr.offset + length_of_data, (int)(rr.length - length_of_data), rq ); request_offset = rr.offset + rr.length; } if (request_max < rq.Size()) { request_max++; } loop_continue: ; } loop_break: ; dst.Flush(); if (monitor != null) { monitor.End(); } rq.Cancel(header, buf); _sendCLOSE(handle, header); } catch (Exception e) { if (e is SftpException) { throw (SftpException)e; } if (e is Exception) { throw new SftpException(SSH_FX_FAILURE, string.Empty, (Exception)e); } throw new SftpException(SSH_FX_FAILURE, string.Empty); } }
/// <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 "<<<<<<< " or ">>>>>>> " /// 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)); } }
public virtual void WritePrivateKey(OutputStream @out) { byte[] plain = GetPrivateKey(); byte[][] _iv = new byte[1][]; byte[] encoded = Encrypt(plain, _iv); if (encoded != plain) { Util.Bzero(plain); } byte[] iv = _iv[0]; byte[] prv = Util.ToBase64(encoded, 0, encoded.Length); try { @out.Write(GetBegin()); @out.Write(cr); if (passphrase != null) { @out.Write(header[0]); @out.Write(cr); @out.Write(header[1]); for (int i = 0; i < iv.Length; i++) { @out.Write(B2a(unchecked((byte)((iv[i] >> 4) & unchecked((int)(0x0f)))))); @out.Write(B2a(unchecked((byte)(iv[i] & unchecked((int)(0x0f)))))); } @out.Write(cr); @out.Write(cr); } int i_1 = 0; while (i_1 < prv.Length) { if (i_1 + 64 < prv.Length) { @out.Write(prv, i_1, 64); @out.Write(cr); i_1 += 64; continue; } @out.Write(prv, i_1, prv.Length - i_1); @out.Write(cr); break; } @out.Write(GetEnd()); @out.Write(cr); } catch (Exception) { } }
/// <exception cref="System.IO.IOException"></exception> private void SwitchToOverflow() { overflow = Overflow(); TemporaryBuffer.Block last = blocks.Remove(blocks.Count - 1); foreach (TemporaryBuffer.Block b in blocks) { overflow.Write(b.buffer, 0, b.count); } blocks = null; overflow = new BufferedOutputStream(overflow, TemporaryBuffer.Block.SZ); overflow.Write(last.buffer, 0, last.count); }
public virtual void WritePublicKey(OutputStream @out, string comment) { byte[] pubblob = GetPublicKeyBlob(); byte[] pub = Util.ToBase64(pubblob, 0, pubblob.Length); try { @out.Write(GetKeyTypeName()); @out.Write(space); @out.Write(pub, 0, pub.Length); @out.Write(space); @out.Write(Util.Str2byte(comment)); @out.Write(cr); } catch (Exception) { } }
/// <exception cref="System.IO.IOException"></exception> public override void WriteTo(OutputStream @out) { if (@out == null) { throw new ArgumentException("Output stream may not be null"); } InputStream @in = new ByteArrayInputStream(this.content); byte[] tmp = new byte[4096]; int l; while ((l = @in.Read(tmp)) != -1) { @out.Write(tmp, 0, l); } @out.Flush(); }
public virtual void WriteSECSHPublicKey(OutputStream @out, string comment) { byte[] pubblob = GetPublicKeyBlob(); byte[] pub = Util.ToBase64(pubblob, 0, pubblob.Length); try { @out.Write(Util.Str2byte("---- BEGIN SSH2 PUBLIC KEY ----")); @out.Write(cr); @out.Write(Util.Str2byte("Comment: \"" + comment + "\"")); @out.Write(cr); int index = 0; while (index < pub.Length) { int len = 70; if ((pub.Length - index) < len) { len = pub.Length - index; } @out.Write(pub, index, len); @out.Write(cr); index += len; } @out.Write(Util.Str2byte("---- END SSH2 PUBLIC KEY ----")); @out.Write(cr); } catch (Exception) { } }
/// <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); }
/// <exception cref="System.IO.IOException"></exception> internal void Write(OutputStream @out, long pos, int cnt) { @out.Write(array, (int)(pos - start), cnt); }