Human File Size
jeesl:humanFileSize(sizeInLong) is a function that convert long value of file size to readable file size like 1kb, 2mb or 1gb.
| Long | Text |
|---|---|
| 7 | 7 B |
| 90 | 90 B |
| 470 | 470 B |
| 2452 | 2.5 kB |
| 7739 | 7.7 kB |
| 916547 | 916.5 kB |
| 7589951 | 7.6 MB |
| 69440052 | 69.4 MB |
| 743521564 | 743.5 MB |
| 1801143671 | 1.8 GB |
<p:dataTable var="l" value="#{humanFileSizeBean.list}" styleClass="jeesl-datatable">
<p:column headerText="Long">
<h:outputText value="#{l}"/>
</p:column>
<p:column headerText="Text">
<h:outputText value="#{jeesl:humanFileSize(l)}"/>
</p:column>
</p:dataTable>
@Named @ViewScoped
public class HumanFileSizeBean extends AbstractJeeBean implements Serializable
{
final static Logger logger = LoggerFactory.getLogger(HumanFileSizeBean.class);
private static final long serialVersionUID = 1L;
private List<Long> list;
public List<Long> getList(){return list;}
@PostConstruct
public void init()
{
super.initSecurity();
showcase();
}
private void showcase()
{
Random rnd = new Random();
list = new ArrayList<>();
for(int i=1;i<=10;i++)
{
int pow = (int)Math.pow(10,i);
list.add(Integer.valueOf(rnd.nextInt(pow)).longValue());
}
}
}