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:com.wabacus.config.database.type.AbsDatabaseType.java
public byte[] getBlobValue(ResultSet rs, int iindex) throws SQLException { InputStream in = null;//from w ww. ja v a 2 s. c o m try { in = rs.getBinaryStream(iindex); if (in == null) return null; return Tools.getBytesArrayFromInputStream(in); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:org.codehaus.wadi.core.store.DatabaseStore.java
protected byte[] loadBody(ResultSet rs) throws SQLException { InputStream in = rs.getBinaryStream("body"); ByteArrayOutputStream memOut = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int read;/*from w w w . ja v a2 s . c om*/ try { while (-1 < (read = in.read(buffer))) { memOut.write(buffer, 0, read); } } catch (IOException e) { throw (SQLException) new SQLException().initCause(e); } return memOut.toByteArray(); }
From source file:com.wabacus.config.database.type.AbsDatabaseType.java
public byte[] getBlobValue(ResultSet rs, String column) throws SQLException { InputStream in = null;// ww w. ja va 2 s .c om try { in = rs.getBinaryStream(column); if (in == null) return null; return Tools.getBytesArrayFromInputStream(in); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:org.jbpm.bpel.persistence.db.type.ElementType.java
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { // retrieve stream from database String columnName = names[0]; InputStream xmlStream = rs.getBinaryStream(columnName); // if SQL value is NULL, element is null as well if (xmlStream == null) return null; // introduce inflater, if requested Integer deflateLevel = getXmlDeflateLevel(); if (deflateLevel != null) xmlStream = new InflaterInputStream(xmlStream); try {// w w w. j a v a 2s. co m // parse XML text Element element = XmlUtil.getDocumentBuilder().parse(xmlStream).getDocumentElement(); xmlStream.close(); if (log.isTraceEnabled()) log.trace("returning '" + XmlUtil.toTraceString(element) + "' as column: " + columnName); return element; } catch (SAXException e) { throw new HibernateException("could not parse column: " + columnName, e); } catch (IOException e) { throw new HibernateException("could not read column: " + columnName, e); } }
From source file:io.lavagna.service.CardDataRepository.java
public void outputFileContent(String digest, final OutputStream out) throws IOException { LOG.debug("get file digest : {} ", digest); SqlParameterSource param = new MapSqlParameterSource("digest", digest); jdbc.query(queries.fileContent(), param, new RowCallbackHandler() { @Override/*from ww w . j a v a2 s . co m*/ public void processRow(ResultSet rs) throws SQLException { try (InputStream is = rs.getBinaryStream("CONTENT")) { StreamUtils.copy(is, out); } catch (IOException e) { throw new IllegalStateException("Error while copying data", e); } } }); }
From source file:org.artifactory.storage.db.fs.dao.ConfigsDao.java
public InputStream loadStreamConfig(String name) throws SQLException { ResultSet resultSet = null; try {/*from w w w. j a v a2s . c o m*/ resultSet = jdbcHelper.executeSelect("SELECT data FROM configs WHERE config_name = ?", name); if (resultSet.next()) { InputStream binaryStream = null; try { binaryStream = resultSet.getBinaryStream(1); return IOUtils.toBufferedInputStream(binaryStream); } finally { IOUtils.closeQuietly(binaryStream); } } return null; } catch (IOException e) { throw new SQLException("Failed to read config '" + name + "' due to: " + e.getMessage(), e); } finally { DbUtils.close(resultSet); } }
From source file:org.sonar.server.source.index.SourceFileResultSetIterator.java
@Override protected Row read(ResultSet rs) throws SQLException { String projectUuid = rs.getString(1); String fileUuid = rs.getString(2); Date updatedAt = new Date(rs.getLong(3)); FileSourceDb.Data data = FileSourceDto.decodeData(rs.getBinaryStream(4)); return toRow(projectUuid, fileUuid, updatedAt, data); }
From source file:org.sonar.core.source.db.FileSourceDao.java
public <T> void readDataStream(String fileUuid, Function<InputStream, T> function) { DbSession dbSession = mybatis.openSession(false); Connection connection = dbSession.getConnection(); PreparedStatement pstmt = null; ResultSet rs = null; InputStream input = null;//ww w . j a v a 2 s .com try { pstmt = connection.prepareStatement("SELECT binary_data FROM file_sources WHERE file_uuid=?"); pstmt.setString(1, fileUuid); rs = pstmt.executeQuery(); if (rs.next()) { input = rs.getBinaryStream(1); function.apply(input); } } catch (SQLException e) { throw new IllegalStateException("Fail to read FILE_SOURCES.BINARY_DATA of file " + fileUuid, e); } finally { IOUtils.closeQuietly(input); DbUtils.closeQuietly(connection, pstmt, rs); MyBatis.closeQuietly(dbSession); } }
From source file:at.ac.tuwien.dsg.depic.orchestrator.elasticityprocessesstore.ElasticityProcessesStore.java
public PrimitiveActionMetadata getPrimitiveActionMetadata(String eDaaSName) { String sql = "SELECT * FROM InputSpecification WHERE name ='" + eDaaSName + "'"; InputStream inputStream = null; String primitiveXML = ""; ResultSet rs = connectionManager.ExecuteQuery(sql); try {/*w w w .j av a 2 s .c om*/ while (rs.next()) { inputStream = rs.getBinaryStream("elasticity_process_config"); } StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(inputStream, writer, encoding); primitiveXML = writer.toString(); } catch (Exception ex) { System.err.println(ex); } Configuration cfg = new Configuration( getClass().getProtectionDomain().getCodeSource().getLocation().getPath()); YamlUtils.setFilePath(cfg.getConfigPath()); PrimitiveActionMetadata primitiveActionMetadata = YamlUtils.unmarshallYaml(PrimitiveActionMetadata.class, primitiveXML); return primitiveActionMetadata; }
From source file:at.ac.tuwien.dsg.depic.orchestrator.elasticityprocessesstore.ElasticityProcessesStore.java
public String getDeployementDescription(String edaas) { String deploymentDescription = ""; try {//ww w.j av a2s. com InputStream inputStream = null; String sql = "Select * from DeploymentDescription where edaas='" + edaas + "'"; ResultSet rs = connectionManager.ExecuteQuery(sql); try { while (rs.next()) { inputStream = rs.getBinaryStream("specs"); } } catch (SQLException ex) { Logger.getLogger(ElasticityProcessesStore.class.getName()).log(Level.SEVERE, null, ex); } StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(inputStream, writer, encoding); deploymentDescription = writer.toString(); } catch (IOException ex) { Logger.getLogger(ElasticityProcessesStore.class.getName()).log(Level.SEVERE, null, ex); } return deploymentDescription; }