private void readLocalInfilePacket ( Buffer buffer , Results results ) throws SQLException { int seq = 2 ; buffer . getLengthEncodedNumeric ( ) ; //field pos String fileName = buffer . readStringNullEnd ( StandardCharsets . UTF_8 ) ; try { // Server request the local file (LOCAL DATA LOCAL INFILE) // We do accept general URLs, too. If the localInfileStream is // set, use that. InputStream is ; writer . startPacket ( seq ) ; if ( localInfileInputStream == null ) { if ( ! getUrlParser ( ) . getOptions ( ) . allowLocalInfile ) { writer . writeEmptyPacket ( ) ; reader . getPacket ( true ) ; throw new SQLException ( "Usage of LOCAL INFILE is disabled. To use it enable it via the connection property allowLocalInfile=true" , FEATURE_NOT_SUPPORTED . getSqlState ( ) , - 1 ) ; } //validate all defined interceptors ServiceLoader < LocalInfileInterceptor > loader = ServiceLoader . load ( LocalInfileInterceptor . class ) ; for ( LocalInfileInterceptor interceptor : loader ) { if ( ! interceptor . validate ( fileName ) ) { writer . writeEmptyPacket ( ) ; reader . getPacket ( true ) ; throw new SQLException ( "LOCAL DATA LOCAL INFILE request to send local file named \"" + fileName + "\" not validated by interceptor \"" + interceptor . getClass ( ) . getName ( ) + "\"" ) ; } } try { URL url = new URL ( fileName ) ; is = url . openStream ( ) ; } catch ( IOException ioe ) { try { is = new FileInputStream ( fileName ) ; } catch ( FileNotFoundException f ) { writer . writeEmptyPacket ( ) ; reader . getPacket ( true ) ; throw new SQLException ( "Could not send file : " + f . getMessage ( ) , "22000" , - 1 , f ) ; } } } else { is = localInfileInputStream ; localInfileInputStream = null ; } try { byte [ ] buf = new byte [ 8192 ] ; int len ; while ( ( len = is . read ( buf ) ) > 0 ) { writer . startPacket ( seq ++ ) ; writer . write ( buf , 0 , len ) ; writer . flush ( ) ; } writer . writeEmptyPacket ( ) ; } catch ( IOException ioe ) { throw handleIoException ( ioe ) ; } finally { is . close ( ) ; } getResult ( results ) ; } catch ( IOException e ) { throw handleIoException ( e ) ; } }
Read Local_infile Packet .