private static byte [ ] readFile ( final HttpQuery query , final File file , final int max_length ) { final int length = ( int ) file . length ( ) ; if ( length <= 0 ) { return null ; } FileInputStream in ; try { in = new FileInputStream ( file . getPath ( ) ) ; } catch ( FileNotFoundException e ) { return null ; } try { final byte [ ] buf = new byte [ Math . min ( length , max_length ) ] ; final int read = in . read ( buf ) ; if ( read != buf . length ) { logError ( query , "When reading " + file + ": read only " + read + " bytes instead of " + buf . length ) ; return null ; } return buf ; } catch ( IOException e ) { logError ( query , "Error while reading " + file , e ) ; return null ; } finally { try { in . close ( ) ; } catch ( IOException e ) { logError ( query , "Error while closing " + file , e ) ; } } }
Reads a file into a byte array .