}
}
}
if (file != null) {
if (!file.exists()) {
throw new UnexpectedException("Your file does not exists (" + file + ")");
}
if (!file.canRead()) {
throw new UnexpectedException("Can't read your file (" + file + ")");
}
if (!file.isFile()) {
throw new UnexpectedException("Your file is not a real file (" + file + ")");
}
response.direct = file;
} else {
if (response.getHeader("Content-Length") != null) {
response.direct = is;
} else {
if (length != 0) {
response.setHeader("Content-Length", length + "");
response.direct = is;
} else {
try {
byte[] buffer = new byte[8192];
int count = 0;
while ((count = is.read(buffer)) > -1) {
response.out.write(buffer, 0, count);
}
} finally {
try {
is.close();
} catch (IOException e) {
}
}
}
}
}
} catch (Exception e) {
throw new UnexpectedException(e);
}
}