An EbcdicReader reads bytes from an input stream and returns records, according to a copybook. Each call to NextRecord returns a list of objects, containing the decoded values of the fields. When there are no more records to read, it returns null. Copybooks with multiple records are supported. The reader relies on the position get/set methods of the input stream to detect the format of the current record.
Пример #1
0
        public void EbcdicTestsTestReader()
        {
            FileFormat fileFormat = CopybookLoader.LoadCopybook(Copybook + "/Test.fileformat");
            using (BufferedStream inputStream = new BufferedStream(new MemoryStream(Bytes)))
            {
                EbcdicReader reader = new EbcdicReader(inputStream, fileFormat, false);
                List<object> record = reader.NextRecord();
                Assert.AreEqual(Objects.Length, record.ToArray().Length);
                Assert.AreEqual(Objects.GetType(), record.ToArray().GetType());

                //NOTE : CollectionAssert does not support nested collection handling ...
                int index = 0;
                foreach (var rec in record.ToArray())
                {
                    var array = rec as Array;
                    if (array != null)
                    {
                        CollectionAssert.AreEqual((Array)Objects[index], array);
                    }
                    else
                    {
                        Assert.AreEqual(Objects[index], rec);
                    }
                    index++;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// @see AbstractItemCountingItemStreamItemReader#DoOpen
        /// </summary>
        protected override void DoOpen()
        {
            Assert.IsTrue(Resource.Exists(), "The input file must exist.");
            _inputStream = new BufferedStream(Resource.GetInputStream());

            FileFormat fileFormat = CopybookLoader.LoadCopybook(Copybook.GetInputStream());

            _reader = new EbcdicReader(_inputStream, fileFormat, Rdw);
            EbcdicReaderMapper.RecordFormatMap = new RecordFormatMap(fileFormat);

            _nbRead = 0;
            Name    = string.Concat("EbcdicFileReader.", Resource.GetFilename());
        }
Пример #3
0
        private void Test(String name, byte[] newLine, bool useRdw = false)
        {
            //BeforeClass();
            string input = Inputs +"/"+ name + ".txt";
            string output = Outputs + "/" + name + ".txt";
            string copybook = Copybook + "/" + name + ".fileformat";
            FileFormat fileFormat = CopybookLoader.LoadCopybook(copybook);
            using (BufferedStream inputStream = new BufferedStream(GetInputStream(input)))
            using (BufferedStream outputStream = new BufferedStream(new FileStream(output, FileMode.OpenOrCreate)))
            {
                EbcdicReader reader = new EbcdicReader(inputStream, fileFormat, useRdw);
                EbcdicWriter writer = new EbcdicWriter(outputStream, fileFormat.Charset, useRdw, EbcdicEncoder.DefaultValue.LowValue)
                {
                    RecordFormatMap = new RecordFormatMap(fileFormat)
                };


                List<Object> record = reader.NextRecord();
                while (record != null)
                {
                    writer.WriteRecord(record);
                    outputStream.Write(newLine);
                    record = reader.NextRecord();
                }
            }

            Assert.IsTrue(TestHelper.TestHelper.ContentEquals(GetInputStream(output), GetInputStream(input)));
        }