Skip to content

Commit

Permalink
Cody tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy1612 committed Jul 8, 2021
1 parent 424edf9 commit 6dccb42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.idrsolutions</groupId>
<artifactId>idrsolutions-java-client</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>IDRsolutions Java Client</name>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/idrsolutions/IDRCloudClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -145,10 +145,10 @@ public static void downloadResults(final Map<String, String> results, String out
if (fileName != null) {
outputFilePath += '/' + fileName + ".zip";
} else {
outputFilePath += '/' + Path.of(results.get("downloadUrl").toString()).getFileName().toString() + ".zip";
outputFilePath += '/' + Paths.get(results.get("downloadUrl")).getFileName().toString() + ".zip";
}

download(results.get("downloadUrl").toString(), outputFilePath, encodedAuth);
download(results.get("downloadUrl"), outputFilePath, encodedAuth);
}

/**
Expand Down Expand Up @@ -219,7 +219,8 @@ private String upload(final Map<String, String> parameters) throws ClientExcepti
private static void file(final Map<String, String> parameters, final HttpURLConnection con) throws ClientException {

final File file = new File(parameters.get("file"));
final String fileName = Path.of(file.toURI()).getFileName().toString();
final String fileName = Paths.get(file.toURI()).getFileName().toString();
final String format = fileName.substring(fileName.lastIndexOf('.')+ 1);
final String boundary = String.valueOf(System.currentTimeMillis());
try {
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
Expand All @@ -232,7 +233,7 @@ private static void file(final Map<String, String> parameters, final HttpURLConn
if ("file".equals(key)) {
post.append("Content-Disposition: form-data; name=\"").append(key).append("\"; filename=\"").append(fileName).append("\";").append("\r\n");
final String fileString = new String(Files.readAllBytes(file.toPath()));
post.append("Content-Type: application/pdf\r\n\r\n").append(fileString).append("\r\n");
post.append("Content-Type: application/" + format + "\r\n\r\n").append(fileString).append("\r\n");

} else {
post.append("Content-Disposition: form-data; name=\"").append(key).append('\"').append("\r\n");
Expand Down Expand Up @@ -261,11 +262,11 @@ private static void url(final Map<String, String> parameters, final HttpURLConne
postData.append('&');
}
final String key = keys.next();
postData.append(URLEncoder.encode(key, StandardCharsets.UTF_8));
postData.append(URLEncoder.encode(key, StandardCharsets.UTF_8.toString()));
postData.append('=');
postData.append(URLEncoder.encode(parameters.get(key), StandardCharsets.UTF_8));
postData.append(URLEncoder.encode(parameters.get(key), StandardCharsets.UTF_8.toString()));
}
final byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8);
final byte[] postDataBytes = postData.toString().getBytes(StandardCharsets.UTF_8.toString());

con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
Expand Down

0 comments on commit 6dccb42

Please sign in to comment.