public static EmvTrack2 extractTrack2EquivalentData ( final byte [ ] pRawTrack2 ) { EmvTrack2 ret = null ; if ( pRawTrack2 != null ) { EmvTrack2 track2 = new EmvTrack2 ( ) ; track2 . setRaw ( pRawTrack2 ) ; String data = BytesUtils . bytesToStringNoSpace ( pRawTrack2 ) ; Matcher m = TRACK2_EQUIVALENT_PATTERN . matcher ( data ) ; // Check pattern if ( m . find ( ) ) { // read card number track2 . setCardNumber ( m . group ( 1 ) ) ; // Read expire date SimpleDateFormat sdf = new SimpleDateFormat ( "yyMM" , Locale . getDefault ( ) ) ; try { track2 . setExpireDate ( DateUtils . truncate ( sdf . parse ( m . group ( 2 ) ) , Calendar . MONTH ) ) ; } catch ( ParseException e ) { LOGGER . error ( "Unparsable expire card date : {}" , e . getMessage ( ) ) ; return ret ; } // Read service track2 . setService ( new Service ( m . group ( 3 ) ) ) ; ret = track2 ; } } return ret ; }
Extract track 2 Equivalent data