Write() public method

public Write ( byte array, int offset, int count ) : void
array byte
offset int
count int
return void
        static void EncodeFile(byte[] key, String sourceFile, string destFile)
        {
            // initialize keyed hash object
            HMACSHA1 hms = new HMACSHA1(key);

            // open filestreams to read in original file and write out coded file
            using(FileStream inStream = new FileStream(sourceFile,FileMode.Open))
            using (FileStream outStream = new FileStream(destFile, FileMode.Create))
            {
                // array to hold keyed hash value of original file
                byte[] hashValue = hms.ComputeHash(inStream);

                // reset instream ready to read original file contents from start
                inStream.Position = 0;

                // write keyed hash value to coded file
                outStream.Write(hashValue, 0, hashValue.Length);

                // copy data from original file to output file, 1K at a time
                int bytesRead;
                byte[] buffer = new byte[1024];
                do
                {
                    bytesRead = inStream.Read(buffer, 0, 1024);
                    outStream.Write(buffer, 0, bytesRead);
                } while (bytesRead > 0);
                hms.Clear();

                inStream.Close();
                outStream.Close();
            }
        }
        private void ReceiveFile(object obj)
        {
            string msg = (string)obj;
            string savePath = msg.Split(',')[0];
            int len = int.Parse(msg.Split(',')[1]);
            FileStream fileReceive = new FileStream(savePath, FileMode.Create, FileAccess.Write);

            int bufferSize = Clients.client_FileTransport.ReceiveBufferSize;
            byte[] buffer = new byte[bufferSize]; //定义缓冲区
            int left = len;
            //接收数据
            while (left > 0)
            {
                if (left > buffer.Length)
                {
                    Clients.netStream_FileTransport.Read(buffer, 0, buffer.Length);
                    fileReceive.Write(buffer, 0, buffer.Length);
                    left -= bufferSize;
                    int value = (bufferSize - left) / len;
                    SetProgress(value);
                }
                else
                {
                    Clients.netStream_FileTransport.Read(buffer, 0, left);
                    fileReceive.Write(buffer, 0, left);
                    left -= bufferSize;
                    SetProgress(100);
                }
            }
            fileReceive.Close();
        }
        public void Encrypt(string key)
        {
            var stream = new FileStream(Filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            // decido quanti byte di inizio file criptare
            // ovviamente devo tener conto della dimensione del file
            int headerSize = 254;
            if (headerSize > stream.Length)
                headerSize = (int)stream.Length;

            var firstBytes = new byte[headerSize];
            stream.Read(firstBytes, 0, firstBytes.Length);

            // crittografa il primo blocco di N bytes
            var crypto = RijndaelService.EncryptBytes(firstBytes, key);

            // leggi tutto il contenuto restante
            byte[] bytes = new byte[stream.Length - firstBytes.Length];
            stream.Read(bytes, 0, bytes.Length);

            stream.Close();
            stream.Dispose();

            // LA situazione ora è definita da
            // crypto: primi N bytes criptati
            // bytes: i restanti bytes del file, normali

            stream = new FileStream(Filename, FileMode.Create);
            // All'inizio del blocco specifica il numero dei byte adibiti all'header section
            stream.Write(BitConverter.GetBytes(crypto.Length), 0, sizeof(int));
            stream.Write(crypto, 0, crypto.Length);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
            stream.Dispose();
        }
Example #4
0
 // Computes a keyed hash for a source file, creates a target file with the keyed hash
 // prepended to the contents of the source file, then decrypts the file and compares
 // the source and the decrypted files.
 public static void EncodeFile(byte[] key, String sourceFile, String destFile)
 {
     // Initialize the keyed hash object.
     HMACSHA256 myhmacsha256 = new HMACSHA256(key);
     FileStream inStream = new FileStream(sourceFile, FileMode.Open);
     FileStream outStream = new FileStream(destFile, FileMode.Create);
     // Compute the hash of the input file.
     byte[] hashValue = myhmacsha256.ComputeHash(inStream);
     // Reset inStream to the beginning of the file.
     inStream.Position = 0;
     // Write the computed hash value to the output file.
     outStream.Write(hashValue, 0, hashValue.Length);
     // Copy the contents of the sourceFile to the destFile.
     int bytesRead;
     // read 1K at a time
     byte[] buffer = new byte[1024];
     do
     {
         // Read from the wrapping CryptoStream.
         bytesRead = inStream.Read(buffer, 0, 1024);
         outStream.Write(buffer, 0, bytesRead);
     } while (bytesRead > 0);
     myhmacsha256.Clear();
     // Close the streams
     inStream.Close();
     outStream.Close();
     return;
 }
Example #5
0
        public void Encrypt(string filename)
        {
            FileStream fsInput = new FileStream(filename, FileMode.Open, FileAccess.Read);
            FileStream fsOutput = new FileStream(filename + ".crypt", FileMode.Create, FileAccess.Write);
            AesCryptoServiceProvider Aes = new AesCryptoServiceProvider();

            Aes.KeySize = 128;
            Aes.GenerateIV();
            Aes.GenerateKey();

            byte[] output = _algorithm_asym.Encrypt(Aes.Key, false);
            fsOutput.Write(output, 0, 256);
            output = _algorithm_asym.Encrypt(Aes.IV, false);
            fsOutput.Write(output, 0, 256);

            ICryptoTransform encrypt = Aes.CreateEncryptor();
            CryptoStream cryptostream = new CryptoStream(fsOutput, encrypt, CryptoStreamMode.Write);

            byte[] bytearrayinput = new byte[fsInput.Length - 1];
            fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
            cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);

            fsInput.Close();
            fsOutput.Close();
        }
        public void BluRaySupWriteAndReadTwoBitmaps()
        {
            var fileName = Guid.NewGuid() + ".sup";
            using (var binarySubtitleFile = new FileStream(fileName, FileMode.Create))
            {
                var brSub = new BluRaySupPicture
                {
                    StartTime = 0,
                    EndTime = 1000,
                    Width = 1080,
                    Height = 720
                };
                var buffer = BluRaySupPicture.CreateSupFrame(brSub, new Bitmap(100, 20), 10, 25, 10, ContentAlignment.BottomCenter);
                binarySubtitleFile.Write(buffer, 0, buffer.Length);
                brSub.StartTime = 2000;
                brSub.EndTime = 3000;
                buffer = BluRaySupPicture.CreateSupFrame(brSub, new Bitmap(100, 20), 10, 25, 10, ContentAlignment.BottomCenter);
                binarySubtitleFile.Write(buffer, 0, buffer.Length);
            }

            var log = new StringBuilder();
            var subtitles = BluRaySupParser.ParseBluRaySup(fileName, log);

            Assert.AreEqual(2, subtitles.Count);
        }
 // Computes a keyed hash for a source file and creates a target file with the keyed hash
 // prepended to the contents of the source file.
 public static void SignFile(byte[] key, String sourceFile, String destFile)
 {
     // Initialize the keyed hash object.
     using (HMACSHA512 hmac = new HMACSHA512(key))
     {
         using (FileStream inStream = new FileStream(sourceFile, FileMode.Open))
         {
             using (FileStream outStream = new FileStream(destFile, FileMode.Create))
             {
                 // Compute the hash of the input file.
                 byte[] hashValue = hmac.ComputeHash(inStream);
                 // Reset inStream to the beginning of the file.
                 inStream.Position = 0;
                 // Write the computed hash value to the output file.
                 outStream.Write(hashValue, 0, hashValue.Length);
                 // Copy the contents of the sourceFile to the destFile.
                 int bytesRead;
                 // read 1K at a time
                 byte[] buffer = new byte[1024];
                 do
                 {
                     // Read from the wrapping CryptoStream.
                     bytesRead = inStream.Read(buffer, 0, 1024);
                     outStream.Write(buffer, 0, bytesRead);
                 } while (bytesRead > 0);
             }
         }
     }
 }
        public void doBackUp()
        {
            try
            {
                string path = @"C:\";
                string newpath = System.IO.Path.Combine(path, "BackUpLocation");
                Directory.CreateDirectory(newpath);

                FileStream fmdf = new FileStream(mdf, FileMode.Open, FileAccess.Read);
                FileStream fldf = new FileStream(ldf, FileMode.Open, FileAccess.Read);
                FileStream fbak = new FileStream(bak, FileMode.Create, FileAccess.Write);

                byte[] fmcontent = new byte[fmdf.Length];
                fmdf.Read(fmcontent, 0, (int)fmdf.Length);
                fbak.Write(fmcontent, 0, (int)fmdf.Length);

                byte[] sym = new byte[3];
                sym[0] = (byte)'$'; sym[1] = (byte)'*'; sym[2] = (byte)'^';
                fbak.Write(sym, 0, 3);

                byte[] flcontent = new byte[fldf.Length];
                fldf.Read(flcontent, 0, (int)fldf.Length);
                fbak.Write(flcontent, 0, (int)fldf.Length);

                fbak.Flush();
                fbak.Close();
                fmdf.Close();
                fldf.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // Export data
        public static void Export(byte[] data)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.Filter = "Dropset Data|*.dat";
                sfd.Title = "Export Dropset Data";
                sfd.AddExtension = true;
                sfd.RestoreDirectory = true;
                sfd.OverwritePrompt = true;

                DialogResult result = sfd.ShowDialog();

                if (result == DialogResult.OK)
                {
                    try
                    {
                        using (FileStream outstream = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
                        {
                            outstream.Write(new byte[] { 0x50, 0x50, 0x46, 0x44, 0x53, 0x45 }, 0, 6);
                            outstream.Write(data, 0, data.Length);
                            outstream.Close();
                        }

                        MessageBox.Show("Dropset data exported successfully.", "Export Successful");
                    }
                    catch
                    {
                        MessageBox.Show("An error occured when writing the dropset data.", "Export Unsuccessful");
                    }
                }
            }
        }
Example #10
0
 public static void WriteString(FileStream fs, string s)
 {
     if (s == null)
         s = "";
     fs.Write(BitConverter.GetBytes((int)s.Length), 0, 4);
     fs.Write(GetBytes(s), 0, s.Length);
 }
Example #11
0
        //, GameSet set)
        internal void SaveGameSetToFile(string filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Create))
            {
                //write SET file header
                fs.Write(BitConverter.GetBytes(this._recordCount), 0, 2);
                foreach (DatabaseContainer db in this.DatabaseContainers)
                {
                    fs.Write(Encoding.GetEncoding(1252).GetBytes(db.Name.PadRight(_rowNameSize, (char) 0x0)), 0, _rowNameSize);
                    fs.Write(BitConverter.GetBytes(Convert.ToInt32(db.Offset)), 0, 4);
                }

                //write SET file header-trailer (9 nulls followed by int filesize). write size after writing DBFs.
                for (int i = 0; i < 13; i++)
                    fs.WriteByte(0x0);

                long fileSizeBookmark = fs.Position - 4;

                //write out DBFs
                foreach (DatabaseContainer db in this.DatabaseContainers)
                {
            #if DEBUG
                    //writes out individual DBFs... easier to inspect SFRAME, etc
                    string path = this._dbfDirectory + "test";
                    Directory.CreateDirectory(path);
                    db.DbfFileObject.WriteAndClose(path);
            #endif
                    db.DbfFileObject.WriteToStream(fs);
                }
                fs.Position = fileSizeBookmark;
                int fileSize = (int) fs.Length;
                fs.Write(BitConverter.GetBytes(fileSize), 0, 4);
            }
        }
