protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("FollowController:");
FollowedFile ff = (FollowedFile) request.getSession(true).getAttribute("followed_file");
if (ff == null)
{
System.out.println("FollowController: followed_file attr is null");
}
if (ff != null) {
File f = new File(ff.getFileName());
System.out.println("FollowController: file is: " + ff.getFileName());
if (f.exists()) {
System.out.println("FollowController: file exists");
long currentLength = f.length();
long readSize = 0;
int listSize = ff.getLines().size();
System.out.println("FollowController: current len:" + currentLength + " lastknownlen: " + ff.getLastKnowLength() + " listsize: " + listSize);
if (currentLength < ff.getLastKnowLength()) {
//
// file length got reset
//
ff.setLastKnowLength(0);
ff.getLines().add(listSize, " ------------- THE FILE HAS BEEN TRUNCATED --------------");
}
BackwardsFileStream bfs = new BackwardsFileStream(f, currentLength);
try {
LineReader br = new LineReader(bfs, true);
String s;
while (readSize < currentLength - ff.getLastKnowLength() && (s = br.readLine()) != null) {
if (ff.getLines().size() >= maxLines) {
if (listSize > 0) {
ff.getLines().remove(0);
listSize--;
} else {
break;
}
}
ff.getLines().add(listSize, s);
readSize += s.length();
if (ff.getLastKnowLength() == 0 && ff.getLines().size() >= initialLines) break;
}
if (readSize > currentLength - ff.getLastKnowLength() && listSize > 0) {
ff.getLines().remove(listSize-1);
}
ff.setLastKnowLength(currentLength);
} finally {
bfs.close();
}
} else {
ff.getLines().clear();
}
request.getSession(true).setAttribute(fileAttributeName, ff);
}
return new ModelAndView(getViewName());