Example #1
0
  /**
   * Writes the specified index to the associated output stream. This may be called multiple times
   * in order to write multiple indexes.
   *
   * @param index the index to write to the stream
   * @return the number of bytes written to the stream
   * @throws IOException if any i/o error occurs
   */
  public int write(Index index) throws IOException {
    PackedDataOutputStream stream = new PackedDataOutputStream(new BufferedOutputStream(out));
    stream.writeInt(MAGIC);
    stream.writeByte(VERSION);

    buildTables(index);
    writeClassTable(stream);
    writeStringTable(stream);
    writeClasses(stream, index);
    stream.flush();
    return stream.size();
  }