List of usage examples for java.sql Blob getBinaryStream
java.io.InputStream getBinaryStream() throws SQLException;
From source file:com.orangeandbronze.jblubble.jdbc.JdbcBlobstoreService.java
@Override public void readBlob(BlobKey blobKey, BlobstoreReadCallback callback) throws IOException, BlobstoreException { readBlobInternal(blobKey, new BlobHandler() { @Override/*from w ww . ja va2 s . com*/ public void handleBlob(Blob blob) throws SQLException, IOException { try (InputStream in = new BufferedInputStream(blob.getBinaryStream(), getBufferSize())) { callback.readInputStream(in); } } }); }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoFileResource.java
protected void copyDataTo(FileResource fileRes) { Blob blob = getData(); if (blob == null) { fileRes.setData(null);/*from w ww. j a va 2 s.c om*/ } else { try { fileRes.readData(blob.getBinaryStream()); } catch (SQLException e) { log.error("Error while reading data blob of \"" + getResourceURI() + "\"", e); throw new JSExceptionWrapper(e); } } }
From source file:com.orangeandbronze.jblubble.jdbc.springframework.SpringJdbcBlobstoreService.java
@Override public void readBlob(BlobKey blobKey, BlobstoreReadCallback callback) throws IOException, BlobstoreException { try {//w w w .ja v a2 s .c om jdbcTemplate.query(getSelectContentByIdSql(), (rs) -> { if (!rs.next()) { throw new BlobstoreException("Blob not found: " + blobKey); } Blob blob = rs.getBlob("content"); try { try (InputStream in = blob.getBinaryStream()) { callback.readInputStream(in); return true; } catch (IOException ioe) { throw new BlobstoreException("Error while reading blob", ioe); } } finally { blob.free(); } }, Long.valueOf(blobKey.stringValue())); } catch (DataAccessException e) { throw new BlobstoreException(e); } }
From source file:biz.taoconsulting.dominodav.resource.DAVResourceJDBC.java
/** * /**//w w w . jav a 2 s. c o m * * @see biz.taoconsulting.dominodav.resource.DAVAbstractResource#getStream() */ public InputStream getStream() { Connection conn = null; Statement stmt = null; InputStream blobStream = null; try { Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); DataSource ds = (DataSource) // THe internal address of a JDBC source is the data source envCtx.lookup(this.repositoryMeta.getInternalAddress()); conn = ds.getConnection(); stmt = conn.createStatement(); // XXX: THat is plain wrong -- need to rework the JDBC data source // query ResultSet rs = stmt.executeQuery( "select f.fil_blocksize,f.fil_contents_blob from ibkuis_pp_files f where f.fil_id=" + this.getDBFileID()); if (rs.next()) { Blob blob = rs.getBlob(2); blobStream = blob.getBinaryStream(); } } catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); if (conn != null) conn.close(); } catch (SQLException e) { /** Exception handling **/ } } return blobStream; }
From source file:com.npower.dm.hibernate.entity.ModelEntity.java
public InputStream getIconInputStream() throws DMException { try {/*from w ww. ja v a2 s . com*/ Blob iconBlob = this.getIcon(); if (iconBlob != null) { return iconBlob.getBinaryStream(); } else { return null; } } catch (SQLException e) { throw new DMException(e); } }
From source file:edu.wustl.bulkoperator.action.BulkHandler.java
/** * This method call to write Job message. * @param jobMessage jobMessage/*from w w w .j av a2 s .c o m*/ * @param response HttpServletResponse * @throws IOException IOException * @throws SQLException SQLException */ private void writeJobMessage(JobMessage jobMessage, HttpServletResponse response) throws IOException, SQLException { OutputStream ost = response.getOutputStream(); ObjectOutputStream objOutputStream = new ObjectOutputStream(ost); JobDetails jobDetails = jobMessage.getJobData(); if (jobDetails != null && jobDetails.getLogFile() != null) { Blob blob = jobDetails.getLogFile(); InputStream inputStream = blob.getBinaryStream(); int count = 0; final byte[] buf = new byte[Long.valueOf(blob.length()).intValue()]; while (count > -1) { count = inputStream.read(buf); } (jobMessage.getJobData()).setLogFilesBytes(buf); } objOutputStream.writeObject(jobMessage); }
From source file:com.sr.controller.MahasiswaController.java
@RequestMapping("/lihatfoto") public void lihatfoto(@RequestParam("nim") String nim, HttpServletRequest request, HttpServletResponse response) {//from www . j a v a2 s .co m try { Blob blob = mhs.getFotoByNim(nim); response.setContentType("image/jpg"); response.setContentLength((int) blob.length()); InputStream inputStream = blob.getBinaryStream(); OutputStream os = response.getOutputStream(); byte buf[] = new byte[(int) blob.length()]; inputStream.read(buf); os.write(buf); os.close(); } catch (IOException ex) { System.out.println("IOException " + ex.getMessage()); } catch (SQLException ex) { System.out.println("SQLException " + ex.getMessage()); } catch (NullPointerException ex) { System.out.println("NullPointerException " + ex.getMessage()); //buat custom 404 kalau bisa hahahahaha } }
From source file:com.serphacker.serposcope.db.base.ExportDB.java
protected String blobToString(Blob data) throws Exception { final StringBuilder sb = new StringBuilder("X'"); int b;// w w w . j a va 2s . com try (InputStream br = data.getBinaryStream()) { while (-1 != (b = br.read())) { if (b < 0x10) { sb.append('0'); } sb.append(Integer.toString(b, 16)); } sb.append("'"); } return sb.toString(); }
From source file:com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.RepoFileResource.java
public FileResourceData copyData() { try {//from w ww .j a va 2 s . com if (isFileReference()) { String quotedResourceURI = "\"" + getResourceURI() + "\""; throw new JSException("jsexception.file.resource.is.reference", new Object[] { quotedResourceURI }); } FileResourceData resData; Blob blob = getData(); if (blob == null) { resData = new FileResourceData((byte[]) null); } else { resData = new FileResourceData(blob.getBinaryStream()); } return resData; } catch (SQLException e) { log.error("Error while reading data blob of \"" + getResourceURI() + "\"", e); throw new JSExceptionWrapper(e); } }
From source file:fr.gael.dhus.database.liquibase.CopyProductImagesBlobToFile.java
private void blobToFile(Blob blob, String out) { InputStream is = null;//ww w .j a va2 s . c o m OutputStream os = null; BufferedOutputStream bos = null; try { is = blob.getBinaryStream(); os = new FileOutputStream(out); bos = new BufferedOutputStream(os); IOUtils.copy(is, bos); bos.flush(); } catch (Exception e) { logger.error("Cannot copy blob into '" + out + "'.", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { logger.warn("Cannot close InputStream !"); } } if (bos != null) { try { bos.close(); } catch (IOException e) { logger.warn("Cannot close BufferedOutputStream !"); } } if (os != null) { try { os.close(); } catch (IOException e) { logger.warn("Cannot close OutputStream !"); } } } }