Skip to content

Commit 5abb6a0

Browse files
committed
Some clean-ups
1 parent c54f6d1 commit 5abb6a0

File tree

10 files changed

+32
-42
lines changed

10 files changed

+32
-42
lines changed

src/express/expressfilter/ExpressFilterImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import express.http.response.Response;
66

77
import java.util.HashMap;
8-
import java.util.regex.Matcher;
9-
import java.util.regex.Pattern;
108

119
/**
1210
* @author Simon Reinisch
@@ -40,14 +38,14 @@ public void handle(Request req, Response res) {
4038

4139
// Parse params
4240
HashMap<String, String> params = matchURL(CONTEXT, requestPath);
43-
if(params == null)
41+
if (params == null)
4442
return;
4543

4644
req.setParams(params);
4745
REQUEST.handle(req, res);
4846
}
4947

50-
private static HashMap<String, String> matchURL(String filter, String url) {
48+
private HashMap<String, String> matchURL(String filter, String url) {
5149
HashMap<String, String> params = new HashMap<>();
5250
StringBuilder key = new StringBuilder();
5351
StringBuilder val = new StringBuilder();

src/express/expressfilter/ExpressFilterTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface ExpressFilterTask {
99

1010
/**
1111
* Returns the delay between the updates
12+
*
1213
* @return Update delay in milliseconds
1314
*/
1415
long getDelay();

src/express/http/SessionCookie.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public SessionCookie(long maxAge) {
1818
}
1919

2020
/**
21-
* @return Max age from this cookie
21+
* @return Max age from this cookie
2222
*/
2323
public long getMaxAge() {
2424
return MAX_AGE;
@@ -40,6 +40,7 @@ public Object getData() {
4040

4141
/**
4242
* Set the session data
43+
*
4344
* @param data The data object
4445
* @return The object itself
4546
*/

src/express/http/request/Request.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
import com.sun.net.httpserver.Headers;
44
import com.sun.net.httpserver.HttpExchange;
5-
import express.utils.MediaType;
6-
import express.utils.Utils;
75
import express.expressfilter.ExpressFilter;
86
import express.http.Cookie;
7+
import express.utils.Utils;
98

109
import java.io.*;
1110
import java.net.InetAddress;
@@ -284,21 +283,21 @@ public HashMap<String, String> getParams() {
284283
}
285284

286285
/**
287-
* Return all url-querys.
286+
* Set the params.
288287
*
289-
* @return An entire list of key-values
288+
* @param params
290289
*/
291-
public HashMap<String, String> getQuerys() {
292-
return QUERYS;
290+
public void setParams(HashMap<String, String> params) {
291+
this.params = params;
293292
}
294293

295294
/**
296-
* Set the params.
295+
* Return all url-querys.
297296
*
298-
* @param params
297+
* @return An entire list of key-values
299298
*/
300-
public void setParams(HashMap<String, String> params) {
301-
this.params = params;
299+
public HashMap<String, String> getQuerys() {
300+
return QUERYS;
302301
}
303302

304303
/**

src/express/http/request/RequestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.sun.net.httpserver.Headers;
44
import express.http.Cookie;
55

6-
import java.io.*;
6+
import java.io.UnsupportedEncodingException;
77
import java.net.URLDecoder;
88
import java.util.HashMap;
99
import java.util.List;

src/express/http/response/Response.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public Response setStatus(@NotNull Status status) {
6767
}
6868

6969
/**
70-
*
7170
* @return The current contentType
7271
*/
7372
public MediaType getContentType() {

src/express/middleware/ExpressCookieSession.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package express.middleware;
22

3-
import express.utils.Utils;
43
import express.events.HttpRequest;
54
import express.expressfilter.ExpressFilter;
65
import express.expressfilter.ExpressFilterTask;
7-
import express.http.request.Request;
8-
import express.http.response.Response;
96
import express.http.Cookie;
107
import express.http.SessionCookie;
8+
import express.http.request.Request;
9+
import express.http.response.Response;
10+
import express.utils.Utils;
1111

1212
import java.util.concurrent.ConcurrentHashMap;
1313

src/express/middleware/ExpressStatic.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import express.events.HttpRequest;
44
import express.http.request.Request;
55
import express.http.response.Response;
6+
import express.utils.Utils;
67

78
import java.io.File;
89

@@ -33,7 +34,7 @@ public void handle(Request req, Response res) {
3334
if (reqFile.exists()) {
3435

3536
if (EXTENSIONS != null) {
36-
String reqEx = reqFile.getAbsolutePath().replaceAll("^(.*\\.|.*\\|.+$)", "");
37+
String reqEx = Utils.getExtension(reqFile);
3738

3839
for (String ex : EXTENSIONS) {
3940
if (reqEx.equals(ex)) {
@@ -47,7 +48,7 @@ public void handle(Request req, Response res) {
4748
} else {
4849
if (ONHANDLE != null)
4950
ONHANDLE.handle(req, res);
50-
51+
5152
res.send(reqFile);
5253
}
5354
}

src/express/utils/MediaType.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,6 @@ public enum MediaType {
700700
this.extension = extension;
701701
}
702702

703-
public String getMIME() {
704-
return MIME;
705-
}
706-
707-
public String getExtension() {
708-
return extension;
709-
}
710-
711703
public static MediaType getForExtension(String extension) {
712704
switch (extension) {
713705
case "aw":
@@ -2083,4 +2075,12 @@ public static MediaType getForExtension(String extension) {
20832075
}
20842076
return null;
20852077
}
2078+
2079+
public String getMIME() {
2080+
return MIME;
2081+
}
2082+
2083+
public String getExtension() {
2084+
return extension;
2085+
}
20862086
}

src/express/utils/Utils.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.net.Inet4Address;
88
import java.net.UnknownHostException;
99
import java.security.SecureRandom;
10-
import java.util.Arrays;
1110

1211
public class Utils {
1312

@@ -45,7 +44,7 @@ public static MediaType getContentType(File file) {
4544
MediaType contentType = MediaType.getForExtension(ex);
4645

4746
if (contentType == null)
48-
return MediaType._bin;
47+
return MediaType._bin;
4948

5049
return contentType;
5150
}
@@ -78,16 +77,8 @@ public static String getYourIp() throws UnknownHostException {
7877
* @return The extension.
7978
*/
8079
public static String getExtension(@NotNull File file) {
81-
char[] buffer = new char[255];
82-
int bufferIndex = 0;
83-
84-
for (char c : file.getAbsolutePath().toCharArray()) {
85-
if (c == '\\' || c == '.' || c == '/')
86-
bufferIndex = 0;
87-
else
88-
buffer[bufferIndex++] = c;
89-
}
90-
return new String(Arrays.copyOf(buffer, bufferIndex));
80+
String path = file.getAbsolutePath();
81+
return path.substring(path.lastIndexOf('.'));
9182
}
9283

9384
}

0 commit comments

Comments
 (0)