docs: protected static PreparedAttachment prepareAttachment(String attachmentsDir,
                                                            AttachmentStreamFactory attachmentStreamFactory, Attachment attachment, long length, long encodedLength) throws AttachmentException {
          PreparedAttachment pa = new PreparedAttachment(attachment, attachmentsDir, length, attachmentStreamFactory);
          // check the length on disk is correct:
          // - plain encoding, length on disk is signalled by the "length" metadata property
          // - all other encodings, length on disk is signalled by the "encoded_length" metadata property
          if (pa.attachment.encoding == Attachment.Encoding.Plain) {
              if (pa.length != length) {
                  throw new AttachmentNotSavedException(String.format("Actual length of %d does not equal expected length of %d", pa.length, length));
              }
          } else {
              if (pa.encodedLength != encodedLength) {
                  throw new AttachmentNotSavedException(String.format("Actual encoded length of %d does not equal expected encoded length of %d", pa.encodedLength, pa.length));
              }
          }
          return pa;
      }