private File generate ( String pattern , int generation , int unique ) throws IOException { File file = null ; String word = "" ; int ix = 0 ; boolean sawg = false ; boolean sawu = false ; while ( ix < pattern . length ( ) ) { char ch = pattern . charAt ( ix ) ; ix ++ ; char ch2 = 0 ; if ( ix < pattern . length ( ) ) { ch2 = Character . toLowerCase ( pattern . charAt ( ix ) ) ; } if ( ch == ' ' ) { if ( file == null ) { file = new File ( word ) ; } else { file = new File ( file , word ) ; } word = "" ; continue ; } else if ( ch == ' ' ) { if ( ch2 == ' ' ) { String tmpDir = System . getProperty ( "java.io.tmpdir" ) ; if ( tmpDir == null ) { tmpDir = System . getProperty ( "user.home" ) ; } file = new File ( tmpDir ) ; ix ++ ; word = "" ; continue ; } else if ( ch2 == ' ' ) { file = new File ( System . getProperty ( "user.home" ) ) ; // Android-changed: Don't make a special exemption for setuid programs. // // if (isSetUID()) { // // Ok, we are in a set UID program. For safety's sake // // we disallow attempts to open files relative to %h. // throw new IOException("can't use %h in set UID program"); // } ix ++ ; word = "" ; continue ; } else if ( ch2 == ' ' ) { word = word + generation ; sawg = true ; ix ++ ; continue ; } else if ( ch2 == ' ' ) { word = word + unique ; sawu = true ; ix ++ ; continue ; } else if ( ch2 == ' ' ) { word = word + "%" ; ix ++ ; continue ; } } word = word + ch ; } if ( count > 1 && ! sawg ) { word = word + "." + generation ; } if ( unique > 0 && ! sawu ) { word = word + "." + unique ; } if ( word . length ( ) > 0 ) { if ( file == null ) { file = new File ( word ) ; } else { file = new File ( file , word ) ; } } return file ; }
Generate a filename from a pattern .