long writeFixedBlock ( FSDataInputStream [ ] inputs , int [ ] erasedLocations , int erasedLocationToFix , long limit , OutputStream out , Progressable reporter , ParallelStreamReader parallelReader , CRC32 crc ) throws IOException { LOG . info ( "Need to write " + limit + " bytes for erased location index " + erasedLocationToFix ) ; if ( crc != null ) { crc . reset ( ) ; } int [ ] tmp = new int [ inputs . length ] ; int [ ] decoded = new int [ erasedLocations . length ] ; // Loop while the number of written bytes is less than the max. long written ; for ( written = 0 ; written < limit ; ) { erasedLocations = readFromInputs ( inputs , erasedLocations , limit , reporter , parallelReader ) ; if ( decoded . length != erasedLocations . length ) { decoded = new int [ erasedLocations . length ] ; } int toWrite = ( int ) Math . min ( ( long ) bufSize , limit - written ) ; int partSize = ( int ) Math . ceil ( bufSize * 1.0 / parallelism ) ; try { long startTime = System . currentTimeMillis ( ) ; for ( int i = 0 ; i < parallelism ; i ++ ) { decodeOps . acquire ( 1 ) ; int start = i * partSize ; int count = Math . min ( bufSize - start , partSize ) ; parallelDecoder . execute ( new DecodeOp ( readBufs , writeBufs , start , count , erasedLocations , reedSolomonCode [ i ] ) ) ; } decodeOps . acquire ( parallelism ) ; decodeOps . release ( parallelism ) ; decodeTime += ( System . currentTimeMillis ( ) - startTime ) ; } catch ( InterruptedException e ) { throw new IOException ( "Interrupted while waiting for read result" ) ; } for ( int i = 0 ; i < erasedLocations . length ; i ++ ) { if ( erasedLocations [ i ] == erasedLocationToFix ) { out . write ( writeBufs [ i ] , 0 , toWrite ) ; if ( crc != null ) { crc . update ( writeBufs [ i ] , 0 , toWrite ) ; } written += toWrite ; break ; } } } return written ; }
Decode the inputs provided and write to the output .