当前位置: 首页>>代码示例>>Java>>正文


Java Blob.getBinaryStream方法代码示例

本文整理汇总了Java中java.sql.Blob.getBinaryStream方法的典型用法代码示例。如果您正苦于以下问题:Java Blob.getBinaryStream方法的具体用法?Java Blob.getBinaryStream怎么用?Java Blob.getBinaryStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.Blob的用法示例。


在下文中一共展示了Blob.getBinaryStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getExecLog

import java.sql.Blob; //导入方法依赖的package包/类
public String getExecLog(long execId, String jobName)
  throws SQLException, IOException {
  System.out.println("start");
  String cmd = "select log from execution_logs where exec_id = " + execId +
    " and name = '" + jobName + "'and attempt = 0 order by start_byte;";
  System.out.println(cmd);
  Statement statement = conn.createStatement();
  ResultSet rs = statement.executeQuery(cmd);
  StringBuilder sb = new StringBuilder();
  while (rs.next()) {
    Blob logBlob = rs.getBlob("log");
    GZIPInputStream gzip = new GZIPInputStream(logBlob.getBinaryStream());
    sb.append(IOUtils.toString(gzip, "UTF-8"));
  }
  statement.close();
  System.out.println("stop");
  return sb.toString();
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:19,代码来源:AzDbCommunicator.java

示例2: getObjectFromBlob

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * <p>
 * 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 {
    Object obj = null;

    Blob blobLocator = rs.getBlob(colName);
    if (blobLocator != null && blobLocator.length() != 0) {
        InputStream binaryInput = blobLocator.getBinaryStream();

        if (null != binaryInput) {
            if (binaryInput instanceof ByteArrayInputStream
                && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                //do nothing
            } else {
                ObjectInputStream in = new ObjectInputStream(binaryInput);
                try {
                    obj = in.readObject();
                } finally {
                    in.close();
                }
            }
        }

    }
    return obj;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:43,代码来源:StdJDBCDelegate.java

示例3: exportBackup

import java.sql.Blob; //导入方法依赖的package包/类
public void exportBackup(int id, OutputStream out) {
	Connection conn = null;
	PreparedStatement pstmt = null;
	try {
		conn = DBPower.getConnection(table.getId());
		conn.setAutoCommit(false);
		pstmt = conn.prepareStatement(SELECT_CONTENT_SQL);
		pstmt.setInt(1, id);
		ResultSet rs = pstmt.executeQuery();
		if (rs.next()) {
			Blob blob = rs.getBlob(1);
			InputStream in = blob.getBinaryStream();
			byte[] buf = new byte[1024];
			int len = 0;
			while ((len = in.read(buf)) != -1) {
				out.write(buf, 0, len);
			}
			in.close();
		}
		conn.commit();
	} catch (Exception e) {
		log.error( "", e );
	} finally {
		DBUtil.close(pstmt, conn);
	}
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:27,代码来源:BackupManagerImpl.java

示例4: getJobDataFromBlob

import java.sql.Blob; //导入方法依赖的package包/类
@Override
protected Object getJobDataFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    
    if (canUseProperties()) {
        Blob blobLocator = rs.getBlob(colName);
        InputStream binaryInput = null;
        try {
            if (null != blobLocator && blobLocator.length() > 0) {
                binaryInput = blobLocator.getBinaryStream();
            }
        } catch (Exception ignore) {
        }
        return binaryInput;
    }

    return getObjectFromBlob(rs, colName);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:WebLogicDelegate.java

示例5: mergeBlob

import java.sql.Blob; //导入方法依赖的package包/类
@Override
public Blob mergeBlob(Blob original, Blob target, SessionImplementor session) {
	if ( original != target ) {
		try {
			// the BLOB just read during the load phase of merge
			final OutputStream connectedStream = target.setBinaryStream( 1L );
			// the BLOB from the detached state
			final InputStream detachedStream = original.getBinaryStream();
			StreamCopier.copy( detachedStream, connectedStream );
			return target;
		}
		catch (SQLException e ) {
			throw session.getFactory().getSQLExceptionHelper().convert( e, "unable to merge BLOB data" );
		}
	}
	else {
		return NEW_LOCATOR_LOB_MERGE_STRATEGY.mergeBlob( original, target, session );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:Dialect.java

示例6: getObjectFromBlob

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * <p>
 * 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 {
    
    Object obj = null;

    Blob blobLocator = rs.getBlob(colName);
    InputStream binaryInput = null;
    try {
        if (null != blobLocator && blobLocator.length() > 0) {
            binaryInput = blobLocator.getBinaryStream();
        }
    } catch (Exception ignore) {
    }

    if (null != binaryInput) {
        ObjectInputStream in = new ObjectInputStream(binaryInput);
        try {
            obj = in.readObject();
        } finally {
            in.close();
        }
    }

    return obj;
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:43,代码来源:WebLogicDelegate.java

示例7: getJobDetailFromBlob

import java.sql.Blob; //导入方法依赖的package包/类
protected Object getJobDetailFromBlob(ResultSet rs, String colName)
    throws ClassNotFoundException, IOException, SQLException {
    
    if (canUseProperties()) {
        Blob blobLocator = rs.getBlob(colName);
        InputStream binaryInput = null;
        try {
            if (null != blobLocator && blobLocator.length() > 0) {
                binaryInput = blobLocator.getBinaryStream();
            }
        } catch (Exception ignore) {
        }
        return binaryInput;
    }

    return getObjectFromBlob(rs, colName);
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:18,代码来源:WebLogicDelegate.java

示例8: setBlobForBinaryParameter

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * Converts a blob to binary data for non-blob binary parameters.
 */
private void setBlobForBinaryParameter(int parameterIndex,
        Blob x) throws SQLException {

    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());

        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);

        return;
    }

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Maximum Blob input octet length exceeded: " + length;    // NOI18N

        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }

    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in,
            (int) length);

        setParameter(parameterIndex, out.toByteArray());
        out.close();
    } catch (Throwable e) {
        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,
                                e.toString(), e);
    }
}
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:37,代码来源:JDBCPreparedStatement.java

