27
27
import com .google .gson .Gson ;
28
28
import java .io .File ;
29
29
import java .util .ArrayList ;
30
+ import java .util .Arrays ;
30
31
import java .util .List ;
31
32
32
33
public class SettingsActivity extends AppCompatActivity {
@@ -324,7 +325,7 @@ private void setupBackendSelectorDialog() {
324
325
}
325
326
326
327
private void setupModelSelectorDialog () {
327
- String [] pteFiles = listLocalFile ("/data/local/tmp/llama/" , ".pte" );
328
+ String [] pteFiles = listLocalFile ("/data/local/tmp/llama/" , new String [] { ".pte" } );
328
329
AlertDialog .Builder modelPathBuilder = new AlertDialog .Builder (this );
329
330
modelPathBuilder .setTitle ("Select model path" );
330
331
@@ -341,13 +342,17 @@ private void setupModelSelectorDialog() {
341
342
modelPathBuilder .create ().show ();
342
343
}
343
344
344
- private static String [] listLocalFile (String path , String suffix ) {
345
+ private static boolean fileHasExtension (String file , String [] suffix ) {
346
+ return Arrays .stream (suffix ).anyMatch (entry -> file .endsWith (entry ));
347
+ }
348
+
349
+ private static String [] listLocalFile (String path , String [] suffix ) {
345
350
File directory = new File (path );
346
351
if (directory .exists () && directory .isDirectory ()) {
347
- File [] files = directory .listFiles ((dir , name ) -> name . toLowerCase (). endsWith ( suffix ));
352
+ File [] files = directory .listFiles ((dir , name ) -> ( fileHasExtension ( name , suffix ) ));
348
353
String [] result = new String [files .length ];
349
354
for (int i = 0 ; i < files .length ; i ++) {
350
- if (files [i ].isFile () && files [i ].getName (). endsWith ( suffix )) {
355
+ if (files [i ].isFile () && fileHasExtension ( files [i ].getName (), suffix )) {
351
356
result [i ] = files [i ].getAbsolutePath ();
352
357
}
353
358
}
@@ -380,11 +385,8 @@ private void setupModelTypeSelectorDialog() {
380
385
}
381
386
382
387
private void setupTokenizerSelectorDialog () {
383
- String [] binFiles = listLocalFile ("/data/local/tmp/llama/" , ".bin" );
384
- String [] modelFiles = listLocalFile ("/data/local/tmp/llama/" , ".model" );
385
- String [] tokenizerFiles = new String [binFiles .length + modelFiles .length ];
386
- System .arraycopy (binFiles , 0 , tokenizerFiles , 0 , binFiles .length );
387
- System .arraycopy (modelFiles , 0 , tokenizerFiles , binFiles .length , modelFiles .length );
388
+ String [] tokenizerFiles =
389
+ listLocalFile ("/data/local/tmp/llama/" , new String [] {".bin" , ".json" , ".model" });
388
390
AlertDialog .Builder tokenizerPathBuilder = new AlertDialog .Builder (this );
389
391
tokenizerPathBuilder .setTitle ("Select tokenizer path" );
390
392
tokenizerPathBuilder .setSingleChoiceItems (
0 commit comments