Skip to content

Instantly share code, notes, and snippets.

@jab416171
Created June 29, 2013 00:50
Show Gist options
  • Save jab416171/5889173 to your computer and use it in GitHub Desktop.
Save jab416171/5889173 to your computer and use it in GitHub Desktop.
public List<Snippet> listSnippets() throws IOException {
verifyRootDirectoryExists();
File[] files = DIRECTORY.listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isFile() && !file.isHidden();
}
});
List<Snippet> result = Collections.emptyList();
if(files != null) {
result = new ArrayList<Snippet>(files.length);
for (File file : files) {
if(!file.getName().endsWith(".txt")) continue;
Snippet snippet = new Snippet(file);
snippet.setTitle("untitled");
for (File title : files) {
if(!title.getName().endsWith(".title")) continue;
if(file.getName().substring(0, file.getName().length() - ".txt".length()).equals(title.getName().substring(0, title.getName().length() - ".title".length()))) {
snippet.setTitle(FileUtils.readFileToString(title, CodeSnippetAction.UTF_8));
}
}
result.add(0, snippet);
}
}
Collections.sort(result);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment