Do you have any problem using code samples from the documentation?
Based on Setting a Document's Content:
// references to the document and file you are working with
Document document;
File file;
document.checkout(ReservationType.EXCLUSIVE, null, null, null);
document.save(RefreshMode.REFRESH);
Document reservation = (Document) document.get_Reservation();
ContentTransfer contentTransfer = Factory.ContentTransfer.createInstance();
InputStream inputStream = new FileInputStream(file);
ContentElementList contentList = Factory.ContentTransfer.createList();
contentTransfer.setCaptureSource(inputStream);
contentList.add(contentTransfer);
reservation.set_ContentElements(contentList);
reservation.save(RefreshMode.REFRESH);
reservation.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
reservation.save(RefreshMode.REFRESH);