當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。