示例#1
0
        /// <summary>
        /// Read bytes in file stream from the current position
        /// </summary>
        /// <param name="count">The maximum number of bytes to read.</param>
        /// <returns>Contains the specified byte array.</returns>
        public byte[] ReadBytes(int count)
        {
            var b = new byte[count];

            SnipStream.Read(b, 0, count);
            return(b);
        }
示例#2
0
 /// <summary>
 /// Write UInt32 in file stream
 /// </summary>
 /// <param name="value">A UInt32 value.</param>
 public void WriteUInt32(UInt32 value)
 {
     if (SnipStream != null)
     {
         _bytes4 = Framework.TypeConverter.i2h(value);
         SnipStream.Write(_bytes4, 0, _bytes4.Length);
     }
 }
示例#3
0
 /// <summary>
 /// Writes an array of bytes in the file stream
 /// </summary>
 /// <param name="b">A byte array.</param>
 public void WriteBytesArrayInFileStream(byte[] b)
 {
     if (SnipStream == null)
     {
         return;
     }
     SnipStream.Write(b, 0, b.Length);
 }
示例#4
0
        /// <summary>
        /// Close the file stream
        /// </summary>
        public void CloseAndDisposeFileStream()
        {
            if (SnipStream != null)
            {
                SnipStream.Close();
                SnipStream.Dispose();
            }

            SnipStream = null;
        }
示例#5
0
 /// <summary>
 /// Writes the output buffer in the file stream
 /// </summary>
 public void WriteOutputBufferInFileStream()
 {
     if (SnipStream == null)
     {
         return;
     }
     if (OutputBufferLength <= 0)
     {
         return;
     }
     SnipStream.Write(OutputBuffer, 0, (int)OutputBufferLength);
 }
示例#6
0
        /// <summary>
        /// Writes a string in the file stream
        /// </summary>
        /// <param name="s">String to write</param>
        public void WriteStringInFileStream(string s)
        {
            if (SnipStream == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(s))
            {
                return;
            }
            var b = new byte[s.Length];

            for (int i = 0; i < s.Length; i++)
            {
                b[i] = (byte)s[i];
            }

            SnipStream.Write(b, 0, s.Length);
        }
示例#7
0
        /// <summary>
        /// Jump to position in stream from offset
        /// </summary>
        /// <param name="offset">Offset (can be negative or positive)</param>
        /// <param name="from">Reference points in stream</param>
        /// <exception cref="Exception">An exception if size or position error</exception>
        public void JumpTo(int offset, SeekOrigin from)
        {
            if (SnipStream != null)
            {
                long newPosition = SnipStream.Position;

                if (@from == SeekOrigin.Begin)
                {
                    newPosition = offset;
                }
                if (@from == SeekOrigin.Current)
                {
                    newPosition += offset;
                }
                if (@from == SeekOrigin.End)
                {
                    newPosition += offset;
                }

                if (newPosition > _streamSize)
                {
                    throw new Exception(
                              string.Format(
                                  format: TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "SnipStreamWrapper_JumpTo_GreaterSize"),
                                  arg0: newPosition.ToString(CultureInfo.InvariantCulture),
                                  arg1: _streamSize.ToString(CultureInfo.InvariantCulture)));
                }


                if (newPosition < 0)
                {
                    throw new Exception(
                              string.Format(
                                  format: TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "SnipStreamWrapper_JumpTo_PositionNegative"),
                                  arg0: newPosition.ToString(CultureInfo.InvariantCulture)));
                }

                SnipStream.Seek(offset, from);
            }
        }
示例#8
0
 /// <summary>
 /// Read UInt32 in file stream from the current position
 /// </summary>
 /// <returns>An UInt32 number</returns>
 public UInt32 ReadUInt32()
 {
     SnipStream.Read(_bytes4, 0, 4);
     return(BitConverter.ToUInt32(_bytes4, 0));
 }
示例#9
0
 /// <summary>
 /// Read UInt16 in file stream from the current position
 /// </summary>
 /// <returns>An UInt16 number</returns>
 public UInt16 ReadUInt16()
 {
     SnipStream.Read(_bytes2, 0, 2);
     return(BitConverter.ToUInt16(_bytes2, 0));
 }