# Description This pull request includes several changes aimed at improving the code structure and removing redundant code. The most significant changes involve reordering methods, removing unnecessary annotations, and refactoring constructors to use dependency injection. Autowired now comes via constructor (which also doesn't need autowired annotation as its done by default for configuration) ## Checklist - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have performed a self-review of my own code - [ ] I have attached images of the change if it is UI based - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] If my code has heavily changed functionality I have updated relevant docs on [Stirling-PDFs doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) - [ ] My changes generate no new warnings - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only)
50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package stirling.software.SPDF.utils;
|
|
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Data;
|
|
|
|
@AllArgsConstructor
|
|
@Data
|
|
public class FileInfo {
|
|
private static final DateTimeFormatter DATE_FORMATTER =
|
|
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
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) {
|
|
return String.format("%.2f GB", fileSize / (1024.0 * 1024 * 1024));
|
|
} else if (fileSize >= 1024 * 1024) {
|
|
return String.format("%.2f MB", fileSize / (1024.0 * 1024));
|
|
} else if (fileSize >= 1024) {
|
|
return String.format("%.2f KB", fileSize / 1024.0);
|
|
} 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);
|
|
}
|
|
}
|