Esempio n. 1
0
 /// <exception cref="System.IO.IOException"></exception>
 private void Digest(TemporaryBuffer.Heap buf)
 {
     MessageDigest md = Constants.NewMessageDigest();
     md.Update(buf.ToByteArray());
     buf.Write(md.Digest());
 }
Esempio n. 2
0
 // max obj size
 /// <exception cref="System.IO.IOException"></exception>
 private void PackHeader(TemporaryBuffer.Heap tinyPack, int cnt)
 {
     byte[] hdr = new byte[8];
     NB.EncodeInt32(hdr, 0, 2);
     NB.EncodeInt32(hdr, 4, cnt);
     tinyPack.Write(Constants.PACK_SIGNATURE);
     tinyPack.Write(hdr, 0, 8);
 }
Esempio n. 3
0
 public BlockInputStream(TemporaryBuffer _enclosing)
 {
     this._enclosing = _enclosing;
     this.block      = this._enclosing.blocks[this.blockIndex];
 }
Esempio n. 4
0
 /// <exception cref="System.IO.IOException"></exception>
 private void Deflate(TemporaryBuffer.Heap tinyPack, byte[] content)
 {
     Deflater deflater = new Deflater();
     byte[] buf = new byte[128];
     deflater.SetInput(content, 0, content.Length);
     deflater.Finish();
     do
     {
         int n = deflater.Deflate(buf, 0, buf.Length);
         if (n > 0)
         {
             tinyPack.Write(buf, 0, n);
         }
     }
     while (!deflater.IsFinished);
 }
Esempio n. 5
0
 /// <exception cref="System.IO.IOException"></exception>
 private void ObjectHeader(TemporaryBuffer.Heap pack, int type, int sz)
 {
     byte[] buf = new byte[8];
     int nextLength = (int)(((uint)sz) >> 4);
     buf[0] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked((int
         )(0x00))) | (type << 4) | (sz & unchecked((int)(0x0F)))));
     sz = nextLength;
     int n = 1;
     while (sz > 0)
     {
         nextLength = (int)(((uint)nextLength) >> 7);
         buf[n++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
             (int)(0x00))) | (sz & unchecked((int)(0x7F)))));
         sz = nextLength;
     }
     pack.Write(buf, 0, n);
 }
Esempio n. 6
0
 // We should drop the current source entry from the window,
 // it is somehow invalid for us to work with.
 private bool IsBetterDelta(DeltaWindowEntry src, TemporaryBuffer.Heap resDelta)
 {
     if (bestDelta == null)
     {
         return true;
     }
     // If both delta sequences are the same length, use the one
     // that has a shorter delta chain since it would be faster
     // to access during reads.
     //
     if (resDelta.Length() == bestDelta.Length())
     {
         return src.Depth() < window[bestSlot].Depth();
     }
     return resDelta.Length() < bestDelta.Length();
 }
		/// <exception cref="System.IO.IOException"></exception>
		private static PacketLineIn AsPacketLineIn(TemporaryBuffer.Heap buf)
		{
			return new PacketLineIn(new ByteArrayInputStream(buf.ToByteArray()));
		}
