<commit_before>﻿namespace Aegis.Shp
{
    using System;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Aegis.Dbf;

    public class Layer : ILayer, IDisposable
    {
        private readonly BinaryReader shpReader;
        private readonly DbfReader dbfReader;
        private bool disposed = false;

        private int fp = 0;

        private Layer(
            string name,
            BinaryReader shpReader,
            DbfReader dbfReader)
        {
            this.Name = name;
            this.shpReader = shpReader;
            this.dbfReader = dbfReader;
        }

        public virtual string Name { get; }

        public static ILayer Create(
            string name,
            Stream shpStream,
            Stream dbfStream)
        {
            var shpReader = new BinaryReader(shpStream, Encoding.UTF8, leaveOpen: true);
            var dbfReader = DbfReader.Create(dbfStream);

            var layer = new Layer(
                name,
                shpReader,
                dbfReader);

            layer.Reset();
            return layer;
        }

        public virtual IFeatureDefinition GetLayerDefinition()
        {
            return new FeatureDefinition(
                this.dbfReader.FieldDescriptors.ToArray());
        }

        public virtual IFeature GetNextFeature()
        {
            if (this.EOF())
            {
                return null;
            }

            var fields = this.dbfReader.GetRecord(this.fp);
            var header = RecordHeader.Read(this.shpReader);
            var type = this.shpReader.ReadInt32Ndr();

            // Content length is in words so multiply by 2 to get the number
            // of bytes. And we need to substract 4 bytes for the int that we
            // just read.
            var contentLength = (header.ContentLength * 2) - 4;
            var contents = this.shpReader.ReadBytes(contentLength);
            return Feature.Create(
                (ShapeType)type,
                this.fp++,
                contents,
                fields);
        }

        public virtual void Reset()
        {
            // Shapefile file header is fixed 100 bytes (just skip them)
            this.shpReader.BaseStream.Seek(100, SeekOrigin.Begin);
        }

        public virtual void Dispose()
        {
            this.Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                this.shpReader.Dispose();
            }

            this.disposed = true;
        }

        private bool EOF()
        {
            var stream = this.shpReader.BaseStream;
            return stream.Position == stream.Length;
        }
    }
}
<commit_msg>Added missing call to Dispose.<commit_after>﻿namespace Aegis.Shp
{
    using System;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Aegis.Dbf;

    public class Layer : ILayer, IDisposable
    {
        private readonly BinaryReader shpReader;
        private readonly DbfReader dbfReader;
        private bool disposed = false;

        private int fp = 0;

        private Layer(
            string name,
            BinaryReader shpReader,
            DbfReader dbfReader)
        {
            this.Name = name;
            this.shpReader = shpReader;
            this.dbfReader = dbfReader;
        }

        public virtual string Name { get; }

        public static ILayer Create(
            string name,
            Stream shpStream,
            Stream dbfStream)
        {
            var shpReader = new BinaryReader(shpStream, Encoding.UTF8, leaveOpen: true);
            var dbfReader = DbfReader.Create(dbfStream);

            var layer = new Layer(
                name,
                shpReader,
                dbfReader);

            layer.Reset();
            return layer;
        }

        public virtual IFeatureDefinition GetLayerDefinition()
        {
            return new FeatureDefinition(
                this.dbfReader.FieldDescriptors.ToArray());
        }

        public virtual IFeature GetNextFeature()
        {
            if (this.EOF())
            {
                return null;
            }

            var fields = this.dbfReader.GetRecord(this.fp);
            var header = RecordHeader.Read(this.shpReader);
            var type = this.shpReader.ReadInt32Ndr();

            // Content length is in words so multiply by 2 to get the number
            // of bytes. And we need to substract 4 bytes for the int that we
            // just read.
            var contentLength = (header.ContentLength * 2) - 4;
            var contents = this.shpReader.ReadBytes(contentLength);
            return Feature.Create(
                (ShapeType)type,
                this.fp++,
                contents,
                fields);
        }

        public virtual void Reset()
        {
            // Shapefile file header is fixed 100 bytes (just skip them)
            this.shpReader.BaseStream.Seek(100, SeekOrigin.Begin);
        }

        public virtual void Dispose()
        {
            this.Dispose(disposing: true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                this.shpReader.Dispose();
                this.dbfReader.Dispose();
            }

            this.disposed = true;
        }

        private bool EOF()
        {
            var stream = this.shpReader.BaseStream;
            return stream.Position == stream.Length;
        }
    }
}

{'fraction_non_alphanumeric': 0.07440425167152409, 'fraction_numerical': 0.00480027430138865, 'mean_word_length': 1.3382765531062124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372057', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1466, 'n_words': 395}