I am using this code now:
ContentHolder refreshedContentHolder = ContentHelper.service.getContents(document);
ContentItem contentItem = ContentHelper.getPrimary((FormatContentHolder) refreshedContentHolder);
ContentHolderHelper.deleteContents(document, contentItem);
ContentHolderHelper.setContents(document, byteArray, ContentRoleType.PRIMARY, "name", "", false);