[nanohttpd]code format

This commit is contained in:
yushijinhun 2018-12-30 16:59:09 +08:00
parent 6dccd97269
commit ffc96d0a05
No known key found for this signature in database
GPG key ID: 5BC167F73EA558E4

View file

@ -254,9 +254,9 @@ public abstract class NanoHTTPD {
*/
public class CookieHandler implements Iterable<String> {
private final HashMap<String, String> cookies = new HashMap<String, String>();
private final HashMap<String, String> cookies = new HashMap<>();
private final ArrayList<Cookie> queue = new ArrayList<Cookie>();
private final ArrayList<Cookie> queue = new ArrayList<>();
public CookieHandler(Map<String, String> httpHeaders) {
String raw = httpHeaders.get("cookie");
@ -356,7 +356,7 @@ public abstract class NanoHTTPD {
@Override
public void closeAll() {
// copy of the list for concurrency
for (ClientHandler clientHandler : new ArrayList<ClientHandler>(this.running)) {
for (ClientHandler clientHandler : new ArrayList<>(this.running)) {
clientHandler.close();
}
}
@ -436,7 +436,7 @@ public abstract class NanoHTTPD {
if (!tmpdir.exists()) {
tmpdir.mkdirs();
}
this.tempFiles = new ArrayList<TempFile>();
this.tempFiles = new ArrayList<>();
}
@Override
@ -650,7 +650,7 @@ public abstract class NanoHTTPD {
this.outputStream = outputStream;
this.remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString();
this.remoteHostname = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "localhost" : inetAddress.getHostName().toString();
this.headers = new HashMap<String, String>();
this.headers = new HashMap<>();
}
/**
@ -727,8 +727,7 @@ public abstract class NanoHTTPD {
fbuf.position(boundaryIdxs[boundaryIdx]);
int len = (fbuf.remaining() < MAX_HEADER_SIZE) ? fbuf.remaining() : MAX_HEADER_SIZE;
fbuf.get(partHeaderBuff, 0, len);
BufferedReader in =
new BufferedReader(new InputStreamReader(new ByteArrayInputStream(partHeaderBuff, 0, len), Charset.forName(contentType.getEncoding())), len);
BufferedReader in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(partHeaderBuff, 0, len), Charset.forName(contentType.getEncoding())), len);
int headerLines = 0;
// First line is boundary string
@ -786,7 +785,7 @@ public abstract class NanoHTTPD {
List<String> values = parms.get(partName);
if (values == null) {
values = new ArrayList<String>();
values = new ArrayList<>();
parms.put(partName, values);
}
@ -854,7 +853,7 @@ public abstract class NanoHTTPD {
List<String> values = p.get(key);
if (values == null) {
values = new ArrayList<String>();
values = new ArrayList<>();
p.put(key, values);
}
@ -906,9 +905,9 @@ public abstract class NanoHTTPD {
this.inputStream.skip(this.splitbyte);
}
this.parms = new HashMap<String, List<String>>();
this.parms = new HashMap<>();
if (null == this.headers) {
this.headers = new HashMap<String, String>();
this.headers = new HashMap<>();
} else {
this.headers.clear();
}
@ -917,7 +916,7 @@ public abstract class NanoHTTPD {
BufferedReader hin = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buf, 0, this.rlen)));
// Decode the header into parms and header java properties
Map<String, String> pre = new HashMap<String, String>();
Map<String, String> pre = new HashMap<>();
decodeHeader(hin, pre, this.parms, this.headers);
if (null != this.remoteIp) {
@ -1079,7 +1078,7 @@ public abstract class NanoHTTPD {
@Override
@Deprecated
public final Map<String, String> getParms() {
Map<String, String> result = new HashMap<String, String>();
Map<String, String> result = new HashMap<>();
for (String key : this.parms.keySet()) {
result.put(key, this.parms.get(key).get(0));
}
@ -1471,9 +1470,9 @@ public abstract class NanoHTTPD {
* Headers for the HTTP response. Use addHeader() to add lines. the
* lowercase map is automatically kept up to date.
*/
@SuppressWarnings("serial")
private final Map<String, String> header = new HashMap<String, String>() {
@Override
public String put(String key, String value) {
lowerCaseHeader.put(key == null ? key : key.toLowerCase(), value);
return super.put(key, value);
@ -1484,7 +1483,7 @@ public abstract class NanoHTTPD {
* copy of the header map with all the keys lowercase for faster
* searching.
*/
private final Map<String, String> lowerCaseHeader = new HashMap<String, String>();
private final Map<String, String> lowerCaseHeader = new HashMap<>();
/**
* The request method that spawned this response.
@ -1863,7 +1862,7 @@ public abstract class NanoHTTPD {
public static Map<String, String> mimeTypes() {
if (MIME_TYPES == null) {
MIME_TYPES = new HashMap<String, String>();
MIME_TYPES = new HashMap<>();
loadMimeTypes(MIME_TYPES, "META-INF/nanohttpd/default-mimetypes.properties");
loadMimeTypes(MIME_TYPES, "META-INF/nanohttpd/mimetypes.properties");
if (MIME_TYPES.isEmpty()) {
@ -1881,7 +1880,7 @@ public abstract class NanoHTTPD {
try {
Enumeration<URL> resources = NanoHTTPD.class.getClassLoader().getResources(resourceName);
while (resources.hasMoreElements()) {
URL url = (URL) resources.nextElement();
URL url = resources.nextElement();
Properties properties = new Properties();
InputStream stream = null;
try {
@ -2094,7 +2093,7 @@ public abstract class NanoHTTPD {
* <code>List&lt;String&gt;</code> (a list of the values supplied).
*/
protected static Map<String, List<String>> decodeParameters(String queryString) {
Map<String, List<String>> parms = new HashMap<String, List<String>>();
Map<String, List<String>> parms = new HashMap<>();
if (queryString != null) {
StringTokenizer st = new StringTokenizer(queryString, "&");
while (st.hasMoreTokens()) {
@ -2227,7 +2226,7 @@ public abstract class NanoHTTPD {
* @return HTTP response, see class Response for details
*/
public Response serve(IHTTPSession session) {
Map<String, String> files = new HashMap<String, String>();
Map<String, String> files = new HashMap<>();
Method method = session.getMethod();
if (Method.PUT.equals(method) || Method.POST.equals(method)) {
try {