CompositeMetadataCodec { @Nullable public static CharSequence decodeMimeTypeFromMimeBuffer(ByteBuf flyweightMimeBuffer) { if (flyweightMimeBuffer.readableBytes() < 2) { throw new IllegalStateException("unable to decode explicit MIME type"); } flyweightMimeBuffer.skipBytes(1); int mimeStringLength = flyweightMimeBuffer.readableBytes(); return flyweightMimeBuffer.readCharSequence(mimeStringLength, CharsetUtil.US_ASCII); } private  CompositeMetadataCodec(); static int computeNextEntryIndex(
      int currentEntryIndex, ByteBuf headerSlice, ByteBuf contentSlice); static ByteBuf[] decodeMimeAndContentBuffersSlices(
      ByteBuf compositeMetadata, int entryIndex, boolean retainSlices); static byte decodeMimeIdFromMimeBuffer(ByteBuf mimeBuffer); @Nullable static CharSequence decodeMimeTypeFromMimeBuffer(ByteBuf flyweightMimeBuffer); static void encodeAndAddMetadata(
      CompositeByteBuf compositeMetaData,
      ByteBufAllocator allocator,
      String customMimeType,
      ByteBuf metadata); static void encodeAndAddMetadata(
      CompositeByteBuf compositeMetaData,
      ByteBufAllocator allocator,
      WellKnownMimeType knownMimeType,
      ByteBuf metadata); static void encodeAndAddMetadataWithCompression(
      CompositeByteBuf compositeMetaData,
      ByteBufAllocator allocator,
      String mimeType,
      ByteBuf metadata); static boolean hasEntry(ByteBuf compositeMetadata, int entryIndex); static boolean isWellKnownMimeType(ByteBuf header);  }
@Test void decodeStringNullIfLengthOne() { ByteBuf fakeTypeBuffer = Unpooled.buffer(2); fakeTypeBuffer.writeByte(1); assertThatIllegalStateException() .isThrownBy(() -> decodeMimeTypeFromMimeBuffer(fakeTypeBuffer)); }
@Test void decodeStringNullIfLengthZero() { ByteBuf fakeTypeBuffer = Unpooled.buffer(2); assertThatIllegalStateException() .isThrownBy(() -> decodeMimeTypeFromMimeBuffer(fakeTypeBuffer)); }
@Test void decodeTypeSkipsFirstByte() { ByteBuf fakeTypeBuffer = Unpooled.buffer(2); fakeTypeBuffer.writeByte(128); fakeTypeBuffer.writeCharSequence("example", CharsetUtil.US_ASCII); assertThat(decodeMimeTypeFromMimeBuffer(fakeTypeBuffer)).hasToString("example"); }