package com.phome.so;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.struts.upload.FormFile;
public class FileWrapper {
private FormFile file;
public FileWrapper(FormFile file) {
super();
this.file = file;
}
public FormFile getFile() {
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
public String getDate()
{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date());
}
public String gerName()
{
return file.getFileName();
}
public String gerSize()
{
long s=file.getFileSize();
String t="";
if(s/(1024*1024*1024)>0)
{
t=s/1024/1024/1024+"GB";
}
if(s/(1024*1024*1024)==0)
{
t=s/1024/1024+"MB";
}
if(s/(1024*1024)==0)
{
t=s/1024+"KB";
}
if(s/1024==0)
{
t=s+"字节";
}
return t;
}
public String getMD5()
{
return MD5.create(file.getContentType()).toUpperCase();
}
public String gerUrl()
{
return "download.do?md5="+getMD5();
}
public static FileWrapper[] warpper(FormFile[] files)
{
FileWrapper f[]=new FileWrapper[files.length];
for(int i=0;i<f.length;i++)
{
f[i]=new FileWrapper(files[i]);
}
return f;
}
}