package com.dbnt.faisp.config; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; @Service @RequiredArgsConstructor public class BaseService { @Value("${spring.servlet.multipart.location}") protected String locationPath; protected String calculationSize(double fileSize){ String[] units = {"bytes", "KB", "MB", "GB", "TB", "PB"}; double unitSelector = Math.floor(Math.log(fileSize)/Math.log(1024)); if(fileSize>0){ return Math.round((fileSize/Math.pow(1024, unitSelector))*100)/100d+" "+units[(int)unitSelector]; }else{ return ""; } } public void deleteStoredFile(File deleteFile){ deleteFile.delete(); } }