protected long getDataSize(DataHandler dh) {
long dataSize = -1L;
try {
DataSource ds = dh.getDataSource();
//Do files our selfs since this is costly to read in. Ask the file system.
// This is 90% of the use of attachments.
if (ds instanceof javax.activation.FileDataSource) {
javax.activation.FileDataSource fdh =
(javax.activation.FileDataSource) ds;
java.io.File df = fdh.getFile();
if (!df.exists()) {
throw new RuntimeException(
JavaUtils.getMessage("noFile",
df.getAbsolutePath()));
}
dataSize = df.length();
} else {
dataSize = 0;
java.io.InputStream in = ds.getInputStream();
byte[] readbuf = new byte[64 * 1024];
int bytesread;
do {
bytesread = in.read(readbuf);