Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit b133a99

Browse files
authored
Changed adapter so it works with directory names (#120)
* Implement #119 - Closes #119 * Update DirectoryEntry.java
1 parent 63aa926 commit b133a99

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/handler/DirectoryEntry.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ public final File getFile(final String path){
146146
final String fileName = targetFile.getParentFile() == null ? targetFile.getPath() : targetFile.getName();
147147

148148
// for each file in parent directory, run adapter to find file that matches adapted name
149-
for(final File file : Objects.requireNonNullElse(parentFile.listFiles(), new File[0])){
150-
if(fileName.equals(file.isDirectory() ? file.getName() : adapter.getName(file))) // use adapter name only if not a directory
149+
for(final File file : Objects.requireNonNullElse(parentFile.listFiles(), new File[0]))
150+
if(fileName.equals(adapter.getName(file)))
151151
return file;
152-
}
153152
return null;
154153
}
155154

@@ -200,7 +199,7 @@ public final byte[] getBytes(final String path){
200199
}else{
201200
try{
202201
final File file = Objects.requireNonNull(getFile(path)); // check if file is allowed
203-
return !file.isDirectory() ? adapter.getBytes(file, Files.readAllBytes(file.toPath())) : null; // adapt bytes here
202+
return file.isFile() ? adapter.getBytes(file, Files.readAllBytes(file.toPath())) : null; // adapt bytes here
204203
}catch(final NullPointerException | IOException ignored){
205204
return null;
206205
}

0 commit comments

Comments
 (0)