@Override
    public OggPacket write() {
        // Serialise the comments
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            // Pad for the header (size isn't known yet, so can't fully write)
            byte[] headerPadding = new byte[getHeaderSize()];
            baos.write(headerPadding);

            // Do the vendor string
            IOUtils.writeUTF8WithLength(baos, vendor);

            // Next is the number of comments
            int numComments = 0;
            for(List<String> c : comments.values()) {
                numComments += c.size();
            }
            IOUtils.writeInt4(baos, numComments);

            // Write out the tags. While the spec doesn't require
            //  an order, unit testing does!
            String[] tags = comments.keySet().toArray(new String[comments.size()]);
            Arrays.sort(tags);
            for(String tag : tags) {
                for(String value : comments.get(tag)) {
                    String comment = tag + '=' + value;

                    IOUtils.writeUTF8WithLength(baos, comment);
                }
            }

            // Do a header, if required for the format
            populateMetadataFooter(baos);
        } catch(IOException e) {
            // Should never happen!
            throw new RuntimeException(e);
        }

        // Now fill in the header
        byte[] data = baos.toByteArray();
        populateMetadataHeader(data, data.length);

        // Record the data
        setData(data);

        // Now write
        return super.write();
    }