class FileListJsonBuilder {

    public String buildFileListJson(final File directory) {
        String result = "{\"files\":[]}";
        Collection<File> messageFiles = fileUtilsWrapper.listFiles(directory);
        if (messageFiles != null) {
            List<String> fileNames = getFileNames(messageFiles);
            Collections.sort(fileNames);
            result = getJson(fileNames);
        } else {
            logger.debug("The directory '" + directory + "' has not been created yet, or an I/O error occurred.");
        }
        return result;
    }

}