List<File> totalList = Arrays.asList(files);
final List<File> list = new ArrayList<File>(totalList.size());
for (File file : totalList){
if (file.isFile() && file.canRead() && !file.isHidden() && file.length()>2 ){
try {
FileURLConnection conn = (FileURLConnection) file.toURI().toURL().openConnection();
if (!json && conn.getContentType().endsWith("java-serialized-object")){
list.add(file);
}
if (json && conn.getContentType().contains("json")){
list.add(file);
}
conn.close();
} catch (Exception e) {
logger.warning("Couldn't check contentType of potential state file:"+file.getName());
}
}
}