code: public void write(OutputStream stream) throws IOException {
          //Creating buffer
          ByteArrayOutputStream bos = new ByteArrayOutputStream();
  
          //Creating compressed output data stream
          DeflaterOutputStream deflate = new DeflaterOutputStream(bos);
          DataOutputStream dataStream = new DataOutputStream(deflate);
  
          //Writing index step
          dataStream.writeLong(step);
  
          //Writing boundaries of index
          dataStream.writeLong(getStartingRecordNumber());
          dataStream.writeLong(getLastRecordNumber());
  
          //Writing number of meta-records
          dataStream.writeInt(metadata.size());
  
          //Writing meta records
          for (Map.Entry<String, String> e : metadata.entrySet()) {
              dataStream.writeUTF(e.getKey());
              dataStream.writeUTF(e.getValue());
          }
  
          //Writing number of entries
          dataStream.writeInt(index.size());
  
          //Writing index
          long lastValue = 0, v;
          for (int i = 0; i < index.size(); ++i) {
              IOUtil.writeRawVarint64(dataStream, (v = index.get(i)) - lastValue);
              lastValue = v;
          }
  
          //Flushing gzip output stream to underlying stream
          deflate.finish();
  
          //Creating raw output stream
          DataOutputStream raw = new DataOutputStream(stream);
  
          //Writing non-compressed magic number
          raw.writeInt(MAGIC);
  
          //Writing index size
          raw.writeInt(bos.size());
  
          //Writes index
          raw.write(bos.toByteArray());
      }
docs: Writes this index to specified output stream.
  
  @param stream output stream
  @throws IOException