Ejemplo n.º 1
0
		/// <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;
			}
		}
Ejemplo n.º 2
0
		/// <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()));
				}
			}
		}