/// <summary>Constructor</summary> /// <param name="fin">FS input stream.</param> /// <param name="fileLength">Length of the corresponding file</param> /// <exception cref="System.IO.IOException"/> public Reader(FSDataInputStream fin, long fileLength, Configuration conf) { this.@in = fin; this.conf = conf; // move the cursor to the beginning of the tail, containing: offset to the // meta block index, version and magic fin.Seek(fileLength - BCFile.Magic.Size() - Utils.Version.Size() - long.Size / byte .Size); long offsetIndexMeta = fin.ReadLong(); version = new Utils.Version(fin); BCFile.Magic.ReadAndVerify(fin); if (!version.CompatibleWith(BCFile.ApiVersion)) { throw new RuntimeException("Incompatible BCFile fileBCFileVersion."); } // read meta index fin.Seek(offsetIndexMeta); metaIndex = new BCFile.MetaIndex(fin); // read data:BCFile.index, the data block index BCFile.Reader.BlockReader blockR = GetMetaBlock(BCFile.DataIndex.BlockName); try { dataIndex = new BCFile.DataIndex(blockR); } finally { blockR.Close(); } }
/// <summary>Constructor</summary> /// <param name="fout">FS output stream.</param> /// <param name="compressionName"> /// Name of the compression algorithm, which will be used for all /// data blocks. /// </param> /// <exception cref="System.IO.IOException"/> /// <seealso cref="Compression.GetSupportedAlgorithms()"/> public Writer(FSDataOutputStream fout, string compressionName, Configuration conf ) { if (fout.GetPos() != 0) { throw new IOException("Output file not at zero offset."); } this.@out = fout; this.conf = conf; dataIndex = new BCFile.DataIndex(compressionName); metaIndex = new BCFile.MetaIndex(); fsOutputBuffer = new BytesWritable(); BCFile.Magic.Write(fout); }