
package water.api;

import java.io.File;

import com.google.gson.*;

public class TypeaheadFileRequest extends TypeaheadRequest {

  public TypeaheadFileRequest() {
    super("Provides a simple JSON array of filtered local files.","");
  }

  @Override
  protected JsonArray serve(String filter, int limit) {
    File base = null;
    String filterPrefix = "";
    if( !filter.isEmpty() ) {
      File file = new File(filter);
      if( file.isDirectory() ) {
        base = file;
      } else {
        base = file.getParentFile();
        filterPrefix = file.getName().toLowerCase();
      }
    }
    if( base == null ) base = new File(".");

    JsonArray array = new JsonArray();
    for( File file : base.listFiles() ) {
      if( file.isHidden() ) continue;
      if( file.getName().toLowerCase().startsWith(filterPrefix) ) {
        String s = file.getPath();
        array.add(new JsonPrimitive(s));
      }
      if( array.size() == limit) break;
    }
    return array;
  }
}

@@ -686,25 +686,23 @@
 %0A   
- for(
  File
+%5B%5D
  file
- :
+s =
  bas
@@ -714,16 +714,82 @@
 tFiles()
+;%0A    if( files == null ) return array;%0A    for( File file : files
  ) %7B%0A   
@@ -892,45 +892,8 @@
 x) )
- %7B%0A        String s = file.getPath();
 %0A   
@@ -929,20 +929,25 @@
 ive(
-s));%0A      %7D
+file.getPath()));
 %0A   

Fix NPE for mispelled/missing directories in type-ahead file lookup