I am using contentService.streamDirectory to get a callback containing all directories/files within a BitBucket project, then I am using a for loop and "callback.getFiles().get(i).toString()" to print out each filepath in a web page using a writer object. It looks something like this:
- folder_1/file_1.txt
- folder_1/file_2.txt
- folder_2/folder_3/file_3.txt
- folder_2/file_4.txt
What I want to do is generate something that resembles the directory structure and groups by folders, like this:
- folder_1
- file_1.txt
- file_2.txt
- folder_2
- folder_3
- file_3.txt
- file_4.txt
- folder_3
I'm a bit unsure how to go about this. The current method for printing out is as follows:
resp.setContentType("text/html");
resp.getWriter().print("<html><body><p>Repository: " + repo.getName() +);
for (int i = 0; i < callback.getFiles().size(); i++) {
resp.getWriter().println("<p><a href=\"/\">" + callback.getFiles().get(i).toString() + "</a></p>");
}
resp.getWriter().print("</body></html>");
I'm sure a whole lot of loops are required, I know there's a Files.walk() method but it looks like you point to the starting folder within the computer files, I do not know if its possible to point this to BitBucket? Thanks for any help you can give.
callback.getFiles()? A list ofjava.io.File,java.nio.file.Path, or something different?