コード例 #1
0
ファイル: PackFileTest.cs プロジェクト: ststeiger/ngit-core
        public virtual void TestWhole_SmallObject()
        {
            int type = Constants.OBJ_BLOB;

            byte[]  data = GetRng().NextBytes(300);
            RevBlob id   = tr.Blob(data);

            tr.Branch("master").Commit().Add("A", id).Create();
            tr.PackAndPrune();
            NUnit.Framework.Assert.IsTrue(wc.Has(id), "has blob");
            ObjectLoader ol = wc.Open(id);

            NUnit.Framework.Assert.IsNotNull(ol, "created loader");
            NUnit.Framework.Assert.AreEqual(type, ol.GetType());
            NUnit.Framework.Assert.AreEqual(data.Length, ol.GetSize());
            NUnit.Framework.Assert.IsFalse(ol.IsLarge(), "is not large");
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(data, ol.GetCachedBytes()), "same content"
                                          );
            ObjectStream @in = ol.OpenStream();

            NUnit.Framework.Assert.IsNotNull(@in, "have stream");
            NUnit.Framework.Assert.AreEqual(type, @in.GetType());
            NUnit.Framework.Assert.AreEqual(data.Length, @in.GetSize());
            byte[] data2 = new byte[data.Length];
            IOUtil.ReadFully(@in, data2, 0, data.Length);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(data2, data), "same content");
            NUnit.Framework.Assert.AreEqual(-1, @in.Read(), "stream at EOF");
            @in.Close();
        }
コード例 #2
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override ObjectStream OpenStream()
        {
            WindowCursor wc = new WindowCursor(db);
            InputStream  @in;

            try
            {
                @in = new PackInputStream(pack, objectOffset + headerLength, wc);
            }
            catch (IOException)
            {
                // If the pack file cannot be pinned into the cursor, it
                // probably was repacked recently. Go find the object
                // again and open the stream from that location instead.
                //
                return(wc.Open(GetObjectId(), type).OpenStream());
            }
            @in = new BufferedInputStream(new InflaterInputStream(@in, wc.Inflater(), 8192),
                                          8192);
            //
            //
            //
            //
            //
            return(new ObjectStream.Filter(type, size, @in));
        }
コード例 #3
0
 public override int GetType()
 {
     if (type == Constants.OBJ_BAD)
     {
         WindowCursor wc = new WindowCursor(db);
         try
         {
             type = pack.GetObjectType(wc, objectOffset);
         }
         catch (IOException)
         {
             // If the pack file cannot be pinned into the cursor, it
             // probably was repacked recently. Go find the object
             // again and get the type from that location instead.
             //
             try
             {
                 type = wc.Open(GetObjectId()).GetType();
             }
             catch (IOException)
             {
             }
         }
         finally
         {
             // "He's dead, Jim." We just can't discover the type
             // and the interface isn't supposed to be lazy here.
             // Report an invalid type code instead, callers will
             // wind up bailing out with an error at some point.
             wc.Release();
         }
     }
     return(type);
 }
コード例 #4
0
 public override long GetSize()
 {
     if (size == SIZE_UNKNOWN)
     {
         WindowCursor wc = new WindowCursor(db);
         try
         {
             byte[] b = pack.GetDeltaHeader(wc, objectOffset + headerLength);
             size = BinaryDelta.GetResultSize(b);
         }
         catch (SharpZipBaseException)
         {
         }
         catch (IOException)
         {
             // The zlib stream for the delta is corrupt. We probably
             // cannot access the object. Keep the size negative and
             // report that bogus result to the caller.
             // If the pack file cannot be pinned into the cursor, it
             // probably was repacked recently. Go find the object
             // again and get the size from that location instead.
             //
             try
             {
                 size = wc.Open(GetObjectId()).GetSize();
             }
             catch (IOException)
             {
             }
         }
         finally
         {
             // "He's dead, Jim." We just can't discover the size
             // and the interface isn't supposed to be lazy here.
             // Report an invalid type code instead, callers will
             // wind up bailing out with an error at some point.
             wc.Release();
         }
     }
     return(size);
 }
