/**
       * Closes an HFile writer.
       *
       * @param hfileWriter The writer to close.
       * @throws IOException If there is an error.
       */
      private void closeWriter(HFile.Writer hfileWriter) throws IOException {
        LOG.info("Closing HFile " + hfileWriter.getPath());

        // Write file metadata:
        hfileWriter.appendFileInfo(StoreFile.BULKLOAD_TIME_KEY, toBytes(mLatestTimestamp));

        final String taskAttemptID = mContext.getTaskAttemptID().toString();
        hfileWriter.appendFileInfo(StoreFile.BULKLOAD_TASK_KEY, toBytes(taskAttemptID));
        hfileWriter.appendFileInfo(StoreFile.MAJOR_COMPACTION_KEY, toBytes(true));

        ResourceUtils.closeOrLog(hfileWriter);
      }
 /** {@inheritDoc} */
 @Override
 public void close(TaskAttemptContext context) throws IOException {
   if (null != mWriter) {
     if (mCurrentHFileSize > 0) {
       // Write out a timerange. This is the only Metadata we write out.
       // See: HBASE-8055 and KIJIMR-204.
       mWriter.appendFileInfo(
           StoreFile.TIMERANGE_KEY, WritableUtils.toByteArray(mTimeRangeTracker));
     }
     mTimeRangeTracker = new TimeRangeTracker();
     closeWriter(mWriter);
   }
 }
 /** Create an HFile with the given number of rows with a specified value. */
 public static void createHFile(
     FileSystem fs, Path path, byte[] family, byte[] qualifier, byte[] value, int numRows)
     throws IOException {
   HFileContext context =
       new HFileContextBuilder().withBlockSize(BLOCKSIZE).withCompression(COMPRESSION).build();
   HFile.Writer writer =
       HFile.getWriterFactory(conf, new CacheConfig(conf))
           .withPath(fs, path)
           .withFileContext(context)
           .create();
   long now = System.currentTimeMillis();
   try {
     // subtract 2 since iterateOnSplits doesn't include boundary keys
     for (int i = 0; i < numRows; i++) {
       KeyValue kv = new KeyValue(rowkey(i), family, qualifier, now, value);
       writer.append(kv);
     }
     writer.appendFileInfo(StoreFile.BULKLOAD_TIME_KEY, Bytes.toBytes(now));
   } finally {
     writer.close();
   }
 }