示例9: PreparedStmtSetValue

import java.sql.Blob; //导入方法依赖的package包/类
public static Object PreparedStmtSetValue(int columnType, ResultSet rs, int index) throws SQLException, IOException{
	StringBuffer sb = new StringBuffer();
	switch(columnType){
	case 2005:  //CLOB
		Clob clob = rs.getClob(index);
		
		if (clob == null){
			return null;
		}
		
		Reader reader = clob.getCharacterStream();
		char[] buffer = new char[(int)clob.length()];
		while(reader.read(buffer) != -1){
			sb.append(buffer);				
		}
		return sb.toString();
	case 2004:  //BLOB			
		Blob blob = rs.getBlob(index);
		
		if (blob == null){
			return null;
		}
		
		InputStream in = blob.getBinaryStream();
		byte[] Bytebuffer = new byte[(int)blob.length()];
		in.read(Bytebuffer);
		return Bytebuffer;
	case -2:
		return rs.getBytes(index);
	default:
		return rs.getObject(index);
	}	
}
 
开发者ID:experdb,项目名称:eXperDB-DB2PG,代码行数:34,代码来源:DatabaseUtil.java

示例10: setBlobForBinaryParameter

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * Converts a blob to binary data for non-blob binary parameters.
 */
private void setBlobForBinaryParameter(int parameterIndex,
        Blob x) throws SQLException {

    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());

        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);

        return;
    }
    checkSetParameterIndex(parameterIndex, true);

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Maximum Blob input octet length exceeded: " + length;    // NOI18N

        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }

    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in,
            (int) length);

        setParameter(parameterIndex, out.toByteArray());
    } catch (IOException e) {
        throw Util.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,
                                e.toString());
    }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:37,代码来源:JDBCPreparedStatement.java

