List of usage examples for java.sql ResultSet getBinaryStream
java.io.InputStream getBinaryStream(String columnLabel) throws SQLException;
ResultSet
object as a stream of uninterpreted byte
s. From source file:org.wso2.carbon.apimgt.hybrid.gateway.usage.publisher.dao.UploadedUsageFileInfoDAO.java
/** * Get the content of the file based on the file information * * @param dto Processed file represented by {@link UploadedFileInfoDTO} * @return InputStream with the content of the file of null if there is no content * @throws UsagePublisherException// w w w . j av a 2 s. co m */ public static InputStream getFileContent(UploadedFileInfoDTO dto) throws UsagePublisherException { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; InputStream fileContentInputStream = null; try { connection = APIMgtDBUtil.getConnection(); statement = connection.prepareStatement(MicroGatewayAPIUsageConstants.GET_UPLOADED_FILE_CONTENT_QUERY); statement.setString(1, dto.getTenantDomain()); statement.setString(2, dto.getFileName()); resultSet = statement.executeQuery(); while (resultSet.next()) { //Postgres bytea data doesn't support getBlob operation if (connection.getMetaData().getDriverName().contains("PostgreSQL")) { fileContentInputStream = resultSet .getBinaryStream(MicroGatewayAPIUsageConstants.API_USAGE_FILE_CONTENT); } else { Blob content = resultSet.getBlob(MicroGatewayAPIUsageConstants.API_USAGE_FILE_CONTENT); fileContentInputStream = content.getBinaryStream(); } if (log.isDebugEnabled()) { log.debug("Added File to list : " + dto.toString()); } } if (log.isDebugEnabled()) { log.debug("Retrieved content of file : " + dto.toString()); } } catch (SQLException e) { throw new UsagePublisherException( "Error occurred while retrieving the content of the file: " + dto.toString(), e); } finally { APIMgtDBUtil.closeAllConnections(statement, connection, resultSet); } return fileContentInputStream; }
From source file:org.seasar.s2sqlmap.spring.lob.port.DefaultLobHandler.java
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning BLOB as binary stream"); return rs.getBinaryStream(columnIndex); }
From source file:org.sakaiproject.metaobj.shared.model.impl.HibernateSchemaNode.java
public Object nullSafeGet(ResultSet rs, String[] names, Object object) throws HibernateException, SQLException { InputStream in = rs.getBinaryStream(names[0]); if (rs.wasNull()) { return null; }/*from w w w.jav a 2 s . c om*/ SchemaFactory schemaFactory = SchemaFactory.getInstance(); return schemaFactory.getSchema(in); }
From source file:org.quartz.impl.jdbcjobstore.HSQLDBDelegate.java
/** * <p>//from ww w . ja va2 s . c o m * This method should be overridden by any delegate subclasses that need * special handling for BLOBs. The default implementation uses standard * JDBC <code>java.sql.Blob</code> operations. * </p> * * @param rs * the result set, already queued to the correct row * @param colName * the column name for the BLOB * @return the deserialized Object from the ResultSet BLOB * @throws ClassNotFoundException * if a class found during deserialization cannot be found * @throws IOException * if deserialization causes an error */ protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { InputStream binaryInput = rs.getBinaryStream(colName); if (binaryInput == null || binaryInput.available() == 0) { return null; } Object obj = null; ObjectInputStream in = new ObjectInputStream(binaryInput); try { obj = in.readObject(); } finally { in.close(); } return obj; }
From source file:io.lightlink.types.BlobConverter.java
@Override public Object readFromResultSet(ResultSet resultSet, int pos, RunnerContext runnerContext, String colName) throws SQLException, IOException { InputStream stream = resultSet.getBinaryStream(pos); return stream == null ? null : inputStreamToReturnValue(stream); }
From source file:org.sonar.server.db.migrations.v51.FeedFileSourcesBinaryDataTest.java
private FileSourceDb.Data selectData(Connection connection, long fileSourceId) throws SQLException { PreparedStatement pstmt = connection.prepareStatement("select binary_data from file_sources where id=?"); ResultSet rs = null; try {//from w w w. j a v a 2 s . com pstmt.setLong(1, fileSourceId); rs = pstmt.executeQuery(); rs.next(); InputStream data = rs.getBinaryStream(1); return FileSourceDto.decodeSourceData(data); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(pstmt); } }
From source file:org.copperengine.spring.audit.AuditTrailQueryEngine.java
public byte[] getMessage(long id) { String customSelect = "select LONG_MESSAGE from COP_AUDIT_TRAIL_EVENT where SEQ_ID = ? "; ResultSetExtractor<byte[]> rse = new ResultSetExtractor<byte[]>() { @Override//w ww . j a v a 2s .c om public byte[] extractData(ResultSet rs) throws SQLException, DataAccessException { rs.next(); return convertToArray(rs.getBinaryStream("LONG_MESSAGE")); } }; return this.getJdbcTemplate().query(customSelect, rse, new Object[] { id }); }
From source file:org.apache.sandesha2.storage.jdbc.PersistentBeanMgr.java
protected Object getObject(ResultSet rs, String field) throws Exception { // MySQL JDBC connector returns a byte array // and Derby an EmbedBlob with : // return rs.getObject(field); // so/*from ww w .j av a 2 s .c o m*/ InputStream bs = rs.getBinaryStream(field); if (bs == null) return null; return (new ObjectInputStream(bs)).readObject(); }
From source file:org.quartz.impl.jdbcjobstore.HSQLDBDelegate.java
protected Object getJobDetailFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { if (canUseProperties()) { InputStream binaryInput = rs.getBinaryStream(colName); return binaryInput; }/*from w w w . ja v a 2s . co m*/ return getObjectFromBlob(rs, colName); }
From source file:at.ac.tuwien.dsg.cloudlyra.service.core.dafstore.DafStore.java
public String getDafXML(String dafName) { String dafStr = ""; try {//from ww w . j av a 2s. c o m InputStream inputStream = null; MySqlConnectionManager connectionManager = new MySqlConnectionManager(ip, port, database, username, password); String sql = "Select * from Daf where name='" + dafName + "'"; ResultSet rs = connectionManager.ExecuteQuery(sql); try { while (rs.next()) { inputStream = rs.getBinaryStream("file"); } } catch (SQLException ex) { Logger.getLogger(DafStore.class.getName()).log(Level.SEVERE, null, ex); } StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(inputStream, writer, encoding); dafStr = writer.toString(); Logger.getLogger(DafStore.class.getName()).log(Level.INFO, null, "DAF XML: " + dafStr); } catch (IOException ex) { Logger.getLogger(DafStore.class.getName()).log(Level.SEVERE, null, ex); } return dafStr; }