Example #12
0
        public void Save(string path)
        {
            using (var sw = new FileStream(path, FileMode.Create))
            {
                var heightBytes = BitConverter.GetBytes(Height);
                sw.Write(heightBytes, 0, 4);

                var widthBytes = BitConverter.GetBytes(Width);
                sw.Write(widthBytes, 0, 4);

                var compressionLevelBytes = BitConverter.GetBytes(CompressionLevel);
                sw.Write(compressionLevelBytes, 0, 4);

                var frequencesPerBlockBytes = BitConverter.GetBytes(FrequencesPerBlock);
                sw.Write(frequencesPerBlockBytes, 0, 4);

                int blockSize = FrequencesPerBlock;
                for (int blockNum = 0; blockNum * blockSize < Frequences.Count; blockNum++)
                {
                    for (int freqNum = 0; freqNum < blockSize; freqNum++)
                    {
                        var portion = BitConverter.GetBytes((short)Frequences[blockNum * blockSize + freqNum]);
                        sw.Write(portion, 0, portion.Length);
                    }
                }
            }
        }
Example #13
0
        //Đưa SecretKey vào File của thuật toán 3DES
        public void AddSecretKeytoFile(string inputFile)
        {
            //Add SecretKey to File;
            if (File.Exists(inputFile))
            {
                FileStream fsOpen = new FileStream(inputFile, FileMode.Open, FileAccess.ReadWrite);
                try
                {
                    byte[] content = new byte[fsOpen.Length];
                    fsOpen.Read(content, 0, content.Length);
                    //string sContent = System.Text.Encoding.UTF8.GetString(content); //noi dung bang string

                    //byte[] plainbytesCheck = System.Text.Encoding.UTF8.GetBytes(sContent);
                    byte[] plainbytesKey = new UTF8Encoding(true).GetBytes(m_EncryptedSecretKey + "\r\n");

                    fsOpen.Seek(0, SeekOrigin.Begin);
                    fsOpen.Write(plainbytesKey, 0, plainbytesKey.Length);
                    fsOpen.Flush();
                    fsOpen.Write(content, 0, content.Length);
                    fsOpen.Flush();
                    fsOpen.Close();
                }
                catch
                {
                    fsOpen.Close();
                }
            }
        }
