// Creates the ByteBuffer for the ogg tag
  public void create(Tag tag, ByteBuffer buf, List fields, int tagSize, int padding)
      throws UnsupportedEncodingException {
    String vendorString = ((OggTag) tag).getVendor();
    int vendorLength = Utils.getUTF8Bytes(vendorString).length;
    buf.put(
        new byte[] {
          (byte) (vendorLength & 0xFF),
          (byte) ((vendorLength & 0xFF00) >> 8),
          (byte) ((vendorLength & 0xFF0000) >> 16),
          (byte) ((vendorLength & 0xFF000000) >> 24)
        });
    buf.put(Utils.getUTF8Bytes(vendorString));

    // [user comment list length]
    int listLength = fields.size();
    byte[] b = new byte[4];
    b[3] = (byte) ((listLength & 0xFF000000) >> 24);
    b[2] = (byte) ((listLength & 0x00FF0000) >> 16);
    b[1] = (byte) ((listLength & 0x0000FF00) >> 8);
    b[0] = (byte) (listLength & 0x000000FF);
    buf.put(b);

    Iterator it = fields.iterator();
    while (it.hasNext()) {
      buf.put((byte[]) it.next());
    }
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  @SuppressWarnings("all")
  @Override
  public boolean writeTo(ByteBuffer buf) {
    commState.setBuffer(buf);

    if (!super.writeTo(buf)) return false;

    if (!commState.typeWritten) {
      if (!commState.putByte(directType())) return false;

      commState.typeWritten = true;
    }

    switch (commState.idx) {
      case 8:
        if (nearKeyBytes != null) {
          if (commState.it == null) {
            if (!commState.putInt(nearKeyBytes.size())) return false;

            commState.it = nearKeyBytes.iterator();
          }

          while (commState.it.hasNext() || commState.cur != NULL) {
            if (commState.cur == NULL) commState.cur = commState.it.next();

            if (!commState.putByteArray((byte[]) commState.cur)) return false;

            commState.cur = NULL;
          }

          commState.it = null;
        } else {
          if (!commState.putInt(-1)) return false;
        }

        commState.idx++;
    }

    return true;
  }