public static void encode(String content,ErrorCorrectionLevel ecLevel,Map<EncodeHintType,Object> hints,QRCode qrCode) throws WriterException {
  String encoding=hints == null ? null : (String)hints.get(EncodeHintType.CHARACTER_SET);
  if (encoding == null) {
    encoding=DEFAULT_BYTE_MODE_ENCODING;
  }
  int desiredMinVersion=(hints == null || hints.get(EncodeHintType.MIN_VERSION_NR) == null) ? 1 : (int)hints.get(EncodeHintType.MIN_VERSION_NR);
  if (desiredMinVersion < 1)   desiredMinVersion=1;
  if (desiredMinVersion > 40)   desiredMinVersion=40;
  Mode mode=chooseMode(content,encoding);
  BitVector dataBits=new BitVector();
  appendBytes(content,mode,dataBits,encoding);
  int numInputBytes=dataBits.sizeInBytes();
  initQRCode(numInputBytes,ecLevel,desiredMinVersion,mode,qrCode);
  BitVector headerAndDataBits=new BitVector();
  if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) {
    CharacterSetECI eci=CharacterSetECI.getCharacterSetECIByName(encoding);
    if (eci != null) {
      appendECI(eci,headerAndDataBits);
    }
  }
  appendModeInfo(mode,headerAndDataBits);
  int numLetters=mode.equals(Mode.BYTE) ? dataBits.sizeInBytes() : content.length();
  appendLengthInfo(numLetters,qrCode.getVersion(),mode,headerAndDataBits);
  headerAndDataBits.appendBitVector(dataBits);
  terminateBits(qrCode.getNumDataBytes(),headerAndDataBits);
  BitVector finalBits=new BitVector();
  interleaveWithECBytes(headerAndDataBits,qrCode.getNumTotalBytes(),qrCode.getNumDataBytes(),qrCode.getNumRSBlocks(),finalBits);
  ByteMatrix matrix=new ByteMatrix(qrCode.getMatrixWidth(),qrCode.getMatrixWidth());
  qrCode.setMaskPattern(chooseMaskPattern(finalBits,qrCode.getECLevel(),qrCode.getVersion(),matrix));
  MatrixUtil.buildMatrix(finalBits,qrCode.getECLevel(),qrCode.getVersion(),qrCode.getMaskPattern(),matrix);
  qrCode.setMatrix(matrix);
  if (!qrCode.isValid()) {
    throw new WriterException("Invalid QR code: " + qrCode.toString());
  }
}

public static void encode ( String content , ErrorCorrectionLevel ecLevel , Map < EncodeHintType , Object > hints , QRCode qrCode ) throws WriterException { String encoding = hints == null ? null : ( String ) hints . get ( EncodeHintType . CHARACTER_SET ) ; if ( encoding == null ) { encoding = DEFAULT_BYTE_MODE_ENCODING ; } int desiredMinVersion = ( hints == null || hints . get ( EncodeHintType . MIN_VERSION_NR ) == null ) ? 1 : ( int ) hints . get ( EncodeHintType . MIN_VERSION_NR ) ; if ( desiredMinVersion < 1 ) desiredMinVersion = 1 ; if ( desiredMinVersion > 40 ) desiredMinVersion = 40 ; Mode mode = chooseMode ( content , encoding ) ; BitVector dataBits = new BitVector ( ) ; appendBytes ( content , mode , dataBits , encoding ) ; int numInputBytes = dataBits . sizeInBytes ( ) ; initQRCode ( numInputBytes , ecLevel , desiredMinVersion , mode , qrCode ) ; BitVector headerAndDataBits = new BitVector ( ) ; if ( mode == Mode . BYTE && ! DEFAULT_BYTE_MODE_ENCODING . equals ( encoding ) ) { CharacterSetECI eci = CharacterSetECI . getCharacterSetECIByName ( encoding ) ; if ( eci != null ) { appendECI ( eci , headerAndDataBits ) ; } } appendModeInfo ( mode , headerAndDataBits ) ; int numLetters = mode . equals ( Mode . BYTE ) ? dataBits . sizeInBytes ( ) : content . length ( ) ; appendLengthInfo ( numLetters , qrCode . getVersion ( ) , mode , headerAndDataBits ) ; headerAndDataBits . appendBitVector ( dataBits ) ; terminateBits ( qrCode . getNumDataBytes ( ) , headerAndDataBits ) ; BitVector finalBits = new BitVector ( ) ; interleaveWithECBytes ( headerAndDataBits , qrCode . getNumTotalBytes ( ) , qrCode . getNumDataBytes ( ) , qrCode . getNumRSBlocks ( ) , finalBits ) ; ByteMatrix matrix = new ByteMatrix ( qrCode . getMatrixWidth ( ) , qrCode . getMatrixWidth ( ) ) ; qrCode . setMaskPattern ( chooseMaskPattern ( finalBits , qrCode . getECLevel ( ) , qrCode . getVersion ( ) , matrix ) ) ; MatrixUtil . buildMatrix ( finalBits , qrCode . getECLevel ( ) , qrCode . getVersion ( ) , qrCode . getMaskPattern ( ) , matrix ) ; qrCode . setMatrix ( matrix ) ; if ( ! qrCode . isValid ( ) ) { throw new WriterException ( "Invalid QR code: " + qrCode . toString ( ) ) ; } }
encode " bytes " with the error correction level " eclevel " . the encoding mode will be chosen internally by choosemode ( ) . on success , store the result in " qrcode " . < p > we recommend you to use qrcode . ec_level_l ( the lowest level ) for " geteclevel " since our primary use is to show qr code on desktop screens . we don ' t need very strong error correction for this purpose . < p > note that there is no way to encode bytes in mode_kanji . we might want to add encodewithmode ( ) with which clients can specify the encoding mode . for now , we don ' t need the functionality .
