String formatted = format.format(new Date(lastModified)) + " GMT";
response.setHeader("Last-Modified", formatted);
}
// Guessing the charset (and closing the stream)
EncodingInfo encInfo = null;
FileInputStream input = null;
OutputStream output = null;
final byte[] b4 = new byte[4];
int count = 0;
try {
// open the output
input = new FileInputStream(file);
// Read the first four bytes, and determine charset encoding
count = input.read(b4);
encInfo = XmlCharsetDetector.getEncodingName(b4, count);
response.setCharacterEncoding(encInfo.getEncoding() != null ? encInfo.getEncoding() : "UTF-8");
// send out the first four bytes read
output = response.getOutputStream();
output.write(b4, 0, count);