changeset 1273:ed6e8bd78c11

sort in DirHandler
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Dec 2018 03:35:38 -0700
parents 95f6540b27f9
children 383f924dfe9d
files src/luan/webserver/handlers/DirHandler.java
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r 95f6540b27f9 -r ed6e8bd78c11 src/luan/webserver/handlers/DirHandler.java
--- a/src/luan/webserver/handlers/DirHandler.java	Mon Nov 12 21:41:25 2018 -0700
+++ b/src/luan/webserver/handlers/DirHandler.java	Tue Dec 04 03:35:38 2018 -0700
@@ -7,6 +7,8 @@
 import java.io.IOException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Comparator;
 import java.util.Date;
 import luan.webserver.Handler;
 import luan.webserver.Request;
@@ -21,6 +23,12 @@
 		this.fileHandler = fileHandler;
 	}
 
+	private static final Comparator<File> sorter = new Comparator<File>() {
+		public int compare(File f1, File f2) {
+			return f1.getName().compareTo(f2.getName());
+		}
+	};
+
 	public Response handle(Request request) {
 		try {
 			File file = fileHandler.file(request);
@@ -34,7 +42,9 @@
 				writer.write( "<body>" );
 				writer.write( "<h1>Directory: "+request.path+"</h1>" );
 				writer.write( "<table border=0>" );
-				for( File child : file.listFiles() ) {
+				File[] a = file.listFiles();
+				Arrays.sort(a,sorter);
+				for( File child : a ) {
 					String name = child.getName();
 					if( child.isDirectory() )
 						name += '/';