/*
- * Svjatoslav Commons - shared library of common functionality.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
*/
-
package eu.svjatoslav.commons.file;
import java.io.File;
public class FilePathParser {
- public static String getFileExtension(final File file) {
- final String fullFileName = file.getName();
-
- return getFileExtension(fullFileName);
- }
-
- public static String getFileExtension(final String fullFileName) {
- final int dot = fullFileName.lastIndexOf('.');
- String fileExtension;
- if (dot == -1)
- fileExtension = "";
- else {
- fileExtension = fullFileName.substring(dot + 1);
- fileExtension = fileExtension.toLowerCase();
- }
-
- return fileExtension;
- }
-
- public static String getFileNameWithoutExtension(final File file) {
- final String fullFileName = file.getName();
- return getFileNameWithoutExtension(fullFileName);
- }
-
- public static String getFileNameWithoutExtension(final String fullFileName) {
- final int dot = fullFileName.lastIndexOf('.');
- String fileName;
- if (dot == -1)
- fileName = fullFileName;
- else
- fileName = fullFileName.substring(0, dot);
-
- return fileName;
- }
-
- public static String getFileSizeDescription(long fileSize) {
- String suffix = "b";
-
- if (fileSize > (1024 * 1024 * 10)) {
- fileSize = fileSize / (1024 * 1024);
- suffix = "Mb";
- } else if (fileSize > (1024 * 10)) {
- fileSize = fileSize / 1024;
- suffix = "Kb";
- }
-
- final String fileSizeString = String.valueOf(fileSize) + " " + suffix;
-
- return fileSizeString;
- }
+ public static String getFileExtension(final File file) {
+ final String fullFileName = file.getName();
+
+ return getFileExtension(fullFileName);
+ }
+
+ public static String getFileExtension(final String fullFileName) {
+ final int dot = fullFileName.lastIndexOf('.');
+ String fileExtension;
+ if (dot == -1)
+ fileExtension = "";
+ else {
+ fileExtension = fullFileName.substring(dot + 1);
+ fileExtension = fileExtension.toLowerCase();
+ }
+
+ return fileExtension;
+ }
+
+ public static String getFileNameWithoutExtension(final File file) {
+ final String fullFileName = file.getName();
+ return getFileNameWithoutExtension(fullFileName);
+ }
+
+ public static String getFileNameWithoutExtension(final String fullFileName) {
+ final int dot = fullFileName.lastIndexOf('.');
+ String fileName;
+ if (dot == -1)
+ fileName = fullFileName;
+ else
+ fileName = fullFileName.substring(0, dot);
+
+ return fileName;
+ }
+
+ public static String getFileSizeDescription(long fileSize) {
+ String suffix = "b";
+
+ if (fileSize > (1024 * 1024 * 10)) {
+ fileSize = fileSize / (1024 * 1024);
+ suffix = "MiB";
+ } else if (fileSize > (1024 * 10)) {
+ fileSize = fileSize / 1024;
+ suffix = "KiB";
+ }
+
+ return String.valueOf(fileSize) + " " + suffix;
+ }
}