public InputStream downloadStream ( String stageName , String sourceFileName , boolean decompress ) throws SQLException { logger . debug ( "download data to stream: stageName={}" + ", sourceFileName={}" , stageName , sourceFileName ) ; if ( Strings . isNullOrEmpty ( stageName ) ) { throw new SnowflakeSQLException ( SqlState . INTERNAL_ERROR , ErrorCode . INTERNAL_ERROR . getMessageCode ( ) , "stage name is null or empty" ) ; } if ( Strings . isNullOrEmpty ( sourceFileName ) ) { throw new SnowflakeSQLException ( SqlState . INTERNAL_ERROR , ErrorCode . INTERNAL_ERROR . getMessageCode ( ) , "source file name is null or empty" ) ; } SnowflakeStatementV1 stmt = new SnowflakeStatementV1 ( this , ResultSet . TYPE_FORWARD_ONLY , ResultSet . CONCUR_READ_ONLY , ResultSet . CLOSE_CURSORS_AT_COMMIT ) ; StringBuilder getCommand = new StringBuilder ( ) ; getCommand . append ( "get " ) ; if ( ! stageName . startsWith ( "@" ) ) { getCommand . append ( "@" ) ; } getCommand . append ( stageName ) ; getCommand . append ( "/" ) ; if ( sourceFileName . startsWith ( "/" ) ) { sourceFileName = sourceFileName . substring ( 1 ) ; } getCommand . append ( sourceFileName ) ; //this is a fake path, used to form Get query and retrieve stage info, //no file will be downloaded to this location getCommand . append ( " file:///tmp/ /*jdbc download stream*/" ) ; SnowflakeFileTransferAgent transferAgent = new SnowflakeFileTransferAgent ( getCommand . toString ( ) , sfSession , stmt . getSfStatement ( ) ) ; InputStream stream = transferAgent . downloadStream ( sourceFileName ) ; if ( decompress ) { try { return new GZIPInputStream ( stream ) ; } catch ( IOException ex ) { throw new SnowflakeSQLException ( SqlState . INTERNAL_ERROR , ErrorCode . INTERNAL_ERROR . getMessageCode ( ) , ex . getMessage ( ) ) ; } } else { return stream ; } }
Download file from the given stage and return an input stream