private void Init(Stream stream) { _stream = stream; _header = new Header(); _decoder = new BinaryDecoder(stream); _syncBuffer = new byte[DataFileConstants.SyncSize]; // validate header byte[] firstBytes = new byte[DataFileConstants.AvroHeader.Length]; try { _decoder.ReadFixed(firstBytes); } catch (Exception) { throw new InvalidAvroHeaderException(); } if (!firstBytes.SequenceEqual(DataFileConstants.AvroHeader)) { throw new InvalidAvroHeaderException(); } // read meta data long len = _decoder.ReadMapStart(); if (len > 0) { do { for (long i = 0; i < len; i++) { string key = _decoder.ReadString(); byte[] val = _decoder.ReadBytes(); _header.MetaData.Add(key, val); } } while ((len = _decoder.ReadMapNext()) != 0); } // read in sync data _decoder.ReadFixed(_header.SyncData); // parse schema and set codec _header.Schema = Schema.Parse(GetMetaString(DataFileConstants.SchemaMetadataKey)); _reader = _datumReaderFactory(_header.Schema, _readerSchema ?? _header.Schema); _codec = ResolveCodec(); }
private Codec ResolveCodec() { return(Codec.CreateCodecFromString(GetMetaString(DataFileConstants.CodecMetadataKey))); }