Created
November 10, 2016 05:07
-
-
Save mushfek/b78ca28747ff08e6ebd89d0700489543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AverageFileSize extends SimpleTagSupport { | |
private boolean humanReadable; | |
private List<AttachedFile> fileList; | |
public AverageFileSize(List<AttachedFile> fileList) { | |
this.humanReadable = false; | |
this.fileList = fileList; | |
} | |
public AverageFileSize(boolean humanReadable, List<AttachedFile> fileList) { | |
this.humanReadable = humanReadable; | |
this.fileList = fileList; | |
} | |
@Override | |
public void doTag() throws JspException, IOException { | |
long fileSizeAvg = 0; | |
for (AttachedFile f : fileList) { | |
fileSizeAvg += f.getSize(); | |
} | |
fileSizeAvg /= fileList.size(); | |
try { | |
String fileSize = humanReadable ? getPrettyFileSize(fileSizeAvg) : Long.toString(fileSizeAvg) + "B"; | |
getJspContext().getOut().write(fileSize); | |
} catch (IOException e) { | |
throw new SkipPageException(e); | |
} | |
} | |
private String getPrettyFileSize(long sizeInBytes) { | |
String prettyFileSize = ""; | |
/** | |
* Logic for formatting to human readable | |
*/ | |
return prettyFileSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment