Skip to content

Commit

Permalink
Fix: Linux file extension handling, delegate to Apache Commons #135
Browse files Browse the repository at this point in the history
  • Loading branch information
SonarSonic committed Apr 11, 2024
1 parent f42c588 commit fdd42b1
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/main/java/drawingbot/files/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,23 @@ public static FileChooser.ExtensionFilter registerSingleExtensionFilter(String d
}

public static File removeExtension(File file){
String path = file.toString();
return new File(removeExtension(path));
return new File(removeExtension(file.toString()));
}

public static String removeExtension(String string){
int end = string.lastIndexOf(".");
if(end == -1){
return string;
}
string = string.substring(0, end);
return string;
public static String removeExtension(String path){
return FilenameUtils.removeExtension(path);
}

public static String getExtension(String string){
int begin = string.lastIndexOf(".");
if(begin == -1){
public static String getExtension(String path){
String result = FilenameUtils.getExtension(path);
if(result == null || result.isEmpty()){
return "";
}
return string.substring(begin);
return FilenameUtils.EXTENSION_SEPARATOR + result;
}

public static boolean hasExtension(String string){
int begin = string.lastIndexOf(".");
return begin != -1;
public static boolean hasExtension(String path){
return FilenameUtils.indexOfExtension(path) != -1;
}

public static String getSafeFileName(String filename){
Expand Down

0 comments on commit fdd42b1

Please sign in to comment.