예제 #1
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();
 }
예제 #2
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);
		}