Example usage for org.hibernate.engine.jdbc StreamUtils copy

List of usage examples for org.hibernate.engine.jdbc StreamUtils copy

Introduction

In this page you can find the example usage for org.hibernate.engine.jdbc StreamUtils copy.

Prototype

public static long copy(Reader reader, Writer writer) throws IOException 

Source Link

Document

Copy the reader to the writer.

Usage

From source file:conddb.svc.dao.repositories.impl.PayloadDataJCRImpl.java

License:Open Source License

@Override
public PayloadData save(PayloadData entity) {
    String id = entity.getHash();
    log.info("Inserting payload data using hash " + entity.getHash());
    try {//from   w  ww  .  j  av a 2  s  . co  m
        Resource resource = new FileSystemResource(rootpath + "/" + id);
        log.info("Use resource filename " + resource.getFilename() + " in path " + resource.getURI().getPath());
        File outputfile = resource.getFile();
        BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(outputfile));
        //FIXME: need to implement something to copy a file in the correct location
        //       the source location should be passed as an argument ?
        String inputfile = entity.getUri();
        File ifile = new File(inputfile);
        BufferedInputStream istream = new BufferedInputStream(new FileInputStream(ifile));
        StreamUtils.copy(istream, stream);
        //         stream.write(entity.getData());
        istream.close();
        stream.close();
        log.info("Writing of file is ended");
        entity.setUri(outputfile.getAbsolutePath());
        return entity;
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:org.beangle.commons.orm.hibernate.HibernateEntityDao.java

License:Open Source License

public Blob createBlob(InputStream inputStream) {
    try {/*  w ww  . jav a 2s .c om*/
        ByteArrayOutputStream buffer = new ByteArrayOutputStream(inputStream.available());
        StreamUtils.copy(inputStream, buffer);
        return Hibernate.getLobCreator(getSession()).createBlob(buffer.toByteArray());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}