package jp.terasoluna.fw.web.struts.actions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import jp.terasoluna.fw.exception.SystemException;
import org.apache.commons.lang.StringUtils;
public class DownloadFile extends AbstractDownloadObject {
private static final long serialVersionUID = 1461327659352290323L;
/**
protected File file = null;
public DownloadFile(File file) {
this(null, file);
}
public DownloadFile(String name, File file) {
super(name, null, null);
this.file = file;
if (file == null) {
throw new SystemException(new IllegalArgumentException(
"Download content must not be null"),
NO_DOWNLOAD_CONTENT_ERROR);
}
if (StringUtils.isEmpty(getName())) {
setName(file.getName());
}
}
@Override
public int getLengthOfData() {
return (int) file.length();
}
@Override
protected InputStream getStreamInternal() throws FileNotFoundException {
return new FileInputStream(file);
}
}