-
-
Save glenwatson/5889176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Snippet> listSnippets() throws IOException { | |
verifyRootDirectoryExists(); | |
File[] txtfiles = DIRECTORY.listFiles(new FileFilter() { | |
public boolean accept(File file) { | |
return file.isFile() && !file.isHidden() && file.getName().endsWith(".txt"); | |
} | |
}); | |
File[] titlefiles = DIRECTORY.listFiles(new FileFilter() { | |
public boolean accept(File file) { | |
return file.isFile() && !file.isHidden() && title.getName().endsWith(".title"); | |
} | |
}); | |
List<Snippet> result = Collections.emptyList(); | |
if(txtfiles != null) { | |
result = new ArrayList<Snippet>(txtfiles.length); | |
for (File txtfile : txtfiles) { | |
Snippet snippet = new Snippet(txtfile); | |
snippet.setTitle("untitled"); | |
for (File titlefile : titlefiles) { | |
if(txtfile.getName().substring(0, txtfile.getName().length() - ".txt".length()).equals(titlefile.getName().substring(0, titlefile.getName().length() - ".title".length()))) { | |
snippet.setTitle(FileUtils.readFileToString(titlefile, 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