/// <summary>Write all object entries to the index stream.</summary> /// <remarks> /// Write all object entries to the index stream. /// <p> /// After writing the stream passed to the factory is flushed but remains /// open. Callers are always responsible for closing the output stream. /// </remarks> /// <param name="toStore"> /// sorted list of objects to store in the index. The caller must /// have previously sorted the list using /// <see cref="NGit.Transport.PackedObjectInfo">NGit.Transport.PackedObjectInfo</see> /// 's /// native /// <see cref="System.IComparable{T}">System.IComparable<T></see> /// implementation. /// </param> /// <param name="packDataChecksum"> /// checksum signature of the entire pack data content. This is /// traditionally the last 20 bytes of the pack file's own stream. /// </param> /// <exception cref="System.IO.IOException"> /// an error occurred while writing to the output stream, or this /// index format cannot store the object data supplied. /// </exception> public virtual void Write <_T0>(IList <_T0> toStore, byte[] packDataChecksum) where _T0 : PackedObjectInfo { entries = toStore.UpcastTo <_T0, PackedObjectInfo>(); packChecksum = packDataChecksum; WriteImpl(); @out.Flush(); }
/// <exception cref="System.IO.IOException"></exception> /// <exception cref="System.IO.FileNotFoundException"></exception> /// <exception cref="Sharpen.Error"></exception> private FilePath ToTemp(MessageDigest md, int type, long len, InputStream @is) { bool delete = true; FilePath tmp = NewTempFile(); try { FileOutputStream fOut = new FileOutputStream(tmp); try { OutputStream @out = fOut; if (config.GetFSyncObjectFiles()) { @out = Channels.NewOutputStream(fOut.GetChannel()); } DeflaterOutputStream cOut = Compress(@out); DigestOutputStream dOut = new DigestOutputStream(cOut, md); WriteHeader(dOut, type, len); byte[] buf = Buffer(); while (len > 0) { int n = @is.Read(buf, 0, (int)Math.Min(len, buf.Length)); if (n <= 0) { throw ShortInput(len); } dOut.Write(buf, 0, n); len -= n; } dOut.Flush(); cOut.Finish(); } finally { if (config.GetFSyncObjectFiles()) { fOut.GetChannel().Force(true); } fOut.Close(); } delete = false; return(tmp); } finally { if (delete) { FileUtils.Delete(tmp); } } }