cool-core/src/main/java/com/nus/cool/core/io/writestore/ChunkWS.java
@Override
  public int writeTo(DataOutput out) throws IOException {
    int bytesWritten = 0;
    int[] offsets = new int[this.fields.length];

    // Calculate offset of field
    // Write field
    for (int i = 0; i < this.fields.length; i++) {
      offsets[i] = this.offset + bytesWritten;
      bytesWritten += this.fields[i].writeTo(out);
    }

    // Calculate offset of header
    int chunkHeadOff = this.offset + bytesWritten;
    // Write chunkType (DATA)
    out.write(ChunkType.DATA.ordinal());
    bytesWritten++;
    // Write #records
    out.writeInt(IntegerUtil.toNativeByteOrder(this.count));
    bytesWritten += Ints.BYTES;
    // Write #fields
    out.writeInt(IntegerUtil.toNativeByteOrder(this.fields.length));
    bytesWritten += Ints.BYTES;
    // Write field offsets
    for (int offset : offsets) {
      out.writeInt(IntegerUtil.toNativeByteOrder(offset));
      bytesWritten += Ints.BYTES;
    }

    // Write header offset
    out.writeInt(IntegerUtil.toNativeByteOrder(chunkHeadOff));
    bytesWritten += Ints.BYTES;
    return bytesWritten;
  }
/**
   * Write ChunkWS to out stream and return bytes written
   *
   * @param out stream can write data to output stream
   * @return bytes written
   * @throws IOException If an I/O error occurs
   */
Write ChunkWS to out stream and return bytes written
@param out stream can write data to output stream
@return bytes written
@throws IOException If an I/O error occurs
Write ChunkWS to out stream and return bytes written @param out stream can write data to output stream @return bytes written @throws IOException If an I / O error occurs
@Override
  public int writeTo(DataOutput out) throws IOException {
    int bytesWritten = 0;
    int[] offsets = new int[this.fields.length];
    for (int i = 0; i < this.fields.length; i++) {
      offsets[i] = this.offset + bytesWritten;
      bytesWritten += this.fields[i].writeTo(out);
    }
    int chunkHeadOff = this.offset + bytesWritten;
    out.write(ChunkType.DATA.ordinal());
    bytesWritten++;
    out.writeInt(IntegerUtil.toNativeByteOrder(this.count));
    bytesWritten += Ints.BYTES;
    out.writeInt(IntegerUtil.toNativeByteOrder(this.fields.length));
    bytesWritten += Ints.BYTES;
     offsets
    for (int offset : offsets) {
      out.writeInt(IntegerUtil.toNativeByteOrder(offset));
      bytesWritten += Ints.BYTES;
    }
    out.writeInt(IntegerUtil.toNativeByteOrder(chunkHeadOff));
    bytesWritten += Ints.BYTES;
    return bytesWritten;
  }
@ Override public int writeTo ( DataOutput out ) throws IOException { int bytesWritten = 0 ; int [ ] offsets = new int [ this . fields . length ] ; for ( int i = 0 ; i < this . fields . length ; i ++ ) { offsets [ i ] = this . offset + bytesWritten ; bytesWritten += this . fields [ i ] . writeTo ( out ) ; } int chunkHeadOff = this . offset + bytesWritten ; out . write ( ChunkType . DATA . ordinal ( ) ) ; bytesWritten ++ ; out . writeInt ( IntegerUtil . toNativeByteOrder ( this . count ) ) ; bytesWritten += Ints . BYTES ; out . writeInt ( IntegerUtil . toNativeByteOrder ( this . fields . length ) ) ; bytesWritten += Ints . BYTES ; for ( int offset : offsets ) { out . writeInt ( IntegerUtil . toNativeByteOrder ( offset ) ) ; bytesWritten += Ints . BYTES ; } out . writeInt ( IntegerUtil . toNativeByteOrder ( chunkHeadOff ) ) ; bytesWritten += Ints . BYTES ; return bytesWritten ; }
Write ChunkWS to out stream and return bytes written
 @param out stream can write data to output stream
 @return bytes written
 @throws IOException If an I/O error occurs
Write ChunkWS to out stream and return bytes written @param out stream can write data to output stream @return bytes written @throws IOException If an I / O error occurs
// Calculate offset of field // Write field // Calculate offset of header // Write chunkType (DATA) // Write #records // Write #fields // Write field offsets // Write header offset