Пример #1
0
        /// <summary>
        /// Decode base 64 data, unzip binary stream and retrieve each part
        /// </summary>
        /// <param name="base64data">Base 64 encoded data containing MMS message in ZIP file format</param>
        /// <returns></returns>
        private MMSMessage.MessagePartCollection GetParts(string base64data)
        {
            MMSMessage.MessagePartCollection coll = new MMSMessage.MessagePartCollection();

            MemoryStream ms = new MemoryStream(Convert.FromBase64String(base64data));

            // Extract files and add them
            ZipInputStream s = new ZipInputStream(ms);
            ZipEntry       theEntry;
            int            i = 0;

            while ((theEntry = s.GetNextEntry()) != null)
            {
                MMSMessagePart part = new MMSMessagePart();
                part.PartId = i;
                string fileName = theEntry.Name;

                if (fileName != String.Empty)
                {
                    part.Name = fileName;
                    //Read Part into memorystream
                    int          size     = 2048;
                    int          len      = 0;
                    MemoryStream mspart   = new MemoryStream(size);
                    byte[]       partData = new byte[size];
                    while (true)
                    {
                        size = s.Read(partData, 0, partData.Length);
                        len += size;
                        if (size > 0)
                        {
                            mspart.Write(partData, 0, size);
                        }
                        else
                        {
                            break;
                        }
                    }
                    part.Data       = new byte[len];
                    mspart.Position = 0;                     // Reset position and read into byte buffer
                    mspart.Read(part.Data, 0, len);
                    mspart.Close();
                }
                coll.Add(i, part);
                i++;
            }
            s.Close();

            return(coll);
        }
Пример #2
0
        public void LoadCompressed(Stream stream)
        {
            Parts.Clear();
            ZipInputStream s = new ZipInputStream(stream); // Do NOT dispose, as it will close stream aswell, wich might not be what user wants
            ZipEntry       theEntry;
            int            i = 0;

            while ((theEntry = s.GetNextEntry()) != null)
            {
                MMSMessagePart part = new MMSMessagePart {
                    PartId = i
                };

                string fileName = theEntry.Name;

                if (fileName != String.Empty)
                {
                    part.Name = fileName;
                    int size = 2048;
                    int len  = 0;
                    using (MemoryStream mspart = new MemoryStream(size))
                    {
                        byte[] partData = new byte[size];
                        while (true)
                        {
                            size = s.Read(partData, 0, partData.Length);
                            len += size;
                            if (size > 0)
                            {
                                mspart.Write(partData, 0, size);
                            }
                            else
                            {
                                break;
                            }
                        }
                        part.Data       = new byte[len];
                        mspart.Position = 0;
                        // Reset position and read into byte buffer
                        mspart.Read(part.Data, 0, len);
                        mspart.Close();
                    }
                }
                Parts.Add(i, part);
                i++;
            }
            s.Close();
        }
Пример #3
0
 /// <summary>
 /// Pack up the content of this MMSMessage as a zip file for suitable transmission
 /// to the MMS Gateway
 /// </summary>
 /// <returns>Byte array containing zipped data</returns>
 internal byte[] GetCompressed()
 {
     using (MemoryStream msZipOutput = new MemoryStream())
     {
         ZipOutputStream os = new ZipOutputStream(msZipOutput)
         {
             IsStreamOwner = false, UseZip64 = UseZip64.Off
         };
         foreach (int i in Parts.Keys)
         {
             MMSMessagePart part = Parts[i];
             os.PutNextEntry(new ZipEntry(part.Name));
             os.Write(part.Data, 0, part.Data.Length);
             os.CloseEntry();
         }
         os.Finish();
         os.Close();
         byte[] b = new byte[msZipOutput.Length];
         msZipOutput.Position = 0;
         msZipOutput.Read(b, 0, b.Length);
         msZipOutput.Close();
         return(b);
     }
 }
Пример #4
0
 public void Add(int key, MMSMessagePart value)
 {
     Dictionary.Add(key, value);
 }