Id3Decoder implements MetadataDecoder { private static PrivFrame decodePrivFrame(ParsableByteArray id3Data, int frameSize) throws UnsupportedEncodingException { byte[] data = new byte[frameSize]; id3Data.readBytes(data, 0, frameSize); int ownerEndIndex = indexOfZeroByte(data, 0); String owner = new String(data, 0, ownerEndIndex, "ISO-8859-1"); int privateDataStartIndex = ownerEndIndex + 1; byte[] privateData = copyOfRangeIfValid(data, privateDataStartIndex, data.length); return new PrivFrame(owner, privateData); } Id3Decoder();  Id3Decoder(@Nullable FramePredicate framePredicate); @SuppressWarnings("ByteBufferBackingArray") @Override @Nullable Metadata decode(MetadataInputBuffer inputBuffer); @Nullable Metadata decode(byte[] data, int size); static final FramePredicate NO_FRAMES_PREDICATE; static final int ID3_TAG; static final int ID3_HEADER_LENGTH; }
@Test public void testDecodePrivFrame() { byte[] rawId3 = buildSingleFrameTag("PRIV", new byte[] {116, 101, 115, 116, 0, 1, 2, 3, 4}); Id3Decoder decoder = new Id3Decoder(); Metadata metadata = decoder.decode(rawId3, rawId3.length); assertThat(metadata.length()).isEqualTo(1); PrivFrame privFrame = (PrivFrame) metadata.get(0); assertThat(privFrame.owner).isEqualTo("test"); assertThat(privFrame.privateData).isEqualTo(new byte[]{1, 2, 3, 4}); rawId3 = buildSingleFrameTag("PRIV", new byte[0]); metadata = decoder.decode(rawId3, rawId3.length); assertThat(metadata.length()).isEqualTo(1); privFrame = (PrivFrame) metadata.get(0); assertThat(privFrame.owner).isEmpty(); assertThat(privFrame.privateData).isEqualTo(new byte[0]); }