📄 browser_jsp.java
字号:
case 3:return sign * (new Long(f1.lastModified()).compareTo(new Long(f2.lastModified())));
case 4: { // Sort by extension
int tempIndexf1 = f1.getAbsolutePath().lastIndexOf('.');
int tempIndexf2 = f2.getAbsolutePath().lastIndexOf('.');
if ((tempIndexf1 == -1) && (tempIndexf2 == -1)){ // Neither have an extension
return sign * f1.getAbsolutePath().toUpperCase().compareTo(f2.getAbsolutePath().toUpperCase());
}
// f1 has no extension
else if(tempIndexf1 == -1) return -sign;
// f2 has no extension
else if(tempIndexf2 == -1) return sign;
// Both have an extension
else {
String tempEndf1 = f1.getAbsolutePath().toUpperCase().substring(tempIndexf1);
String tempEndf2 = f2.getAbsolutePath().toUpperCase().substring(tempIndexf2);
return sign * tempEndf1.compareTo(tempEndf2);
}
}
default:return 1;
}
}
}
}
/**
* Wrapperclass to wrap an OutputStream around a Writer
*/
class Writer2Stream extends OutputStream{
Writer out;
Writer2Stream (Writer w){
super();
out = w;
}
public void write(int i) throws IOException{
out.write(i);
}
public void write(byte[] b) throws IOException{
for (int i=0;i<b.length;i++){
int n=b[i];
//Convert byte to ubyte
n=((n>>>4)&0xF)*16+(n&0xF);
out.write (n);
}
}
public void write(byte[] b, int off, int len) throws IOException{
for (int i = off; i < off + len; i++){
int n=b[i];
n = ((n>>>4)&0xF)*16+(n&0xF);
out.write(n);
}
}
} //End of class Writer2Stream
static Vector expandFileList(String[] files, boolean inclDirs){
Vector v = new Vector();
if (files == null) return v;
for (int i=0; i < files.length; i++) v.add (new File(URLDecoder.decode(files[i])));
for (int i=0; i < v.size(); i++){
File f = (File) v.get(i);
if (f.isDirectory()){
File[] fs = f.listFiles();
for (int n = 0; n < fs.length; n++) v.add(fs[n]);
if (!inclDirs){
v.remove(i);
i--;
}
}
}
return v;
}
/**
* Method to build an absolute path
* @param dir the root dir
* @param name the name of the new directory
* @return if name is an absolute directory, returns name, else returns dir+name
*/
static String getDir (String dir, String name){
if (!dir.endsWith(File.separator)) dir = dir + File.separator;
File mv = new File (name);
String new_dir = null;
if (!mv.isAbsolute()){
new_dir = dir + name;
}
else new_dir = name;
return new_dir;
}
/**
* This Method converts a byte size in a kbytes or Mbytes size, depending on the size
* @param size The size in bytes
* @return String with size and unit
*/
static String convertFileSize (long size){
int divisor = 1;
String unit = "bytes";
if (size>= 1024*1024){
divisor = 1024*1024;
unit = "MB";
}
else if (size>= 1024){
divisor = 1024;
unit = "KB";
}
if (divisor ==1) return size /divisor + " "+unit;
String aftercomma = ""+100*(size % divisor)/divisor;
if (aftercomma.length() == 1) aftercomma="0"+aftercomma;
return size /divisor + "."+aftercomma+" "+unit;
}
/**
* Copies all data from in to out
* @param in the input stream
* @param out the output stream
* @param buffer copy buffer
*/
static void copyStreams (InputStream in, OutputStream out, byte[] buffer) throws IOException{
copyStreamsWithoutClose(in, out, buffer);
in.close();
out.close();
}
/**
* Copies all data from in to out
* @param in the input stream
* @param out the output stream
* @param buffer copy buffer
*/
static void copyStreamsWithoutClose (InputStream in, OutputStream out, byte[] buffer) throws IOException{
int b;
while((b=in.read(buffer))!=-1) out.write(buffer, 0, b);
}
/**
* Returns the Mime Type of the file, depending on the extension of the filename
*/
static String getMimeType(String fName){
fName = fName.toLowerCase();
if (fName.endsWith(".jpg")||fName.endsWith(".jpeg")||fName.endsWith(".jpe")) return "image/jpeg";
else if (fName.endsWith(".gif")) return "image/gif";
else if (fName.endsWith(".pdf")) return "application/pdf";
else if (fName.endsWith(".htm")||fName.endsWith(".html")||fName.endsWith(".shtml")) return "text/html";
else if (fName.endsWith(".avi")) return "video/x-msvideo";
else if (fName.endsWith(".mov")||fName.endsWith(".qt")) return "video/quicktime";
else if (fName.endsWith(".mpg")||fName.endsWith(".mpeg")||fName.endsWith(".mpe")) return "video/mpeg";
else if (fName.endsWith(".zip")) return "application/zip";
else if (fName.endsWith(".tiff")||fName.endsWith(".tif")) return "image/tiff";
else if (fName.endsWith(".rtf")) return "application/rtf";
else if (fName.endsWith(".mid")||fName.endsWith(".midi")) return "audio/x-midi";
else if (fName.endsWith(".xl")||fName.endsWith(".xls")||fName.endsWith(".xlv")||fName.endsWith(".xla")
||fName.endsWith(".xlb")||fName.endsWith(".xlt")||fName.endsWith(".xlm")||fName.endsWith(".xlk"))
return "application/excel";
else if (fName.endsWith(".doc")||fName.endsWith(".dot")) return "application/msword";
else if (fName.endsWith(".png")) return "image/png";
else if (fName.endsWith(".xml")) return "text/xml";
else if (fName.endsWith(".svg")) return "image/svg+xml";
else if (fName.endsWith(".mp3")) return "audio/mp3";
else if (fName.endsWith(".ogg")) return "audio/ogg";
else return "text/plain";
}
/**
* Converts some important chars (int) to the corresponding html string
*/
static String conv2Html(int i){
if (i=='&') return "&";
else if (i=='<') return "<";
else if (i=='>') return ">";
else if (i=='"') return """;
else return ""+(char)i;
}
/**
* Converts a normal string to a html conform string
*/
static String conv2Html(String st){
StringBuffer buf = new StringBuffer();
for (int i = 0;i<st.length();i++){
buf.append(conv2Html(st.charAt(i)));
}
return buf.toString();
}
/**
* Starts a native process on the server
* @param command the command to start the process
* @param dir the dir in which the process starts
*/
static String startProcess (String command, String dir) throws IOException{
StringBuffer ret = new StringBuffer();
String[] comm = new String[3];
comm[0] = COMMAND_INTERPRETER[0];
comm[1] = COMMAND_INTERPRETER[1];
comm[2] = command;
long start = System.currentTimeMillis();
try {
//Start process
Process ls_proc = Runtime.getRuntime().exec(comm, null, new File(dir));
//Get input and error streams
BufferedInputStream ls_in = new BufferedInputStream(ls_proc.getInputStream());
BufferedInputStream ls_err = new BufferedInputStream(ls_proc.getErrorStream());
boolean end = false;
while (!end){
int c=0;
while ((ls_err.available()>0)&&(++c <= 1000)){
ret.append (conv2Html(ls_err.read()));
}
c=0;
while ((ls_in.available()>0)&&(++c <= 1000)){
ret.append (conv2Html(ls_in.read()));
}
try{
ls_proc.exitValue();
//if the process has not finished, an exception is thrown
//else
while (ls_err.available()>0) ret.append(conv2Html(ls_err.read()));
while (ls_in.available()>0) ret.append(conv2Html(ls_in.read()));
end = true;
}
catch (IllegalThreadStateException ex){
//Process is running
}
//The process is not allowed to run longer than given time.
if (System.currentTimeMillis() - start > MAX_PROCESS_RUNNING_TIME){
ls_proc.destroy();
end = true;
ret.append ("!!!! Process has timed out, destroyed !!!!!");
}
try { Thread.sleep(50); } catch (InterruptedException ie) {}
}
}
catch (IOException e) {
ret.append ("Error: "+e);
}
return ret.toString();
}
/**
* Converts a dir string to a linked dir string
* @param dir the directory string (e.g. /usr/local/httpd)
* @param browserLink web-path to Browser.jsp
*/
static String dir2linkdir(String dir, String browserLink, int sortMode){
File f = new File(dir);
StringBuffer buf = new StringBuffer();
while (f.getParentFile()!=null){
if (f.canRead()){
String encPath = URLEncoder.encode(f.getAbsolutePath());
buf.insert(0, "<a href=\""+browserLink+"?sort="+sortMode+"&dir="+encPath+"\">"
+conv2Html(f.getName())+File.separator+"</a>");
}
else buf.insert(0, conv2Html(f.getName())+File.separator);
f = f.getParentFile();
}
if (f.canRead()){
String encPath = URLEncoder.encode(f.getAbsolutePath());
buf.insert(0, "<a href=\""+browserLink+"?sort="+sortMode+"&dir="+encPath+"\">"
+conv2Html(f.getAbsolutePath())+"</a>");
}
else buf.insert(0, f.getAbsolutePath());
return buf.toString();
}
/**
* Returns true if the given filename tends towards a packed file
*/
static boolean isPacked(String name, boolean gz){
return (name.toLowerCase().endsWith(".zip")||name.toLowerCase().endsWith(".jar")||
(gz&&name.toLowerCase().endsWith(".gz"))||name.toLowerCase().endsWith(".war"));
}
//---------------------------------------------------------------------------------------------------------------
private static java.util.Vector _jspx_dependants;
public java.util.List getDependants() {
return _jspx_dependants;
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("\r\n");
out.write('\r');
out.write('\n');
//Get the current browsing directory
request.setAttribute("dir", request.getParameter("dir"));
// The browser_name variable is used to keep track of the URI
// of the jsp file itself. It is used in all link-backs.
final String browser_name = request.getRequestURI();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -