Skip to content

Commit

Permalink
use EntrySet instead of keySet in Map traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecreator committed Aug 8, 2017
1 parent 4932bd9 commit 5511337
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/fintx/http/HttpClientBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ public String post(URL url, Map<String, String> formParams) throws IOException,
}

FormBody.Builder builder = new FormBody.Builder();
for (String key : formParams.keySet()) {
builder.add(key, formParams.get(key));
for (Map.Entry<String, String> entry : formParams.entrySet()) {
builder.add(entry.getKey(), entry.getValue());
}
RequestBody formBody = builder.build();

Expand All @@ -389,15 +389,15 @@ public String post(URL url, Map<String, String> formParams, Map<String, File> fo
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.ALTERNATIVE);

if (null != formParams && 0 != formParams.size()) {
for (String key : formParams.keySet()) {
builder = builder.addFormDataPart(key, formParams.get(key));
for (Map.Entry<String, String> entry : formParams.entrySet()) {
builder = builder.addFormDataPart(entry.getKey(), entry.getValue());
}
}

if (null != formFiles && 0 != formFiles.size()) {
for (String key : formFiles.keySet()) {
RequestBody fileBody = RequestBody.create(okhttp3.MediaType.parse(MediaType.APP_OCTETSTREAM.getCode()), formFiles.get(key));
builder.addFormDataPart(key, formFiles.get(key).getName(), fileBody);
for (Map.Entry<String, File> entry : formFiles.entrySet()) {
RequestBody fileBody = RequestBody.create(okhttp3.MediaType.parse(MediaType.APP_OCTETSTREAM.getCode()), entry.getValue());
builder.addFormDataPart(entry.getKey(), entry.getValue().getName(), fileBody);
}

}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/fintx/util/Ips.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class Ips {
// }
// return getRemoteAddress(request);
// }
/**
* Get the remote IP from HttpServletRequest
*
* @param request the HttpServletRequest
* @return String the remote IP
*/
/**
* Get the remote IP from HttpServletRequest
*
* @param request the HttpServletRequest
* @return String the remote IP
*/
public static String getRemoteAddress(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (Strings.isNotBlank(ip) && !"unKnown".equalsIgnoreCase(ip)) {
Expand All @@ -70,6 +70,7 @@ public static String getRemoteAddress(HttpServletRequest request) {
}
return request.getRemoteAddr();
}

/**
* Get the local IP
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/fintx/util/Urls.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ private static byte convertHexDigit(byte b) {
public static String buildQueryData(Map<String, String> map) {
StringBuilder sb = new StringBuilder(512);
boolean first = true;
for (String key : map.keySet()) {
for (Map.Entry<String, String> entry : map.entrySet()) {
if (!first) {
sb.append("&");
} else {
first = false;
}
sb.append(key);
sb.append(entry.getKey());
sb.append("=");
sb.append(URLEncoder.encode(map.get(key)));
sb.append(URLEncoder.encode(entry.getValue()));
}
return sb.toString();

Expand Down

0 comments on commit 5511337

Please sign in to comment.