public static EmvTrack1 extractTrack1Data ( final byte [ ] pRawTrack1 ) { EmvTrack1 ret = null ; if ( pRawTrack1 != null ) { EmvTrack1 track1 = new EmvTrack1 ( ) ; track1 . setRaw ( pRawTrack1 ) ; Matcher m = TRACK1_PATTERN . matcher ( new String ( pRawTrack1 ) ) ; // Check pattern if ( m . find ( ) ) { // Set format code track1 . setFormatCode ( m . group ( 1 ) ) ; // Set card number track1 . setCardNumber ( m . group ( 2 ) ) ; // Extract holder name String [ ] name = StringUtils . split ( m . group ( 4 ) . trim ( ) , CARD_HOLDER_NAME_SEPARATOR ) ; if ( name != null && name . length == 2 ) { track1 . setHolderLastname ( StringUtils . trimToNull ( name [ 0 ] ) ) ; track1 . setHolderFirstname ( StringUtils . trimToNull ( name [ 1 ] ) ) ; } // Read expire date SimpleDateFormat sdf = new SimpleDateFormat ( "yyMM" , Locale . getDefault ( ) ) ; try { track1 . setExpireDate ( DateUtils . truncate ( sdf . parse ( m . group ( 5 ) ) , Calendar . MONTH ) ) ; } catch ( ParseException e ) { LOGGER . error ( "Unparsable expire card date : {}" , e . getMessage ( ) ) ; return ret ; } // Read service track1 . setService ( new Service ( m . group ( 6 ) ) ) ; ret = track1 ; } } return ret ; }
Extract track 1 data