Ref: do not re-invent the wheel, use existing lib

This commit is contained in:
Laurent Clouet
2024-12-28 13:55:44 +01:00
parent 00bb8b2b1e
commit 58bfec1221
2 changed files with 7 additions and 4 deletions

View File

@@ -46,6 +46,7 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.12.+'
implementation 'com.squareup.okhttp3:okhttp-urlconnection:4.12.+'
implementation 'org.slf4j:slf4j-nop:1.7.36'
implementation 'commons-io:commons-io:2.11.0'
}
application {

View File

@@ -23,6 +23,7 @@ import com.sheepit.client.logger.Log;
import com.sheepit.client.datamodel.server.Chunk;
import com.sheepit.client.utils.Utils;
import lombok.AllArgsConstructor;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.io.IOException;
@@ -203,9 +204,9 @@ public class DirectoryManager {
for (File file : files) {
if (file.isFile()) {
try {
String extension = file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase();
String name = file.getName().substring(0, file.getName().length() - 1 * extension.length());
if (".wool".equals(extension)) {
String extension = FilenameUtils.getExtension(file.getName()).toLowerCase();
String name = FilenameUtils.removeExtension(file.getName());
if ("wool".equals(extension)) {
// check if the md5 of the file is ok
String md5_local = Utils.md5(file.getAbsolutePath());
@@ -214,10 +215,11 @@ public class DirectoryManager {
}
}
}
catch (StringIndexOutOfBoundsException e) { // because the file does not have an . his path
catch (IllegalArgumentException e) { // because the file does not have an . his path
}
}
}
return files_local;
}