Example #14
0
 private static void AddText(FileStream fs, string value)
 {
     byte[] info = new UTF8Encoding(true).GetBytes(value);
     fs.Write(info, 0, info.Length);
     byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine);
     fs.Write(newline, 0, newline.Length);
 }
Example #15
0
 private static void DisplayContent(HttpWebResponse response, string id)
 {
     Stream stream = response.GetResponseStream();
     if (stream != null)
     {
         string filePath = "D:\\pic\\" + id + ".png";
         FileStream fs = new FileStream(filePath, FileMode.Create);
         GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress);
         byte[] bytes = new byte[1024];
         int len;
         if ((len = gzip.Read(bytes, 0, bytes.Length)) > 0)
         {
             fs.Write(bytes, 0, len);
         }
         else
         {
             fs.Close();
             File.Delete(filePath);
             throw new Exception();
         }
         while ((len = gzip.Read(bytes, 0, bytes.Length)) > 0)
         {
             fs.Write(bytes, 0, len);
         }
         fs.Close();
     }
 }
Example #16
0
        protected void DoCss(string modulePath, string moduleName)
        {
            List<string> cssFiles = new List<string>();
            ScanDir(new DirectoryInfo(modulePath), "*.css", ref cssFiles);
            ScanDir(new DirectoryInfo(modulePath), "*.less", ref cssFiles);

            FileStream file = new FileStream(_pathBuild + "/" + moduleName + ".css", FileMode.Create);
            foreach (string cssFile in cssFiles)
            {
                if (cssFile.EndsWith(".less"))
                {
                    string fileText = "";
                    fileText = File.ReadAllText(cssFile);
                    fileText = Less.Parse(fileText);
                    byte[] b1 = Encoding.UTF8.GetBytes(fileText);
                    file.Write(b1,0,b1.Length);
                }
                else
                {
                    int Count = 0;
                    byte[] buffer = new byte[1024];
                    FileStream FS = new FileStream(cssFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                    while (FS.Position < FS.Length)
                    {

                        // Читаем данные из файла
                        Count = FS.Read(buffer, 0, buffer.Length);
                        // И передаем их клиенту
                        file.Write(buffer, 0, Count);
                    }
                    FS.Close();
                }
            }
            file.Close();
        }
Example #17
0
 private static void WriteFile(string sFilename, HTTPHeaders oH, byte[] arrData)
 {
     FileStream fileStream = new FileStream(sFilename, FileMode.Create, FileAccess.Write);
     if (oH != null)
     {
         HTTPRequestHeaders hTTPRequestHeader = oH as HTTPRequestHeaders;
         if (hTTPRequestHeader == null)
         {
             HTTPResponseHeaders hTTPResponseHeader = oH as HTTPResponseHeaders;
             if (hTTPResponseHeader != null)
             {
                 byte[] byteArray = hTTPResponseHeader.ToByteArray(true, true);
                 fileStream.Write(byteArray, 0, (int)byteArray.Length);
             }
         }
         else
         {
             byte[] numArray = hTTPRequestHeader.ToByteArray(true, true, true);
             fileStream.Write(numArray, 0, (int)numArray.Length);
         }
     }
     if (arrData != null)
     {
         fileStream.Write(arrData, 0, (int)arrData.Length);
     }
     fileStream.Close();
 }
Example #18
0
        public MovieWriter(string filepath, MovieId id, bool UseExistingFile)
        {
            file = new FileInfo(filepath);

            if (file.Exists && UseExistingFile)
            {
                using (FileStream input = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                    fs = new FrameScanner(input);

                if (fs.HeaderOkay)
                    output = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite);
            }
            else
            {
                output = new FileStream(filepath, FileMode.Create, FileAccess.Write);
                output.Write(Encoding.ASCII.GetBytes("MMDb"), 0, 4);
                output.WriteByte((byte)FileVersions.First.Major);
                output.WriteByte((byte)FileVersions.First.Minor);
                output.Write(BitConverter.GetBytes(id.Id), 0, 4);
                output.Close();

                using (FileStream input = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                    fs = new FrameScanner(input);

                output = new FileStream(filepath, FileMode.Open, FileAccess.Write);
            }
        }
Example #19
0
        public static void Save(string fileName, Subtitle subtitle)
        {
            using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                byte[] buffer = { 0x38, 0x35, 0x30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x30, 0x30, 0x30, 0x39 };
                fs.Write(buffer, 0, buffer.Length);
                for (int i = 0; i < 0xde; i++)
                    fs.WriteByte(0);
                string numberOfLines = subtitle.Paragraphs.Count.ToString("D5");

                buffer = Encoding.ASCII.GetBytes(numberOfLines + numberOfLines + "001");
                fs.Write(buffer, 0, buffer.Length);
                for (int i = 0; i < 0x15; i++)
                    fs.WriteByte(0);
                buffer = Encoding.ASCII.GetBytes("11");
                fs.Write(buffer, 0, buffer.Length);
                while (fs.Length < 1024)
                    fs.WriteByte(0);

                int subtitleNumber = 0;
                foreach (Paragraph p in subtitle.Paragraphs)
                {
                    WriteSubtitleBlock(fs, p, subtitleNumber);
                    subtitleNumber++;
                }
            }
        }
        public static void Main(string[] args)
        {
            string SCRATCH_FILES_PATH = "ziptest";
            string scratchPath = "ziptest.zip";

            using (var archive = ZipArchive.Create()) {
                DirectoryInfo di = new DirectoryInfo(SCRATCH_FILES_PATH);
                foreach (var fi in di.GetFiles()) {
                    archive.AddEntry(fi.Name, fi.OpenRead(), true);
                }
                FileStream fs_scratchPath = new FileStream(scratchPath, FileMode.OpenOrCreate, FileAccess.Write);
                archive.SaveTo(fs_scratchPath, CompressionType.Deflate);
                fs_scratchPath.Close();
                //archive.AddAllFromDirectory(SCRATCH_FILES_PATH);
                //archive.SaveTo(scratchPath, CompressionType.Deflate);
                using (FileStream fs = new FileStream("ziphead.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
                    MyHead mh = new MyHead();
                    byte[] headData = mh.Create();
                    fs.Write(headData, 0, headData.Length);
                    //
                    SharpCompress.IO.OffsetStream ofs = new IO.OffsetStream(fs, fs.Position);
                    archive.SaveTo(ofs, CompressionType.Deflate);
                }
            }
            //write my zipfile with head data
            using (FileStream fs = new FileStream("mypack.data.zip", FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) {
                MyHead mh = new MyHead();
                byte[] headData = mh.Create();
                fs.Write(headData, 0, headData.Length);
                using (FileStream fs2 = new FileStream(scratchPath, FileMode.Open, FileAccess.Read)) {
                    byte[] buf = new byte[1024];
                    int rc = 0;
                    while ((rc = fs2.Read(buf, 0, buf.Length)) > 0) {
                        fs.Write(buf, 0, rc);
                    }
                }
            }
            //
            //read my zip file with head
            //
            using (FileStream fs = new FileStream("mypack.data.zip", FileMode.Open, FileAccess.Read, FileShare.Read)) {
                byte[] buf = new byte[1024];
                int offset = fs.Read(buf, 0, buf.Length);
                System.Diagnostics.Debug.Assert(offset == 1024);
                //fs.Position = 0L;
                SharpCompress.IO.OffsetStream substream = new SharpCompress.IO.OffsetStream(fs, offset);
                ZipArchive zip = ZipArchive.Open(substream, Options.KeepStreamsOpen);//cann't read
                //ZipArchive zip = ZipArchive.Open(fs, Options.None); //will throw exption
                //ZipArchive zip = ZipArchive.Open(fs, Options.KeepStreamsOpen);//cann't read

                foreach (ZipArchiveEntry zf in zip.Entries) {
                    Console.WriteLine(zf.Key);
                    //bug:the will not none in zipfile
                }

                int jjj = 0;
                jjj++;
            }
        }
Example #21
0
 public void dump(string path)
 {
     string fname=Path.Combine(path,Path.GetFileName(filename));
     FileStream fs=new FileStream(fname,FileMode.Create);
     fs.Write(data,0,data.Length);
     fs.Write(footer,0,footer.Length);
     fs.Close();
 }
		public static void SaveLUT(string file, Color32[] lut) {
			if (lut.Length != 256) return;
			using (FileStream fs = new FileStream(file, FileMode.Create))
			{
				fs.Write(lut.Select(color => color.R).ToArray(), 0, lut.Length);
				fs.Write(lut.Select(color => color.G).ToArray(), 0, lut.Length);
				fs.Write(lut.Select(color => color.B).ToArray(), 0, lut.Length);
			}
		}
        public bool Decrypt(string key, bool ownermode = true)
        {
            string password = key;

            var aglService = new FileAGLService(Filename);
            string decryptoAGL = string.Empty;
            if (aglService.Access(key, out decryptoAGL))
            {
                if (decryptoAGL.Contains(FileAGLService.SecurityPhrase + ":"))
                    password = decryptoAGL.Replace(FileAGLService.SecurityPhrase + ":", string.Empty);
            } else return false;

            int aglSize = aglService.Size();

            var stream = new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            // Ottieni la lunghezza dell'header
            stream.Seek(0, SeekOrigin.Begin);
            byte[] headerSizeBytes = new byte[sizeof(int)];
            stream.Read(headerSizeBytes, 0, headerSizeBytes.Length);

            int headerSize = BitConverter.ToInt32(headerSizeBytes, 0);

            // leggi l'header
            var headerBytes = new byte[headerSize];
            stream.Read(headerBytes, 0, headerBytes.Length);

            // decripta l'header
            byte[] decrypto;

            try
            {
                decrypto = RijndaelService.DecryptBytes(headerBytes, password);
                Key = password;
            }
            catch (Exception) { return false; }

            // se è riuscito a decriptarlo, sostituisci il file con quello originale, rimuovendo anchel'AGL

            var bytes = new byte[stream.Length - sizeof(int) - headerBytes.Length - aglSize];
            stream.Read(bytes, 0, bytes.Length);

            stream.Close();
            stream.Dispose();

            // Ripristina il file

            stream = new FileStream(Filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
            // All'inizio del blocco specifica il numero dei byte adibiti all'header section
            stream.Write(decrypto, 0, decrypto.Length);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
            stream.Dispose();

            return true;
        }
Example #24
0
        public void NegativeOffsetThrows()
        {
            using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
            {
                Assert.Throws<ArgumentOutOfRangeException>("offset", () => fs.Write(new byte[1], -1, 1));

                // array is checked first
                Assert.Throws<ArgumentNullException>("array", () => fs.Write(null, -1, 1));
            }
        }
Example #25
0
 public void Serialize(FileStream f)
 {
     f.Write(BitConverter.GetBytes(Neighbors.Length), 0, 4);
     foreach (int neighbor in Neighbors)
     {
         f.Write(BitConverter.GetBytes(neighbor), 0, 4);
     }
     f.Write(BitConverter.GetBytes(position.X), 0, 4);
     f.Write(BitConverter.GetBytes(position.Y), 0, 4);
     f.Write(BitConverter.GetBytes(position.Z), 0, 4);
 }
Example #26
0
        /// <summary>
        /// Encodes unencoded bytes and writes them to the FileStream
        /// </summary>
        /// <param name="w">FileStream to write to</param>
        /// <param name="ride">Unencoded bytes</param>
        public static void Write(FileStream w, byte[] ride)
        {
            byte[] encodedBytes = Encode(ride);
            w.Write(encodedBytes, 0, encodedBytes.Length);

            uint checksum = Checksum(encodedBytes);
            byte[] checksumBytes = BitConverter.GetBytes(checksum);

            w.Write(checksumBytes, 0, checksumBytes.Length);
            w.Flush();
        }
Example #27
0
 public static void ConvertPNGtoTP(Stream stream, string tpPath)
 {
     using (FileStream fs = new FileStream(tpPath, FileMode.Create, FileAccess.Write, FileShare.Read))
     {
         fs.Write(BitConverter.GetBytes(1), 0, 4);
         fs.Write(BitConverter.GetBytes(21), 0, 4);
         fs.Write(BitConverter.GetBytes((int)stream.Length), 0, 4);
         fs.Seek(9, SeekOrigin.Current);
         stream.CopyStream(fs);
     }
 }
Example #28
0
 public virtual void Test1()
 {
     var raf = new FileStream("testBigFile", FileMode.OpenOrCreate);
     long l = 2 * 1024000;
     Println(l);
     raf.Seek(l, SeekOrigin.Begin);
     for (var i = 0; i < 1024000; i++)
         raf.Write(new byte[] {0}, 0, 1);
     raf.Write(new byte[] {0}, 0, 1);
     raf.Close();
 }
Example #29
0
 public static void Save(CurrentIDs currentIDs)
 {
     byte[] arrEncryptByte = Serialize.EncryptToBytes(currentIDs);
     byte[] arrLength = PubHelper.intToByte(arrEncryptByte.Length);  //将长度(整数)保存在4个元素的字节数组中
     lock (GlobalPool.Lock)
     {
         FileStream fs = new FileStream(Application.StartupPath + "\\config.ini", FileMode.OpenOrCreate);
         fs.Write(arrLength, 0, arrLength.Length);
         fs.Write(arrEncryptByte, 0, arrEncryptByte.Length);
         fs.Close();
     }
 }
Example #30
-1
 public void dump(string filename)
 {
     FileStream fs = new FileStream(filename, FileMode.Create);
     fs.Write(data,0, data.Length);
     fs.Write(footer, 0, footer.Length);
     fs.Close();
 }