String[] names = file.list();
if (names == null) {
res.sendError(HttpServletResponse.SC_FORBIDDEN, "Can't access " + req.getRequestURI());
return;
}
PrintStream p = new PrintStream(new BufferedOutputStream(out), false, charSet); // 1.4
p.println("<HTML><HEAD>");
p.println("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=" + charSet + "\">");
p.println("<TITLE>Index of " + path + "</TITLE>");
p.println("</HEAD><BODY " + Serve.BGCOLOR);
p.println("><H2>Index of " + path + "</H2>");
p.println("<PRE>");
p.println("mode bytes last-changed name");
p.println("<HR>");
// TODO consider not case sensetive search
Arrays.sort(names);
long total = 0;
for (int i = 0; i < names.length; ++i) {
File aFile = new File(file, names[i]);
String aFileType;
long aFileLen;
if (aFile.isDirectory())
aFileType = "d";
else if (aFile.isFile())
aFileType = "-";
else
aFileType = "?";
String aFileRead = (aFile.canRead() ? "r" : "-");
String aFileWrite = (aFile.canWrite() ? "w" : "-");
String aFileExe = "-";
if (canExecute != null)
try {
if (((Boolean) canExecute.invoke(aFile, Utils.EMPTY_OBJECTS)).booleanValue())
aFileExe = "x";
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
String aFileSize = lengthftm.format(aFileLen = aFile.length());
total += (aFileLen + 1023) / 1024; //
while (aFileSize.length() < 12)
aFileSize = " " + aFileSize;
String aFileDate = Acme.Utils.lsDateStr(new Date(aFile.lastModified()));
while (aFileDate.length() < 14)
aFileDate += " ";
String aFileDirsuf = (aFile.isDirectory() ? "/" : "");
String aFileSuf = (aFile.isDirectory() ? "/" : "");
p.println(aFileType + aFileRead + aFileWrite + aFileExe + " " + aFileSize + " " + aFileDate + " "
+ "<A HREF=\"" + URLEncoder.encode(names[i], charSet) /* 1.4 */
+ aFileDirsuf + "\">" + names[i] + aFileSuf + "</A>");
}
if (total != 0)
total += 3;
p.println("total " + total);
p.println("</PRE>");
p.println("<HR>");
p.print(Serve.Identification.serverIdHtml);
p.println("</BODY></HTML>");
p.flush();
}
out.close();
}