int length = comment.length();
  private void writeHeaderFrames()  {    if (comment.length() > 247) {      comment = comment.substring(0, 247);    }    int length = comment.length();    while ((buf.length - count) < length + 144) {      // grow buffer (108 = 28 + 80 = size of Ogg Header Frame)      //             (length + 8 + 28 = size of Comment Frame)       int nsz = buf.length * 2;      byte[] nbuf = new byte[nsz];      System.arraycopy(buf, 0, nbuf, 0, count);      buf = nbuf;    }    // writes the OGG header page    writeOggPageHeader(1, 2);    buf[count+27] = 80; // size of SpeexHeader    /* writes the Speex header */    AudioFileWriter.writeSpeexHeader(buf, oggCount, encoder.getSampleRate(),                                     mode, encoder.getChannels(),                                     encoder.getEncoder().getVbr(),                                     framesPerPacket);    oggCount += 80;    /* Calculate Checksum */    int chksum = OggCrc.checksum(0, buf, count, oggCount-count);    AudioFileWriter.writeInt(buf, count+22, chksum);    count = oggCount;    // writes the OGG header page    writeOggPageHeader(1, 0);    buf[count+27] = (byte)(0xff & length+8); // size of CommentHeader    /* writes the OGG comment page */    AudioFileWriter.writeSpeexComment(buf, oggCount, comment);    oggCount += length+8;    /* Calculate Checksum */    chksum = OggCrc.checksum(0, buf, count, oggCount-count);    AudioFileWriter.writeInt(buf, count+22, chksum);    count = oggCount;    // reset variables for a new page.    packetCount = 0;  }