Skip to content

Commit

Permalink
Fixes #87 - Implement getFiles method for Path implementation (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Sep 27, 2023
1 parent 95a1e1b commit 7a86991
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions path/src/main/java/com/manorrock/hummingbird/path/PathFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.nio.file.Files;
import java.nio.file.Path;
import com.manorrock.hummingbird.api.VirtualFile;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -44,7 +46,7 @@ public class PathFile implements VirtualFile {
/**
* Stores the file.
*/
private Path file;
private Path path;

/**
* Stores the file system.
Expand All @@ -55,10 +57,10 @@ public class PathFile implements VirtualFile {
* Constructor.
*
* @param fileSystem the file system.
* @param file the file.
* @param path the path.
*/
public PathFile(PathFileSystem fileSystem, Path file) {
this.file = file;
public PathFile(PathFileSystem fileSystem, Path path) {
this.path = path;
this.fileSystem = fileSystem;
}

Expand All @@ -73,7 +75,7 @@ public InputStream asInputStream() {
PipedOutputStream pipedOutput = new PipedOutputStream();
try {
result = new PipedInputStream(pipedOutput);
Files.copy(file, pipedOutput);
Files.copy(path, pipedOutput);
} catch (IOException ioe) {
// swallowed up on purpose.
}
Expand All @@ -82,17 +84,24 @@ public InputStream asInputStream() {

@Override
public VirtualFile getFile(String path) {
Path newPath = Path.of(file.toString(), path).normalize();
Path newPath = Path.of(path.toString(), path).normalize();
return new PathFile(fileSystem, newPath);
}

@Override
public List<VirtualFile> getFiles() {
throw new UnsupportedOperationException("Not supported yet.");
File[] files = path.toFile().listFiles();
ArrayList<VirtualFile> result = new ArrayList<>();
if (files.length > 0) {
for (File file : files) {
result.add(new PathFile(fileSystem, file.toPath()));
}
}
return result;
}

@Override
public boolean isDirectory() {
return file.toFile().isDirectory();
return path.toFile().isDirectory();
}
}

0 comments on commit 7a86991

Please sign in to comment.