public static void getFileServer ( OutputStream outstream , File localfile , DataTransferThrottler throttler ) throws IOException { byte buf [ ] = new byte [ BUFFER_SIZE ] ; InputStream infile = null ; try { infile = new BufferedInputStream ( new FileInputStream ( localfile ) , BUFFER_SIZE ) ; if ( InjectionHandler . falseCondition ( InjectionEvent . TRANSFERFSIMAGE_GETFILESERVER0 ) && localfile . getAbsolutePath ( ) . contains ( "secondary" ) ) { // throw exception only when the secondary sends its image throw new IOException ( "If this exception is not caught by the " + "name-node fs image will be truncated." ) ; } if ( InjectionHandler . falseCondition ( InjectionEvent . TRANSFERFSIMAGE_GETFILESERVER1 ) && localfile . getAbsolutePath ( ) . contains ( "fsimage" ) ) { // Test sending image shorter than localfile long len = localfile . length ( ) ; buf = new byte [ ( int ) Math . min ( len / 2 , BUFFER_SIZE ) ] ; // This will read at most half of the image // and the rest of the image will be sent over the wire infile . read ( buf ) ; } int num = 1 ; while ( num > 0 ) { num = infile . read ( buf ) ; if ( num <= 0 ) { break ; } if ( InjectionHandler . falseCondition ( InjectionEvent . TRANSFERFSIMAGE_GETFILESERVER2 ) ) { // Simulate a corrupted byte on the wire LOG . warn ( "SIMULATING A CORRUPT BYTE IN IMAGE TRANSFER!" ) ; buf [ 0 ] ++ ; } InjectionHandler . processEvent ( InjectionEvent . TRANSFERFSIMAGE_GETFILESERVER3 ) ; outstream . write ( buf , 0 , num ) ; if ( throttler != null ) { throttler . throttle ( num ) ; } } } finally { if ( infile != null ) { infile . close ( ) ; } } }
A server - side method to respond to a getfile http request Copies the contents of the local file into the output stream .