2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.commons.file;
14 public class FilePathParser {
16 public static String getFileExtension(final File file) {
17 final String fullFileName = file.getName();
19 return getFileExtension(fullFileName);
22 public static String getFileExtension(final String fullFileName) {
23 final int dot = fullFileName.lastIndexOf('.');
28 fileExtension = fullFileName.substring(dot + 1);
29 fileExtension = fileExtension.toLowerCase();
35 public static String getFileNameWithoutExtension(final File file) {
36 final String fullFileName = file.getName();
37 return getFileNameWithoutExtension(fullFileName);
40 public static String getFileNameWithoutExtension(final String fullFileName) {
41 final int dot = fullFileName.lastIndexOf('.');
44 fileName = fullFileName;
46 fileName = fullFileName.substring(0, dot);
51 public static String getFileSizeDescription(long fileSize) {
54 if (fileSize > (1024 * 1024 * 10)) {
55 fileSize = fileSize / (1024 * 1024);
57 } else if (fileSize > (1024 * 10)) {
58 fileSize = fileSize / 1024;
62 return String.valueOf(fileSize) + " " + suffix;