X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Ffile%2FFilePathParser.java;h=05430c45af54bf1f6f6033adda82970b32ed599c;hb=37f0e9901f9ecaea7a28cba616e247415ebb9ea0;hp=c3cf2ea2e2b6347ddb7d41bb35bb3f68a0f8d5a1;hpb=b34ba4499cfbca09bc794a810e460bf1c86dcd34;p=svjatoslav_commons.git diff --git a/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java b/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java index c3cf2ea..05430c4 100755 --- a/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java +++ b/src/main/java/eu/svjatoslav/commons/file/FilePathParser.java @@ -1,66 +1,59 @@ /* - * Svjatoslav Commons - shared library of common functionality. - * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later 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; + } }