コード例 #5
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        private InputStream Open(WindowCursor wc)
        {
            InputStream delta;

            try
            {
                delta = new PackInputStream(pack, objectOffset + headerLength, wc);
            }
            catch (IOException)
            {
                // If the pack file cannot be pinned into the cursor, it
                // probably was repacked recently. Go find the object
                // again and open the stream from that location instead.
                //
                return(wc.Open(GetObjectId()).OpenStream());
            }
            delta = new InflaterInputStream(delta);
            ObjectLoader @base = pack.Load(wc, baseOffset);
            DeltaStream  ds    = new _DeltaStream_223(@base, wc, delta);

            // This code path should never be used as DeltaStream
            // is supposed to open the stream first, which would
            // initialize the size for us directly from the stream.
            if (type == Constants.OBJ_BAD)
            {
                if (!(@base is NGit.Storage.File.LargePackedDeltaObject))
                {
                    type = @base.GetType();
                }
            }
            if (size == SIZE_UNKNOWN)
            {
                size = ds.GetSize();
            }
            return(ds);
        }
コード例 #6
0
		public override int GetType()
		{
			if (type == Constants.OBJ_BAD)
			{
				WindowCursor wc = new WindowCursor(db);
				try
				{
					type = pack.GetObjectType(wc, objectOffset);
				}
				catch (IOException)
				{
					// If the pack file cannot be pinned into the cursor, it
					// probably was repacked recently. Go find the object
					// again and get the type from that location instead.
					//
					try
					{
						type = wc.Open(GetObjectId()).GetType();
					}
					catch (IOException)
					{
					}
				}
				finally
				{
					// "He's dead, Jim." We just can't discover the type
					// and the interface isn't supposed to be lazy here.
					// Report an invalid type code instead, callers will
					// wind up bailing out with an error at some point.
					wc.Release();
				}
			}
			return type;
		}
コード例 #7
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		private InputStream Open(WindowCursor wc)
		{
			InputStream delta;
			try
			{
				delta = new PackInputStream(pack, objectOffset + headerLength, wc);
			}
			catch (IOException)
			{
				// If the pack file cannot be pinned into the cursor, it
				// probably was repacked recently. Go find the object
				// again and open the stream from that location instead.
				//
				return wc.Open(GetObjectId()).OpenStream();
			}
			delta = new InflaterInputStream(delta);
			ObjectLoader @base = pack.Load(wc, baseOffset);
			DeltaStream ds = new _DeltaStream_223(@base, wc, delta);
			// This code path should never be used as DeltaStream
			// is supposed to open the stream first, which would
			// initialize the size for us directly from the stream.
			if (type == Constants.OBJ_BAD)
			{
				if (!(@base is NGit.Storage.File.LargePackedDeltaObject))
				{
					type = @base.GetType();
				}
			}
			if (size == SIZE_UNKNOWN)
			{
				size = ds.GetSize();
			}
			return ds;
		}
コード例 #8
0
		public override long GetSize()
		{
			if (size == SIZE_UNKNOWN)
			{
				WindowCursor wc = new WindowCursor(db);
				try
				{
					byte[] b = pack.GetDeltaHeader(wc, objectOffset + headerLength);
					size = BinaryDelta.GetResultSize(b);
				}
				catch (SharpZipBaseException)
				{
				}
				catch (IOException)
				{
					// The zlib stream for the delta is corrupt. We probably
					// cannot access the object. Keep the size negative and
					// report that bogus result to the caller.
					// If the pack file cannot be pinned into the cursor, it
					// probably was repacked recently. Go find the object
					// again and get the size from that location instead.
					//
					try
					{
						size = wc.Open(GetObjectId()).GetSize();
					}
					catch (IOException)
					{
					}
				}
				finally
				{
					// "He's dead, Jim." We just can't discover the size
					// and the interface isn't supposed to be lazy here.
					// Report an invalid type code instead, callers will
					// wind up bailing out with an error at some point.
					wc.Release();
				}
			}
			return size;
		}
コード例 #9
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		public override ObjectStream OpenStream()
		{
			WindowCursor wc = new WindowCursor(db);
			InputStream @in;
			try
			{
				@in = new PackInputStream(pack, objectOffset + headerLength, wc);
			}
			catch (IOException)
			{
				// If the pack file cannot be pinned into the cursor, it
				// probably was repacked recently. Go find the object
				// again and open the stream from that location instead.
				//
				return wc.Open(GetObjectId(), type).OpenStream();
			}
			@in = new BufferedInputStream(new InflaterInputStream(@in, wc.Inflater(), 8192), 
				8192);
			//
			//
			//
			//
			//
			return new ObjectStream.Filter(type, size, @in);
		}