2024-07-05 21:48:33 +02:00
|
|
|
package stirling.software.SPDF.utils;
|
|
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
2025-03-10 21:35:04 +01:00
|
|
|
import java.util.Locale;
|
2024-07-05 21:48:33 +02:00
|
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Data;
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
@Data
|
|
|
|
public class FileInfo {
|
2024-12-24 09:52:53 +00:00
|
|
|
private static final DateTimeFormatter DATE_FORMATTER =
|
|
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
2024-07-05 21:48:33 +02:00
|
|
|
private String fileName;
|
|
|
|
private String filePath;
|
|
|
|
private LocalDateTime modificationDate;
|
|
|
|
private long fileSize;
|
|
|
|
private LocalDateTime creationDate;
|
|
|
|
|
|
|
|
// Converts the file path string to a Path object.
|
|
|
|
public Path getFilePathAsPath() {
|
|
|
|
return Paths.get(filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formats the file size into a human-readable string.
|
|
|
|
public String getFormattedFileSize() {
|
|
|
|
if (fileSize >= 1024 * 1024 * 1024) {
|
2025-03-10 21:35:04 +01:00
|
|
|
return String.format(Locale.US, "%.2f GB", fileSize / (1024.0 * 1024 * 1024));
|
2024-07-05 21:48:33 +02:00
|
|
|
} else if (fileSize >= 1024 * 1024) {
|
2025-03-10 21:35:04 +01:00
|
|
|
return String.format(Locale.US, "%.2f MB", fileSize / (1024.0 * 1024));
|
2024-07-05 21:48:33 +02:00
|
|
|
} else if (fileSize >= 1024) {
|
2025-03-10 21:35:04 +01:00
|
|
|
return String.format(Locale.US, "%.2f KB", fileSize / 1024.0);
|
2024-07-05 21:48:33 +02:00
|
|
|
} else {
|
|
|
|
return String.format("%d Bytes", fileSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formats the modification date to a string.
|
|
|
|
public String getFormattedModificationDate() {
|
|
|
|
return modificationDate.format(DATE_FORMATTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formats the creation date to a string.
|
|
|
|
public String getFormattedCreationDate() {
|
|
|
|
return creationDate.format(DATE_FORMATTER);
|
|
|
|
}
|
|
|
|
}
|