private ByteBuffer writeHeaderToBuffer(int padding,int size) throws IOException {
  unsynchronization=false;
  extended=false;
  experimental=false;
  footer=false;
  ByteBuffer headerBuffer=ByteBuffer.allocate(TAG_HEADER_LENGTH);
  headerBuffer.put(TAG_ID);
  headerBuffer.put(getMajorVersion());
  headerBuffer.put(getRevision());
  byte flagsByte=0;
  if (isUnsynchronization()) {
    flagsByte|=MASK_V24_UNSYNCHRONIZATION;
  }
  if (extended) {
    flagsByte|=MASK_V24_EXTENDED_HEADER;
  }
  if (experimental) {
    flagsByte|=MASK_V24_EXPERIMENTAL;
  }
  if (footer) {
    flagsByte|=MASK_V24_FOOTER_PRESENT;
  }
  headerBuffer.put(flagsByte);
  int additionalHeaderSize=0;
  if (extended) {
    additionalHeaderSize+=TAG_EXT_HEADER_LENGTH;
    if (updateTag) {
      additionalHeaderSize+=TAG_EXT_HEADER_UPDATE_LENGTH;
    }
    if (crcDataFlag) {
      additionalHeaderSize+=TAG_EXT_HEADER_CRC_LENGTH;
    }
    if (tagRestriction) {
      additionalHeaderSize+=TAG_EXT_HEADER_RESTRICTION_LENGTH;
    }
  }
  headerBuffer.put(ID3SyncSafeInteger.valueToBuffer(padding + size + additionalHeaderSize));
  ByteBuffer extHeaderBuffer=null;
  if (extended) {
    int extendedSize=TAG_EXT_HEADER_LENGTH;
    if (updateTag) {
      extendedSize+=TAG_EXT_HEADER_UPDATE_LENGTH;
    }
    if (crcDataFlag) {
      extendedSize+=TAG_EXT_HEADER_CRC_LENGTH;
    }
    if (tagRestriction) {
      extendedSize+=TAG_EXT_HEADER_RESTRICTION_LENGTH;
    }
    extHeaderBuffer=ByteBuffer.allocate(extendedSize);
    extHeaderBuffer.putInt(extendedSize);
    extHeaderBuffer.put((byte)TAG_EXT_NUMBER_BYTES_DATA_LENGTH);
    byte extFlag=0;
    if (updateTag) {
      extFlag|=MASK_V24_TAG_UPDATE;
    }
    if (crcDataFlag) {
      extFlag|=MASK_V24_CRC_DATA_PRESENT;
    }
    if (tagRestriction) {
      extFlag|=MASK_V24_TAG_RESTRICTIONS;
    }
    extHeaderBuffer.put(extFlag);
    if (updateTag) {
      extHeaderBuffer.put((byte)0);
    }
    if (crcDataFlag) {
      extHeaderBuffer.put((byte)TAG_EXT_HEADER_CRC_DATA_LENGTH);
      extHeaderBuffer.put((byte)0);
      extHeaderBuffer.putInt(crcData);
    }
    if (tagRestriction) {
      extHeaderBuffer.put((byte)TAG_EXT_HEADER_RESTRICTION_DATA_LENGTH);
      extHeaderBuffer.put((byte)0);
    }
  }
  if (extHeaderBuffer != null) {
    extHeaderBuffer.flip();
    headerBuffer.put(extHeaderBuffer);
  }
  headerBuffer.flip();
  return headerBuffer;
}

private ByteBuffer writeHeaderToBuffer ( int padding , int size ) throws IOException { unsynchronization = false ; extended = false ; experimental = false ; footer = false ; ByteBuffer headerBuffer = ByteBuffer . allocate ( TAG_HEADER_LENGTH ) ; headerBuffer . put ( TAG_ID ) ; headerBuffer . put ( getMajorVersion ( ) ) ; headerBuffer . put ( getRevision ( ) ) ; byte flagsByte = 0 ; if ( isUnsynchronization ( ) ) { flagsByte |= MASK_V24_UNSYNCHRONIZATION ; } if ( extended ) { flagsByte |= MASK_V24_EXTENDED_HEADER ; } if ( experimental ) { flagsByte |= MASK_V24_EXPERIMENTAL ; } if ( footer ) { flagsByte |= MASK_V24_FOOTER_PRESENT ; } headerBuffer . put ( flagsByte ) ; int additionalHeaderSize = 0 ; if ( extended ) { additionalHeaderSize += TAG_EXT_HEADER_LENGTH ; if ( updateTag ) { additionalHeaderSize += TAG_EXT_HEADER_UPDATE_LENGTH ; } if ( crcDataFlag ) { additionalHeaderSize += TAG_EXT_HEADER_CRC_LENGTH ; } if ( tagRestriction ) { additionalHeaderSize += TAG_EXT_HEADER_RESTRICTION_LENGTH ; } } headerBuffer . put ( ID3SyncSafeInteger . valueToBuffer ( padding + size + additionalHeaderSize ) ) ; ByteBuffer extHeaderBuffer = null ; if ( extended ) { int extendedSize = TAG_EXT_HEADER_LENGTH ; if ( updateTag ) { extendedSize += TAG_EXT_HEADER_UPDATE_LENGTH ; } if ( crcDataFlag ) { extendedSize += TAG_EXT_HEADER_CRC_LENGTH ; } if ( tagRestriction ) { extendedSize += TAG_EXT_HEADER_RESTRICTION_LENGTH ; } extHeaderBuffer = ByteBuffer . allocate ( extendedSize ) ; extHeaderBuffer . putInt ( extendedSize ) ; extHeaderBuffer . put ( ( byte ) TAG_EXT_NUMBER_BYTES_DATA_LENGTH ) ; byte extFlag = 0 ; if ( updateTag ) { extFlag |= MASK_V24_TAG_UPDATE ; } if ( crcDataFlag ) { extFlag |= MASK_V24_CRC_DATA_PRESENT ; } if ( tagRestriction ) { extFlag |= MASK_V24_TAG_RESTRICTIONS ; } extHeaderBuffer . put ( extFlag ) ; if ( updateTag ) { extHeaderBuffer . put ( ( byte ) 0 ) ; } if ( crcDataFlag ) { extHeaderBuffer . put ( ( byte ) TAG_EXT_HEADER_CRC_DATA_LENGTH ) ; extHeaderBuffer . put ( ( byte ) 0 ) ; extHeaderBuffer . putInt ( crcData ) ; } if ( tagRestriction ) { extHeaderBuffer . put ( ( byte ) TAG_EXT_HEADER_RESTRICTION_DATA_LENGTH ) ; extHeaderBuffer . put ( ( byte ) 0 ) ; } } if ( extHeaderBuffer != null ) { extHeaderBuffer . flip ( ) ; headerBuffer . put ( extHeaderBuffer ) ; } headerBuffer . flip ( ) ; return headerBuffer ; }
write the id3 header to the bytebuffer . todo calculate the cyc data check todo reintroduce extended header
