Пример #1
0
 DataFileReader(Stream stream, Schema readerSchema, CreateDatumReader datumReaderFactory)
 {
     _readerSchema       = readerSchema;
     _datumReaderFactory = datumReaderFactory;
     Init(stream);
     BlockFinished();
 }
Пример #2
0
 DataFileReader(Stream stream, Schema readerSchema, CreateDatumReader datumReaderFactory, bool leaveOpen)
 {
     _readerSchema       = readerSchema;
     _datumReaderFactory = datumReaderFactory;
     _leaveOpen          = leaveOpen;
     Init(stream);
     BlockFinished();
 }
Пример #3
0
        private static Decoder OpenReader(Stream inStream, CreateDatumReader datumReaderFactory)
        {
            if (!inStream.CanSeek)
            {
                throw new AvroRuntimeException("Not a valid input stream - must be seekable!");
            }

            return(new Decoder(inStream, datumReaderFactory));         // (not supporting 1.2 or below, format)
        }
Пример #4
0
        Decoder(Stream stream, CreateDatumReader datumReaderFactory)
        {
            _datumReaderFactory = datumReaderFactory;
            _stream             = stream;
            _header             = new Header();
            _reader             = new Reader(stream);
            _syncBuffer         = new byte[DataFileConstants.SyncSize];

            // validate header
            byte[] firstBytes = new byte[DataFileConstants.AvroHeader.Length];
            try
            {
                _reader.ReadFixed(firstBytes);
            }
            catch (Exception)
            {
                throw new InvalidAvroObjectException("Cannot read length of Avro Header");
            }
            if (!firstBytes.SequenceEqual(DataFileConstants.AvroHeader))
            {
                throw new InvalidAvroObjectException("Cannot read Avro Header");
            }

            // read meta data
            long len = _reader.ReadMapStart();

            if (len > 0)
            {
                do
                {
                    for (long i = 0; i < len; i++)
                    {
                        string key = _reader.ReadString();
                        byte[] val = _reader.ReadBytes();
                        _header.MetaData.Add(key, val);
                    }
                } while ((len = _reader.ReadMapNext()) != 0);
            }

            // read in sync data
            _reader.ReadFixed(_header.SyncData);

            // parse schema and set codec
            _header.Schema = Schema.Parse(GetMetaString(DataFileConstants.SchemaMetadataKey));
            resolver       = _datumReaderFactory(_header.Schema, _readerSchema ?? _header.Schema);
            _codec         = Codec.CreateCodecFromString(GetMetaString(DataFileConstants.CodecMetadataKey));
        }
Пример #5
0
        /// <summary>
        ///  Open a reader for a stream using the reader's schema and a custom DatumReader
        /// </summary>
        /// <param name="inStream"></param>
        /// <returns></returns>
        public static IFileReader <T> OpenReader(Stream inStream, Schema readerSchema, CreateDatumReader datumReaderFactory)
        {
            if (!inStream.CanSeek)
            {
                throw new AvroRuntimeException("Not a valid input stream - must be seekable!");
            }

            if (inStream.Length < DataFileConstants.AvroHeader.Length)
            {
                throw new AvroRuntimeException("Not an Avro data file");
            }

            // verify magic header
            byte[] magic = new byte[DataFileConstants.AvroHeader.Length];
            inStream.Seek(0, SeekOrigin.Begin);
            for (int c = 0; c < magic.Length; c = inStream.Read(magic, c, magic.Length - c))
            {
            }
            inStream.Seek(0, SeekOrigin.Begin);

            if (magic.SequenceEqual(DataFileConstants.AvroHeader))                          // current format
            {
                return(new DataFileReader <T>(inStream, readerSchema, datumReaderFactory)); // (not supporting 1.2 or below, format)
            }
            throw new AvroRuntimeException("Not an Avro data file");
        }
Пример #6
0
 /// <summary>
 ///  Open a reader for a stream using the reader's schema and a custom DatumReader
 /// </summary>
 /// <param name="inStream">Stream of file contents</param>
 /// <param name="readerSchema">Schema used to read the file</param>
 /// <param name="datumReaderFactory">Factory to create datum readers given a reader an writer schema</param>
 /// <returns>A new file reader</returns>
 public static IFileReader <T> OpenReader(Stream inStream, Schema readerSchema, CreateDatumReader datumReaderFactory)
 {
     return(new DataFileReader <T>(inStream, readerSchema, datumReaderFactory));         // (not supporting 1.2 or below, format)
 }
Пример #7
0
 Reader(Stream stream, CreateDatumReader datumReaderFactory)
 {
     _datumReaderFactory = datumReaderFactory;
     Init(stream);
     BlockFinished();
 }