* path. This method is disk-intensive and may take some time on larger
* directories!
*
- * @return The file for the base path
+ * @return The file for the base path, or <code>null</code> if the base
+ * path does not denote an existing directory
*/
public ProjectFile getBaseFile() {
- ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", true, false);
- scanDirectory(new File(basePath), rootProjectFile);
+ File basePathFile = new File(basePath);
+ if (!basePathFile.exists() || !basePathFile.isDirectory()) {
+ return null;
+ }
+ ProjectFileImpl rootProjectFile = new ProjectFileImpl(null, "", 0, true, false);
+ scanDirectory(basePathFile, rootProjectFile);
return rootProjectFile;
}
return;
}
for (File file: directory.listFiles()) {
- ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.isDirectory(), file.isHidden());
+ ProjectFileImpl projectFileChild = projectFile.addFile(file.getName(), file.length(), file.isDirectory(), file.isHidden());
if (file.isDirectory()) {
scanDirectory(file, projectFileChild);
}
/** The name of this project file. */
private final String name;
+ /** The size of the file. */
+ private final long size;
+
/** Whether this project file is a directory. */
private final boolean directory;
* the new project file does not have a parent
* @param name
* The name of the project file
+ * @param size
+ * The size of the file
* @param isDirectory
* <code>true</code> if this project file is a directory,
* <code>false</code> otherwise
* <code>true</code> if this project file is hidden,
* <code>false</code> otherwise
*/
- ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, boolean isDirectory, boolean isHidden) {
+ ProjectFileImpl(ProjectFileImpl parentProjectFile, String name, long size, boolean isDirectory, boolean isHidden) {
this.parentProjectFile = parentProjectFile;
this.name = name;
+ this.size = size;
this.directory = isDirectory;
this.hidden = isHidden;
}
}
/**
+ * {@inheritDoc}
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
* @see net.pterodactylus.jsite.project.ProjectFile#getParents()
*/
public List<ProjectFile> getParents() {
}
/**
+ * {@inheritDoc}
+ */
+ /* TODO - caching? */
+ public String getCompletePath() {
+ StringBuilder completePath = new StringBuilder();
+ ProjectFileImpl currentProjectFile = this;
+ do {
+ completePath.insert(0, File.separatorChar).insert(0, this.getName());
+ } while ((currentProjectFile = currentProjectFile.parentProjectFile) != null);
+ return completePath.substring(1);
+ }
+
+ /**
* @see net.pterodactylus.jsite.project.ProjectFile#isFile()
*/
public boolean isFile() {
*
* @param name
* The name of the file
+ * @param size
+ * The size of the file
* @param isDirectory
* <code>true</code> if the new file is a directory,
* <code>false</code> otherwise
* <code>false</code> otherwise
* @return The created project file
*/
- public ProjectFileImpl addFile(String name, boolean isDirectory, boolean isHidden) {
- ProjectFileImpl newProjectFile = new ProjectFileImpl(this, name, isDirectory, isHidden);
+ public ProjectFileImpl addFile(String name, long size, boolean isDirectory, boolean isHidden) {
+ ProjectFileImpl newProjectFile = new ProjectFileImpl(this, name, size, isDirectory, isHidden);
childProjectFiles.add(newProjectFile);
return newProjectFile;
}