code: public static <PS, SEG, S> Codec<StyledDocument<PS, SEG, S>> codec(Codec<PS> pCodec, Codec<StyledSegment<SEG, S>> segCodec,
                                                                         SegmentOps<SEG, S> segmentOps) {
          return new Codec<StyledDocument<PS, SEG, S>>() {
              private final Codec<List<Paragraph<PS, SEG, S>>> codec = Codec.listCodec(
                      paragraphCodec(pCodec, segCodec, segmentOps)
              );
  
              @Override
              public String getName() {
                  return "application/richtextfx-styled-document<" + pCodec.getName() + ";" + segCodec.getName() + ">";
              }
  
              @Override
              public void encode(DataOutputStream os, StyledDocument<PS, SEG, S> doc) throws IOException {
                  codec.encode(os, doc.getParagraphs());
              }
  
              @Override
              public StyledDocument<PS, SEG, S> decode(DataInputStream is) throws IOException {
                  return new ReadOnlyStyledDocument<>(codec.decode(is));
              }
  
          };
      }
docs: Defines a codec for serializing a {@link ReadOnlyStyledDocument}.
  
  @param pCodec the codec for serializing a {@link Paragraph}
  @param segCodec the codec for serializing a {@link StyledSegment}
  @param segmentOps the operations object for operating on segments
  
  @param <PS> The type of the paragraph style.
  @param <SEG> The type of the segments in the paragraph (e.g. {@link String}).
  @param <S> The type of the style of individual segments.