private Attachment saveChartImageAsAttachment(ContentEntityObject attachmentContent, String attachmentMimeType, String attachmentFileName, byte[] chartImageBytes, String comment, Attachment currentVersionOfAttachment) throws IOException { Attachment previousVersionOfAttachment = null != currentVersionOfAttachment && currentVersionOfAttachment.isPersistent() ? (Attachment) currentVersionOfAttachment.clone() : null; Attachment chartImageAttachment = null == previousVersionOfAttachment ? new Attachment() : currentVersionOfAttachment; chartImageAttachment.setContainer(attachmentContent); chartImageAttachment.setMediaType(attachmentMimeType); chartImageAttachment.setVersionComment(comment); chartImageAttachment.setFileName(attachmentFileName); chartImageAttachment.setFileSize(chartImageBytes.length); if(null == previousVersionOfAttachment) attachmentContent.addAttachment(chartImageAttachment); attachmentManager.saveAttachment(chartImageAttachment, previousVersionOfAttachment, new ByteArrayInputStream(chartImageBytes)); return chartImageAttachment; }