code: public static List<Data> segment(Data template, InputStream bytes, int segmentSize) throws IOException {
      List<Data> segments = new ArrayList<>();
      byte[] readBytes = readAll(bytes);
      int numBytes = readBytes.length;
      int numPackets = (int) Math.ceil((double) numBytes / segmentSize);
      ByteBuffer buffer = ByteBuffer.wrap(readBytes, 0, numBytes);
      Name.Component lastSegment = Name.Component.fromNumberWithMarker((long) numPackets - 1, NDN_SEGMENT_MARKER);
  
      for (int i = 0; i < numPackets; i++) {
        Data segment = new Data(template);
        segment.getName().appendSegment(i);
        segment.getMetaInfo().setFinalBlockId(lastSegment);
        byte[] content = new byte[Math.min(segmentSize, buffer.remaining())];
        buffer.get(content);
        segment.setContent(new Blob(content));
        segments.add(segment);
      }
  
      return segments;
    }
docs: Segment a stream of bytes into a list of Data packets; this must read all the bytes first in order to determine the
  end segment for FinalBlockId. TODO this could be smarter and only add segments if necessary
  
  @param template the {@link Data} packet to use for the segment {@link Name}, {@link net.named_data.jndn.MetaInfo},
  etc.
  @param bytes an {@link InputStream} to the bytes to segment
  @return a list of segmented {@link Data} packets
  @throws IOException if the stream fails