Esempio n. 8
0
 private string[] ExtractFileLines(Encoding[] csGuess)
 {
     TemporaryBuffer[] tmp = new TemporaryBuffer[GetParentCount() + 1];
     try
     {
         for (int i = 0; i < tmp.Length; i++)
         {
             tmp[i] = new TemporaryBuffer.LocalFile();
         }
         foreach (HunkHeader h in GetHunks())
         {
             h.ExtractFileLines(tmp);
         }
         string[] r = new string[tmp.Length];
         for (int i_1 = 0; i_1 < tmp.Length; i_1++)
         {
             Encoding cs = csGuess != null ? csGuess[i_1] : null;
             if (cs == null)
             {
                 cs = Constants.CHARSET;
             }
             r[i_1] = RawParseUtils.Decode(cs, tmp[i_1].ToByteArray());
         }
         return r;
     }
     catch (IOException ioe)
     {
         throw new RuntimeException(JGitText.Get().cannotConvertScriptToText, ioe);
     }
     finally
     {
         foreach (TemporaryBuffer b in tmp)
         {
             if (b != null)
             {
                 b.Destroy();
             }
         }
     }
 }
		/// <exception cref="System.IO.IOException"></exception>
		private void OpenPack(TemporaryBuffer.Heap buf)
		{
			if (inserter == null)
			{
				inserter = src.NewObjectInserter();
			}
			byte[] raw = buf.ToByteArray();
			PackParser p = inserter.NewPackParser(new ByteArrayInputStream(raw));
			p.SetAllowThin(true);
			p.Parse(PM);
		}
		/// <exception cref="System.IO.IOException"></exception>
		private void Copy(TemporaryBuffer.Heap tinyPack, ObjectLoader ldr)
		{
			byte[] buf = new byte[64];
			byte[] content = ldr.GetCachedBytes();
			int dataLength = content.Length;
			int nextLength = (int)(((uint)dataLength) >> 4);
			int size = 0;
			buf[size++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
				(int)(0x00))) | (ldr.GetType() << 4) | (dataLength & unchecked((int)(0x0F)))));
			dataLength = nextLength;
			while (dataLength > 0)
			{
				nextLength = (int)(((uint)nextLength) >> 7);
				buf[size++] = unchecked((byte)((nextLength > 0 ? unchecked((int)(0x80)) : unchecked(
					(int)(0x00))) | (dataLength & unchecked((int)(0x7F)))));
				dataLength = nextLength;
			}
			tinyPack.Write(buf, 0, size);
			Deflate(tinyPack, content);
		}
		/// <exception cref="System.IO.IOException"></exception>
		private void Receive(ReceivePack rp, TemporaryBuffer.Heap inBuf, TemporaryBuffer.Heap
			 outBuf)
		{
			rp.Receive(new ByteArrayInputStream(inBuf.ToByteArray()), outBuf, null);
		}
Esempio n. 12
0
			public BlockInputStream(TemporaryBuffer _enclosing)
			{
				this._enclosing = _enclosing;
				this.block = this._enclosing.blocks[this.blockIndex];
			}
Esempio n. 13
0
		/// <exception cref="System.IO.IOException"></exception>
		private void PutImpl(string bucket, string key, byte[] csum, TemporaryBuffer buf, 
			ProgressMonitor monitor, string monitorTask)
		{
			if (monitor == null)
			{
				monitor = NullProgressMonitor.INSTANCE;
			}
			if (monitorTask == null)
			{
				monitorTask = MessageFormat.Format(JGitText.Get().progressMonUploading, key);
			}
			string md5str = Base64.EncodeBytes(csum);
			long len = buf.Length();
			string lenstr = len.ToString();
			for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++)
			{
				HttpURLConnection c = Open("PUT", bucket, key);
				c.SetRequestProperty("Content-Length", lenstr);
				c.SetRequestProperty("Content-MD5", md5str);
				c.SetRequestProperty(X_AMZ_ACL, acl);
				encryption.Request(c, X_AMZ_META);
				Authorize(c);
				c.SetDoOutput(true);
				c.SetFixedLengthStreamingMode((int)len);
				monitor.BeginTask(monitorTask, (int)(len / 1024));
				OutputStream os = c.GetOutputStream();
				try
				{
					buf.WriteTo(os, monitor);
				}
				finally
				{
					monitor.EndTask();
					os.Close();
				}
				switch (HttpSupport.Response(c))
				{
					case HttpURLConnection.HTTP_OK:
					{
						return;
					}

					case HttpURLConnection.HTTP_INTERNAL_ERROR:
					{
						continue;
						goto default;
					}

					default:
					{
						throw Error("Writing", key, c);
					}
				}
			}
			throw MaxAttempts("Writing", key);
		}