public static CharacterFrequency[] BuildEmptyArray(int size)
 {
     CharacterFrequency[] arr = new CharacterFrequency[size];
     for (int i = 0; i < arr.Length; i++)
     {
         arr[i] = new CharacterFrequency
         {
             Character = Convert.ToChar(i),
             Frequency = 0
         };
     }
     return(arr);
 }
        public void TestFileWriter()
        {
            StringBuilder path = new StringBuilder();

            path.Append(Directory.GetCurrentDirectory());
            path.Append(@"\" + FileWrite + ".txt");

            try
            {
                using (StreamWriter writer = new StreamWriter(path.ToString()))
                {
                    CharacterFrequency.WriteArray(writer, CharFrequencies);
                }
                Console.WriteLine($"File {FileWrite}.txt has been written");
            }
            catch
            {
                Console.WriteLine("Could not write File");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            const byte INPUT  = 0;
            const byte OUTPUT = 1;
            const byte MODE   = 2;

            CompressionInputValidation(args);


            var compressionManager = new CompressionManager
            {
                FileRead        = args[INPUT],
                FileWrite       = args[OUTPUT],
                CharFrequencies = CharacterFrequency.BuildEmptyArray(256),
                CharEncodings   = CharacterEncoding.BuildEmptyArray(256)
            };

            if (args[MODE].ToUpper() == "COMPRESS")
            {
                compressionManager.Compress();
            }
            else if (args[MODE].ToUpper() == "COMPRESSTEST")
            {
                compressionManager.CompressTest();
            }
            else if (args[MODE].ToUpper() == "DECOMPRESS")
            {
                compressionManager.Decompress();
            }
            else
            {
                Console.WriteLine("Please enter COMPRESS or DECOMPRESS after both files");
                Console.ReadKey();
                Environment.Exit(0);
            }
            #endregion
        }