encodeASCII() 공개 정적인 메소드

Convert an integer into its decimal representation.
public static encodeASCII ( long s ) : byte[]
s long the integer to convert.
리턴 byte[]
예제 #1
0
 ///	<summary>
 /// Convert an ObjectId from raw binary representation.
 /// </summary>
 /// <param name="str">
 /// The raw byte buffer to read from. At least 20 bytes must be
 /// available within this byte array.
 /// </param>
 /// <returns> the converted object id. </returns>
 public static ObjectId FromString(string str)
 {
     if (str.Length != Constants.OBJECT_ID_STRING_LENGTH)
     {
         throw new ArgumentException("Invalid id: " + str, "str");
     }
     return(FromHexString(Constants.encodeASCII(str), 0));
 }
예제 #2
0
        public void FromString(string str)
        {
            if (str.Length != StringLength)
            {
                throw new ArgumentException("Invalid id: " + str, "str");
            }

            FromHexString(Constants.encodeASCII(str), 0);
        }
예제 #3
0
        /// <summary>
        /// Convert an AbbreviatedObjectId from hex characters.
        /// </summary>
        /// <param name="str">
        /// the string to read from. Must be &lt;= 40 characters.
        /// </param>
        /// <returns>the converted object id.</returns>
        public static AbbreviatedObjectId FromString(string str)
        {
            if (str.Length > AnyObjectId.StringLength)
            {
                throw new ArgumentException("Invalid id: " + str);
            }

            byte[] b = Constants.encodeASCII(str);
            return(FromHexString(b, 0, b.Length));
        }
        /// <summary>
        /// Convert an AbbreviatedObjectId from hex characters.
        /// </summary>
        /// <param name="str">
        /// the string to read from. Must be &lt;= 40 characters.
        /// </param>
        /// <returns>the converted object id.</returns>
        public static AbbreviatedObjectId FromString(string str)
        {
            if (str == null)
            {
                throw new ArgumentNullException("str");
            }
            if (str.Length > Constants.OBJECT_ID_STRING_LENGTH)
            {
                throw new ArgumentException("Invalid id: " + str);
            }

            byte[] b = Constants.encodeASCII(str);
            return(FromHexString(b, 0, b.Length));
        }
예제 #5
0
        ///	<summary>
        /// Write a Commit to the object database
        ///	</summary>
        ///	<param name="c">Commit to store.</param>
        ///	<returns>SHA-1 of the commit.</returns>
        ///	<exception cref="IOException"></exception>
        public ObjectId WriteCommit(Commit c)
        {
            Encoding encoding = c.Encoding ?? Constants.CHARSET;
            var      output   = new MemoryStream();
            var      s        = new BinaryWriter(output, encoding);

            s.Write(HTree);
            s.Write(' ');
            c.TreeId.CopyTo(s);
            s.Write('\n');
            ObjectId[] parentIds = c.ParentIds;
            for (int i = 0; i < parentIds.Length; i++)
            {
                s.Write(HParent);
                s.Write(' ');
                parentIds[i].CopyTo(s);
                s.Write('\n');
            }
            s.Write(HAuthor);
            s.Write(' ');
            s.Write(c.Author.ToExternalString().ToCharArray());
            s.Write('\n');
            s.Write(HCommitter);
            s.Write(' ');
            s.Write(c.Committer.ToExternalString().ToCharArray());
            s.Write('\n');

            if (encoding != Constants.CHARSET)
            {
                s.Write(HEncoding);
                s.Write(' ');
                s.Write(Constants.encodeASCII(encoding.HeaderName.ToUpperInvariant()));
                s.Write('\n');
            }

            s.Write('\n');
            s.Write(c.Message.ToCharArray());

            return(WriteCommit(output.ToArray()));
        }
예제 #6
0
        internal ObjectId WriteObject(ObjectType type, long len, Stream input, bool store)
        {
            FileInfo             info;
            DeflaterOutputStream stream;
            FileStream           stream2;
            ObjectId             objectId = null;

            if (store)
            {
                info    = _r.ObjectsDirectory.CreateTempFile("noz");
                stream2 = info.OpenWrite();
            }
            else
            {
                info    = null;
                stream2 = null;
            }

            _md.Reset();
            if (store)
            {
                _def.Reset();
                stream = new DeflaterOutputStream(stream2, _def);
            }
            else
            {
                stream = null;
            }

            try
            {
                int    num;
                byte[] bytes = Codec.EncodedTypeString(type);
                _md.Update(bytes);
                if (stream != null)
                {
                    stream.Write(bytes, 0, bytes.Length);
                }

                _md.Update(0x20);
                if (stream != null)
                {
                    stream.WriteByte(0x20);
                }

                bytes = Constants.encodeASCII(len.ToString());
                _md.Update(bytes);
                if (stream != null)
                {
                    stream.Write(bytes, 0, bytes.Length);
                }

                _md.Update(0);
                if (stream != null)
                {
                    stream.WriteByte(0);
                }
                while ((len > 0L) && ((num = input.Read(_buf, 0, (int)Math.Min(len, _buf.Length))) > 0))
                {
                    _md.Update(_buf, 0, num);
                    if (stream != null)
                    {
                        stream.Write(_buf, 0, num);
                    }
                    len -= num;
                }

                if (len != 0L)
                {
                    throw new IOException("Input did not match supplied Length. " + len + " bytes are missing.");
                }

                if (stream != null)
                {
                    stream.Close();
                    if (info != null)
                    {
                        info.IsReadOnly = true;
                    }
                }
                objectId = ObjectId.FromRaw(_md.Digest());
            }
            finally
            {
                if ((objectId == null) && (stream != null))
                {
                    try
                    {
                        stream.Close();
                    }
                    finally
                    {
                        info.DeleteFile();
                    }
                }
            }
            if (info != null)
            {
                if (_r.HasObject(objectId))
                {
                    // Object is already in the repository so remove
                    // the temporary file.
                    //
                    info.DeleteFile();
                }
                else
                {
                    FileInfo info2 = _r.ToFile(objectId);
                    if (!info.RenameTo(info2.FullName))
                    {
                        // Maybe the directory doesn't exist yet as the object
                        // directories are always lazily created. Note that we
                        // try the rename first as the directory likely does exist.
                        //
                        if (info2.Directory != null)
                        {
                            info2.Directory.Create();
                        }
                        if (!info.RenameTo(info2.FullName) && !_r.HasObject(objectId))
                        {
                            // The object failed to be renamed into its proper
                            // location and it doesn't exist in the repository
                            // either. We really don't know what went wrong, so
                            // fail.
                            //
                            info.DeleteFile();
                            throw new ObjectWritingException("Unable to create new object: " + info2);
                        }
                    }
                }
            }
            return(objectId);
        }