public static Blob createBlob(LobHelper lobHelper, InputStream origInputStream) { try { final File file = File.createTempFile(TEMP_PREFIX, TEMP_SUFFIX); OutputStream out = new FileOutputStream(file); IOUtils.copy(origInputStream, out); out.close(); origInputStream.close(); long len = file.length(); file.deleteOnExit(); InputStream in = new FileInputStream(file) { @Override public void close() throws IOException { super.close(); file.delete(); } }; return lobHelper.createBlob(in, len); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override @Transactional public Long addAttachment(Long documentId, InputStream is, String fileName, long fileSize) { Document document = findById(documentId); if (document == null) { throw new ValidationException("id"); } checkPermission(document, Access.Permission.WRITE); Attachment attachment = new Attachment(fileName); Session session = (Session) em.getDelegate(); LobHelper lobHelper = session.getLobHelper(); Blob dataBlob = lobHelper.createBlob(is, fileSize); FileBlobBean fileBlobBean = new FileBlobBean(); fileBlobBean.setSourceBlob(dataBlob); attachment.setFileBlobBean(fileBlobBean); attachment.setCreator(Core.currentUser()); document.getAttachmentList().add(attachment); document = super.save(document); createNotifications(document, Subscription.Type.ATTACHMENT); return document.getAttachmentList().get(document.getAttachmentList().size() - 1).getId(); }
@Override public LobHelper getLobHelper() { if ( lobHelper == null ) { lobHelper = new LobHelperImpl( this ); } return lobHelper; }
@Override public LobHelper getLobHelper() { return session.getLobHelper(); }
public void setBinaryFileStream(InputStream inputStream, long length) { if (this.entityManager == null) this.entityManager = entityManager(); Session session = (Session) this.entityManager.getDelegate(); LobHelper helper = session.getLobHelper(); this.binaryFile = helper.createBlob(inputStream, length); }
public void setBinaryFile(byte[] bytes) { if (this.entityManager == null) this.entityManager = entityManager(); Session session = (Session) this.entityManager.getDelegate(); LobHelper helper = session.getLobHelper(); this.binaryFile = helper.createBlob(bytes); }