예제 #1
0
 private void reencode(string value)
 {
     if (ReplaceEndStringChar)
     {
         int _NeededBytes = DefaultEncoding.GetByteCount(value);
         if (_NeededBytes < _m_Size)
         {
             AppendEndStringChar = true;
         }
         else
         {
             value = value.Remove(value.Length - 1);
             AppendEndStringChar = true;
         }
     }
     if (AppendEndStringChar)
     {
         value = value + (char)0x00;
     }
     _m_name = new byte[_m_Size];
     byte[] data = DefaultEncoding.GetBytes(value);
     if (data.Length > _m_Size)
     {
         Buffer.BlockCopy(data, 0, _m_name, 0, _m_Size);
         return;
     }
     Buffer.BlockCopy(data, 0, _m_name, 0, data.Length);
 }
        /// <summary>
        /// Calcula o tamanho do parametro.
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private long ComputeParameterLength(MultipartFormDataParameter parameter)
        {
            var  letterLenght   = DefaultEncoding.GetByteCount("&");
            var  boundrayLenght = DefaultEncoding.GetByteCount(_boundary);
            long length         = 0;

            return(DefaultEncoding.GetByteCount("--") + boundrayLenght + (letterLenght * 2) + DefaultEncoding.GetByteCount(string.Format("Content-Type: {0}", parameter.ContentType)) + (letterLenght * 2) + DefaultEncoding.GetByteCount("Content-Disposition: form-data; name=\"") + DefaultEncoding.GetByteCount(HttpUtility.UrlEncode(parameter.Name) ?? "") + letterLenght + (parameter is IFileMultipartFormDataParameter ? string.Format("; filename=\"{0}\"", (((IFileMultipartFormDataParameter)parameter).FileName)).Length : 0) + (letterLenght * 2) + (letterLenght * 2) + (parameter.TryComputeLength(out length) ? length : 0) + (letterLenght * 2));
        }
예제 #3
0
            /// <summary>
            /// Gets the size of the table info.
            /// </summary>
            /// <returns>Size of the table info.</returns>
            public int GetInfoSize()
            {
                int size = 1;   // End node type

                foreach (ElementInfo info in this.files)
                {
                    size += 1;  // Node type
                    size += DefaultEncoding.GetByteCount(info.Name);
                }

                foreach (ElementInfo info in this.folders)
                {
                    size += 3;  // Node type + folder ID
                    size += DefaultEncoding.GetByteCount(info.Name);
                }

                return(size);
            }
예제 #4
0
            public void Write(DataStream str, long baseOffset)
            {
                DataWriter bw = new DataWriter(str);

                // Go to offset if we can. Maybe we are writing in a position
                // that it doesn't exist still (it will write written later)
                // so in this case we fill it with zeros
                long tableOffset = baseOffset + this.Offset;

                if (tableOffset > str.Length)
                {
                    str.WriteTimes(0, tableOffset - str.Length);
                }

                // And finally seek there
                str.Seek(baseOffset + this.Offset, SeekMode.Origin);

                byte nodeType;

                // Write file info
                foreach (ElementInfo info in this.Files)
                {
                    nodeType = (byte)DefaultEncoding.GetByteCount(info.Name);                     // Name length
                    bw.Write(nodeType);
                    bw.Write(DefaultEncoding.GetBytes(info.Name));
                }

                // Write folder info
                foreach (ElementInfo info in this.Folders)
                {
                    nodeType = (byte)(0x80 | DefaultEncoding.GetByteCount(info.Name));
                    bw.Write(nodeType);
                    bw.Write(DefaultEncoding.GetBytes(info.Name));
                    bw.Write(info.Id);
                }

                bw.Write((byte)0x00);                   // End of info
                bw = null;
            }