wyUpdate.Common.WriteFiles.WriteString C# (CSharp) Method

WriteString() public static method

public static WriteString ( Stream fs, byte flag, string text ) : void
fs Stream
flag byte
text string
return void
        public static void WriteString(Stream fs, byte flag, string text)
        {
            if (text == null)
                text = String.Empty;//fill with an empty string

            //the string data to be written
            byte[] tempBytes = Encoding.UTF8.GetBytes(text);

            //write the flag (e.g. 0x01, 0xFF, etc.)
            fs.WriteByte(flag);

            //the byte-length of the string.
            fs.Write(BitConverter.GetBytes(tempBytes.Length), 0, 4);

            //write the string data
            fs.Write(tempBytes, 0, tempBytes.Length);
        }

Usage Example

Ejemplo n.º 1
0
 public byte[] GetByteArray()
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         WriteFiles.WriteInt(memoryStream, 1, (int)Action);
         WriteFiles.WriteInt(memoryStream, 2, (int)UpdateStep);
         for (int i = 0; i < ExtraData.Count; i++)
         {
             if (!string.IsNullOrEmpty(ExtraData[i]))
             {
                 if (ExtraDataIsRTF[i])
                 {
                     memoryStream.WriteByte(128);
                 }
                 WriteFiles.WriteString(memoryStream, 3, ExtraData[i]);
             }
         }
         if (ProcessID != 0)
         {
             WriteFiles.WriteInt(memoryStream, 4, ProcessID);
         }
         if (Progress > -1 && Progress <= 100)
         {
             WriteFiles.WriteInt(memoryStream, 5, Progress);
         }
         if (ResponseType != 0)
         {
             WriteFiles.WriteInt(memoryStream, 6, (int)ResponseType);
         }
         memoryStream.WriteByte(byte.MaxValue);
         return(memoryStream.ToArray());
     }
 }
All Usage Examples Of wyUpdate.Common.WriteFiles::WriteString