GetPreamble() public method

public GetPreamble ( ) : byte[]
return byte[]
Esempio n. 1
0
 private void DoExportForHishop(string csvFilename, string imagePath, System.Collections.Generic.List <ExportToLocal.ProductDetail> list)
 {
     using (System.IO.FileStream fileStream = new System.IO.FileStream(csvFilename, System.IO.FileMode.Create, System.IO.FileAccess.Write))
     {
         string productCSVForEcdev = this.GetProductCSVForHishop(imagePath, list);
         System.Text.UnicodeEncoding unicodeEncoding = new System.Text.UnicodeEncoding();
         //UTF8Encoding unicodeEncoding = new UTF8Encoding();
         int    byteCount = unicodeEncoding.GetByteCount(productCSVForEcdev);
         byte[] preamble  = unicodeEncoding.GetPreamble();
         byte[] array     = new byte[preamble.Length + byteCount];
         System.Buffer.BlockCopy(preamble, 0, array, 0, preamble.Length);
         unicodeEncoding.GetBytes(productCSVForEcdev.ToCharArray(), 0, productCSVForEcdev.Length, array, preamble.Length);
         fileStream.Write(array, 0, array.Length);
     }
     using (ZipFile zipFile = new ZipFile(System.Text.Encoding.Default))
     {
         System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(imagePath);
         zipFile.CompressionLevel = CompressionLevel.Default;
         zipFile.AddFile(csvFilename, "");
         zipFile.AddDirectory(directoryInfo.FullName, directoryInfo.Name);
         System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
         response.ContentType     = "application/x-zip-compressed";
         response.ContentEncoding = this._encoding;
         response.AddHeader("Content-Disposition", "attachment; filename=" + directoryInfo.Name + ".zip");
         response.Clear();
         zipFile.Save(response.OutputStream);
         this._workDir.Delete(true);
         response.Flush();
         response.Close();
     }
 }
        public void PosTest3()
        {
            UnicodeEncoding uE = new UnicodeEncoding(false, true);
            Byte[] expectedValue = new Byte[] { 0xff, 0xfe };
            Byte[] actualValue;

            actualValue = uE.GetPreamble();
            Assert.Equal(expectedValue, actualValue);
        }
 static public int GetPreamble(IntPtr l)
 {
     try {
         System.Text.UnicodeEncoding self = (System.Text.UnicodeEncoding)checkSelf(l);
         var ret = self.GetPreamble();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 4
0
        internal static byte[] GetContentBytes(TextEncodingType encodingType, string content)
        {
            byte[] contentBytes;
            switch (encodingType)
            {
                case TextEncodingType.ISO_8859_1:
                    var asciiEncoding = new ASCIIEncoding();
                    contentBytes = asciiEncoding.GetBytes(content);
                    break;
                case TextEncodingType.UTF16:
                    var utf16Encoding = new UnicodeEncoding(false, true);
                    var bom = utf16Encoding.GetPreamble();
                    var dataBytes = utf16Encoding.GetBytes(content);

                    // Copy BOM and Content together in an array
                    contentBytes = new byte[bom.Length + dataBytes.Length];
                    Array.Copy(bom, 0, contentBytes, 0, bom.Length);
                    Array.Copy(dataBytes, 0, contentBytes, bom.Length, dataBytes.Length);
                    break;
                case TextEncodingType.UTF16_BE:
                    var utf16BEEncoding = new UnicodeEncoding(true, true);
                    contentBytes = utf16BEEncoding.GetBytes(content);
                    break;
                case TextEncodingType.UTF8:
                    var utf8Encoding = new UTF8Encoding();
                    contentBytes = utf8Encoding.GetBytes(content);
                    break;
                default:
                    throw new ID3TagException("Unknown Encoding Type found!");
            }

            return contentBytes;
        }
Esempio n. 5
0
                public void TestPreamble3()
                {
                        //little-endian without byte order mark.
                        UnicodeEncoding UnicodeEnc = new UnicodeEncoding (false, false); 
                        byte[] PreAmble = UnicodeEnc.GetPreamble();

                        Assert.AreEqual (0, PreAmble.Length, "Uni #1");
                }
Esempio n. 6
0
                public void TestPreamble2()
                {
                        //big-endian with byte order mark.
                        UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); 
                        byte[] PreAmble = UnicodeEnc.GetPreamble();

                        Assert.AreEqual (0xFE, PreAmble [0], "Uni #1");
                        Assert.AreEqual (0xFF, PreAmble [1], "Uni #2");
                }
Esempio n. 7
0
 public override void DoExport()
 {
     this._workDir = this._baseDir.CreateSubdirectory(this._flag);
     this._productImagesDir = this._workDir.CreateSubdirectory("products");
     string path = Path.Combine(this._workDir.FullName, "products.csv");
     using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
     {
         string productCSV = this.GetProductCSV();
         UnicodeEncoding encoding = new UnicodeEncoding();
         int byteCount = encoding.GetByteCount(productCSV);
         byte[] preamble = encoding.GetPreamble();
         byte[] dst = new byte[preamble.Length + byteCount];
         Buffer.BlockCopy(preamble, 0, dst, 0, preamble.Length);
         encoding.GetBytes(productCSV.ToCharArray(), 0, productCSV.Length, dst, preamble.Length);
         stream.Write(dst, 0, dst.Length);
     }
     using (ZipFile file = new ZipFile())
     {
         file.CompressionLevel = CompressionLevel.Default;
         file.AddFile(path, "");
         file.AddDirectory(this._productImagesDir.FullName, this._productImagesDir.Name);
         HttpResponse response = HttpContext.Current.Response;
         response.ContentType = "application/x-zip-compressed";
         response.ContentEncoding = this._encoding;
         response.AddHeader("Content-Disposition", "attachment; filename=" + this._zipFilename);
         response.Clear();
         file.Save(response.OutputStream);
         this._workDir.Delete(true);
         response.Flush();
         response.Close();
     }
 }
                public void TestPreamble2()
                {
                        //big-endian with byte order mark.
                        UnicodeEncoding UnicodeEnc = new UnicodeEncoding (true, true); 
                        byte[] PreAmble = UnicodeEnc.GetPreamble();

                        Assertion.AssertEquals ("Uni #1", 0xFE, PreAmble [0]);
                        Assertion.AssertEquals ("Uni #2", 0xFF, PreAmble [1]);
                }