Example usage for org.hibernate LobHelper createBlob

List of usage examples for org.hibernate LobHelper createBlob

Introduction

In this page you can find the example usage for org.hibernate LobHelper createBlob.

Prototype

public Blob createBlob(InputStream stream, long length);

Source Link

Document

Create a new Blob from stream data.

Usage

From source file:de.hska.ld.content.service.impl.DocumentServiceImpl.java

License:Apache License

@Override
@Transactional/*ww w.  j  ava 2s.  c  om*/
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();
}

From source file:fr.univrouen.poste.domain.BigFile.java

License:Apache License

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);
}

From source file:org.openeos.attachments.internal.dao.AttachmentUtils.java

License:Apache License

public static Blob createBlob(LobHelper lobHelper, InputStream origInputStream) {
    try {/*from  w ww  .j ava 2 s  .co m*/
        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);
    }
}