示例11: getBlobAsBinaryStream

import java.sql.Blob; //导入方法依赖的package包/类
@Override
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
	logger.debug("Returning Oracle BLOB as binary stream");
	Blob blob = rs.getBlob(columnIndex);
	initializeResourcesBeforeRead(rs.getStatement().getConnection(), blob);
	InputStream retVal = (blob != null ? blob.getBinaryStream() : null);
	releaseResourcesAfterRead(rs.getStatement().getConnection(), blob);
	return retVal;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:OracleLobHandler.java

示例12: toByteArray

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * Reads a byte array from a {@link Blob}.
 * 
 * @param blob
 *            a {@link Blob} containing data.
 * @return data from {@link Blob} as byte array.
 */
public static byte[] toByteArray(Blob blob) {
    if (blob == null) {
        return null;
    }
    InputStream input = null;
    try {
        input = blob.getBinaryStream();
        return IOUtils.toByteArray(input);
    } catch (Exception e) {
        throw new HibernateException("cannot read from blob", e);
    } finally {
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:oehf,项目名称:ipf-flow-manager,代码行数:22,代码来源:HibernateUtils.java

示例13: getObjectFromBlob

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * <p>
 * Caché requires {@code java.sql.Blob} instances to be explicitly freed.
 */
@Override
protected Object getObjectFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException {
    Blob blob = rs.getBlob(colName);
    if (blob == null) {
        return null;
    } else {
        try {
            if (blob.length() == 0) {
                return null;
            } else {
                InputStream binaryInput = blob.getBinaryStream();
                if (binaryInput == null) {
                    return null;
                } else if (binaryInput instanceof ByteArrayInputStream && ((ByteArrayInputStream) binaryInput).available() == 0 ) {
                    return null;
                } else {
                    ObjectInputStream in = new ObjectInputStream(binaryInput);
                    try {
                        return in.readObject();
                    } finally {
                        in.close();
                    }
                }
            }
        } finally {
            blob.free();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:CacheDelegate.java

示例14: BlobToString

import java.sql.Blob; //导入方法依赖的package包/类
private String BlobToString(Blob blob) throws SQLException, IOException {

    String reString = "";
    InputStream is =  blob.getBinaryStream();

    ByteArrayInputStream bais = (ByteArrayInputStream)is;
    byte[] byte_data = new byte[bais.available()]; //bais.available()���ش����������ֽ���
    bais.read(byte_data, 0,byte_data.length);//���������е����ݶ���ָ��������
    reString = new String(byte_data,"utf-8"); //��תΪString����ʹ��ָ���ı��뷽ʽ
    is.close();

    return reString;
  }
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:14,代码来源:DBcrud.java

示例15: setBlobForBinaryParameter

import java.sql.Blob; //导入方法依赖的package包/类
/**
 * Converts a blob to binary data for non-blob binary parameters.
 */
private void setBlobForBinaryParameter(int parameterIndex,
        Blob x) throws SQLException {

    if (x instanceof JDBCBlob) {
        setParameter(parameterIndex, ((JDBCBlob) x).data());

        return;
    } else if (x == null) {
        setParameter(parameterIndex, null);

        return;
    }

    final long length = x.length();

    if (length > Integer.MAX_VALUE) {
        String msg = "Maximum Blob input octet length exceeded: " + length;    // NOI18N

        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR, msg);
    }

    try {
        java.io.InputStream in = x.getBinaryStream();
        HsqlByteArrayOutputStream out = new HsqlByteArrayOutputStream(in,
            (int) length);

        setParameter(parameterIndex, out.toByteArray());
    } catch (Throwable e) {
        throw JDBCUtil.sqlException(ErrorCode.JDBC_INPUTSTREAM_ERROR,
                                e.toString(), e);
    }
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:36,代码来源:JDBCPreparedStatement.java


注:本文中的java.sql.Blob.getBinaryStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。