private void addErrorCorrection(StringBuilder adjustedString, int codewordSize, int dataBlocks, int eccBlocks) {

        int x, poly, startWeight;

        /* Split into codewords and calculate Reed-Solomon error correction codes */
        switch (codewordSize) {
            case 6:
                x = 32;
                poly = 0x43;
                startWeight = 0x20;
                break;
            case 8:
                x = 128;
                poly = 0x12d;
                startWeight = 0x80;
                break;
            case 10:
                x = 512;
                poly = 0x409;
                startWeight = 0x200;
                break;
            case 12:
                x = 2048;
                poly = 0x1069;
                startWeight = 0x800;
                break;
            default:
                throw new OkapiException("Unrecognized codeword size: " + codewordSize);
        }

        ReedSolomon rs = new ReedSolomon();
        int[] data = new int[dataBlocks + 3];
        int[] ecc = new int[eccBlocks + 3];

        for (int i = 0; i < dataBlocks; i++) {
            for (int weight = 0; weight < codewordSize; weight++) {
                if (adjustedString.charAt((i * codewordSize) + weight) == '1') {
                    data[i] += (x >> weight);
                }
            }
        }

        rs.init_gf(poly);
        rs.init_code(eccBlocks, 1);
        rs.encode(dataBlocks, data);

        for (int i = 0; i < eccBlocks; i++) {
            ecc[i] = rs.getResult(i);
        }

        for (int i = (eccBlocks - 1); i >= 0; i--) {
            for (int weight = startWeight; weight > 0; weight = weight >> 1) {
                if ((ecc[i] & weight) != 0) {
                    adjustedString.append('1');
                } else {
                    adjustedString.append('0');
                }
            }
        }
    }
private void addErrorCorrection ( StringBuilder adjustedString , int codewordSize , int dataBlocks , int eccBlocks ) { int x , poly , startWeight ; switch ( codewordSize ) { case 6 : x = 32 ; poly = 0x43 ; startWeight = 0x20 ; break ; case 8 : x = 128 ; poly = 0x12d ; startWeight = 0x80 ; break ; case 10 : x = 512 ; poly = 0x409 ; startWeight = 0x200 ; break ; case 12 : x = 2048 ; poly = 0x1069 ; startWeight = 0x800 ; break ; default : throw new OkapiException ( "Unrecognized codeword size: " + codewordSize ) ; } ReedSolomon rs = new ReedSolomon ( ) ; int [ ] data = new int [ dataBlocks + 3 ] ; int [ ] ecc = new int [ eccBlocks + 3 ] ; for ( int i = 0 ; i < dataBlocks ; i ++ ) { for ( int weight = 0 ; weight < codewordSize ; weight ++ ) { if ( adjustedString . charAt ( ( i * codewordSize ) + weight ) == '1' ) { data [ i ] += ( x > > weight ) ; } } } rs . init_gf ( poly ) ; rs . init_code ( eccBlocks , 1 ) ; rs . encode ( dataBlocks , data ) ; for ( int i = 0 ; i < eccBlocks ; i ++ ) { ecc [ i ] = rs . getResult ( i ) ; } for ( int i = ( eccBlocks - 1 ) ; i >= 0 ; i -- ) { for ( int weight = startWeight ; weight > 0 ; weight = weight > > 1 ) { if ( ( ecc [ i ] & weight ) != 0 ) { adjustedString . append ( '1' ) ; } else { adjustedString . append ( '0' ) ; } } } }
Adds error correction data to the specified binary string, which already contains the primary data