Exemple #1
0
 /// <summary>
 /// Create a Data Block and obtain an output stream for adding data into the
 /// block.
 /// </summary>
 /// <remarks>
 /// Create a Data Block and obtain an output stream for adding data into the
 /// block. There can only be one BlockAppender stream active at any time.
 /// Data Blocks may not be created after the first Meta Blocks. The caller
 /// must call BlockAppender.close() to conclude the block creation.
 /// </remarks>
 /// <returns>The BlockAppender stream</returns>
 /// <exception cref="System.IO.IOException"/>
 public virtual BCFile.Writer.BlockAppender PrepareDataBlock()
 {
     if (blkInProgress == true)
     {
         throw new InvalidOperationException("Cannot create Data Block until previous block is closed."
                                             );
     }
     if (metaBlkSeen == true)
     {
         throw new InvalidOperationException("Cannot create Data Block after Meta Blocks."
                                             );
     }
     BCFile.Writer.DataBlockRegister dbr = new BCFile.Writer.DataBlockRegister(this);
     BCFile.Writer.WBlockState       wbs = new BCFile.Writer.WBlockState(GetDefaultCompressionAlgorithm
                                                                             (), @out, fsOutputBuffer, conf);
     BCFile.Writer.BlockAppender ba = new BCFile.Writer.BlockAppender(this, dbr, wbs);
     blkInProgress = true;
     return(ba);
 }
Exemple #2
0
 /// <exception cref="System.IO.IOException"/>
 /// <exception cref="Org.Apache.Hadoop.IO.File.Tfile.MetaBlockAlreadyExists"/>
 private BCFile.Writer.BlockAppender PrepareMetaBlock(string name, Compression.Algorithm
                                                      compressAlgo)
 {
     if (blkInProgress == true)
     {
         throw new InvalidOperationException("Cannot create Meta Block until previous block is closed."
                                             );
     }
     if (metaIndex.GetMetaByName(name) != null)
     {
         throw new MetaBlockAlreadyExists("name=" + name);
     }
     BCFile.Writer.MetaBlockRegister mbr = new BCFile.Writer.MetaBlockRegister(this, name
                                                                               , compressAlgo);
     BCFile.Writer.WBlockState wbs = new BCFile.Writer.WBlockState(compressAlgo, @out,
                                                                   fsOutputBuffer, conf);
     BCFile.Writer.BlockAppender ba = new BCFile.Writer.BlockAppender(this, mbr, wbs);
     blkInProgress = true;
     metaBlkSeen   = true;
     return(ba);
 }
Exemple #3
0
 /// <summary>Close the BCFile Writer.</summary>
 /// <remarks>
 /// Close the BCFile Writer. Attempting to use the Writer after calling
 /// <code>close</code> is not allowed and may lead to undetermined results.
 /// </remarks>
 /// <exception cref="System.IO.IOException"/>
 public virtual void Close()
 {
     if (closed == true)
     {
         return;
     }
     try
     {
         if (errorCount == 0)
         {
             if (blkInProgress == true)
             {
                 throw new InvalidOperationException("Close() called with active block appender.");
             }
             // add metaBCFileIndex to metaIndex as the last meta block
             BCFile.Writer.BlockAppender appender = PrepareMetaBlock(BCFile.DataIndex.BlockName
                                                                     , GetDefaultCompressionAlgorithm());
             try
             {
                 dataIndex.Write(appender);
             }
             finally
             {
                 appender.Close();
             }
             long offsetIndexMeta = @out.GetPos();
             metaIndex.Write(@out);
             // Meta Index and the trailing section are written out directly.
             @out.WriteLong(offsetIndexMeta);
             ApiVersion.Write(@out);
             BCFile.Magic.Write(@out);
             @out.Flush();
         }
     }
     finally
     {
         closed = true;
     }
 }