/// <exception cref="System.IO.IOException"></exception>
		internal override void Write(PackOutputStream @out, long pos, int cnt)
		{
			ByteBuffer s = buffer.Slice();
			s.Position((int)(pos - start));
			while (0 < cnt)
			{
				byte[] buf = @out.GetCopyBuffer();
				int n = Math.Min(cnt, buf.Length);
				s.Get(buf, 0, n);
				@out.Write(buf, 0, n);
				cnt -= n;
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		public void WriteObjects(PackOutputStream @out, Iterable<ObjectToPack> list)
		{
			foreach (ObjectToPack otp in list)
			{
				@out.WriteObject(otp);
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override void Write(PackOutputStream @out, long pos, int cnt, MessageDigest
			 digest)
		{
			int ptr = (int)(pos - start);
			@out.Write(array, ptr, cnt);
			if (digest != null)
			{
				digest.Update(array, ptr, cnt);
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal void CopyPackAsIs(PackFile pack, long length, bool validate, PackOutputStream
			 @out)
		{
			MessageDigest md = null;
			if (validate)
			{
				md = Constants.NewMessageDigest();
				byte[] buf = @out.GetCopyBuffer();
				Pin(pack, 0);
				if (window.Copy(0, buf, 0, 12) != 12)
				{
					pack.SetInvalid();
					throw new IOException(JGitText.Get().packfileIsTruncated);
				}
				md.Update(buf, 0, 12);
			}
			long position = 12;
			long remaining = length - (12 + 20);
			while (0 < remaining)
			{
				Pin(pack, position);
				int ptr = (int)(position - window.start);
				int n = (int)Math.Min(window.Size() - ptr, remaining);
				window.Write(@out, position, n, md);
				position += n;
				remaining -= n;
			}
			if (md != null)
			{
				byte[] buf = new byte[20];
				byte[] actHash = md.Digest();
				Pin(pack, position);
				if (window.Copy(position, buf, 0, 20) != 20)
				{
					pack.SetInvalid();
					throw new IOException(JGitText.Get().packfileIsTruncated);
				}
				if (!Arrays.Equals(actHash, buf))
				{
					pack.SetInvalid();
					throw new IOException(MessageFormat.Format(JGitText.Get().packfileCorruptionDetected
						, pack.GetPackFile().GetPath()));
				}
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Errors.StoredObjectRepresentationNotAvailableException"></exception>
		public void CopyObjectAsIs(PackOutputStream @out, ObjectToPack otp)
		{
			LocalObjectToPack src = (LocalObjectToPack)otp;
			src.pack.CopyAsIs(@out, src, this);
		}
Exemple #6
0
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract void Write(PackOutputStream @out, long pos, int cnt, MessageDigest
			 md);
		/// <exception cref="System.IO.IOException"></exception>
		public void CopyPackAsIs(PackOutputStream @out, CachedPack pack, bool validate)
		{
			((LocalCachedPack)pack).CopyAsIs(@out, validate, this);
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal override void Write(PackOutputStream @out, long pos, int cnt)
		{
			@out.Write(array, (int)(pos - start), cnt);
		}
Exemple #9
0
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual void CopyAsIs(PackOutputStream @out, bool validate, WindowCursor
			 wc)
		{
			foreach (PackFile pack in GetPacks())
			{
				pack.CopyPackAsIs(@out, validate, wc);
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal abstract void Write(PackOutputStream @out, long pos, int cnt);
		/// <exception cref="System.IO.IOException"></exception>
		internal void CopyPackAsIs(PackFile pack, PackOutputStream @out, long position, long
			 cnt)
		{
			while (0 < cnt)
			{
				Pin(pack, position);
				int ptr = (int)(position - window.start);
				int n = (int)Math.Min(window.Size() - ptr, cnt);
				window.Write(@out, position, n);
				position += n;
				cnt -= n;
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		public void CopyPackAsIs(PackOutputStream @out, CachedPack pack)
		{
			((LocalCachedPack)pack).CopyAsIs(@out, this);
		}