Skip to content

Commit e1c1ba5

Browse files
committed
Fixed warnings
1 parent 0f65966 commit e1c1ba5

File tree

11 files changed

+94
-40
lines changed

11 files changed

+94
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ Please leave all comments, bugs, requests, and issues on the Issues page. We'll
108108

109109
### License
110110
The ConvertAPI Java Library is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form") license.
111-
Refere to the [LICENSE](https://github.com/ConvertAPI/convertapi-java/blob/master/LICENSE) file for more information.
111+
Refer to the [LICENSE](https://github.com/ConvertAPI/convertapi-java/blob/master/LICENSE) file for more information.

src/com/convertapi/Config.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,50 @@
33
public class Config {
44
private static String defaultSecret;
55
private static final String SCHEME = "https";
6+
@SuppressWarnings("SpellCheckingInspection")
67
private static final String HOST = "v2.convertapi.com";
78
private static final int TIMEOUT = 180;
8-
private String scheme;
9-
private String host;
10-
private String secret;
11-
private int timeout;
9+
private final String scheme;
10+
private final String host;
11+
private final String secret;
12+
private final int timeout;
1213

13-
public static void setDefaultSecret(String defaultSecret) {
14-
Config.defaultSecret = defaultSecret;
14+
@SuppressWarnings("unused")
15+
public Config(String secret, String scheme, String host, int timeout) {
16+
this.scheme = scheme;
17+
this.host = host;
18+
this.secret = secret;
19+
this.timeout = timeout;
1520
}
1621

22+
@SuppressWarnings("WeakerAccess")
1723
public static Config defaults() {
1824
return new Config(Config.defaultSecret, SCHEME, HOST, TIMEOUT);
1925
}
2026

27+
@SuppressWarnings("WeakerAccess")
2128
public static Config defaults(String secret) {
2229
return new Config(secret, SCHEME, HOST, TIMEOUT);
2330
}
2431

25-
public Config(String secret, String scheme, String host, int timeout) {
26-
this.scheme = scheme;
27-
this.host = host;
28-
this.secret = secret;
29-
this.timeout = timeout;
32+
@SuppressWarnings("unused")
33+
public static void setDefaultSecret(String defaultSecret) {
34+
Config.defaultSecret = defaultSecret;
3035
}
3136

32-
public int getTimeout() {
37+
int getTimeout() {
3338
return timeout;
3439
}
3540

36-
public String getScheme() {
41+
String getScheme() {
3742
return scheme;
3843
}
3944

40-
public String getHost() {
45+
String getHost() {
4146
return host;
4247
}
4348

44-
public String getSecret() {
49+
String getSecret() {
4550
return secret;
4651
}
4752
}

src/com/convertapi/ConversionException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.convertapi;
22

3-
public class ConversionException extends RuntimeException{
4-
private int httpStatusCode;
3+
class ConversionException extends RuntimeException {
4+
private final int httpStatusCode;
55

66
public ConversionException(String message, int httpStatusCode){
77
super(message);

src/com/convertapi/ConversionResult.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@
44
import com.convertapi.model.ConversionResponseFile;
55

66
import java.nio.file.Files;
7-
import java.nio.file.NotDirectoryException;
87
import java.nio.file.Path;
98
import java.util.ArrayList;
109
import java.util.List;
1110
import java.util.concurrent.CompletableFuture;
1211
import java.util.concurrent.ExecutionException;
12+
import java.util.stream.Collectors;
1313

14+
@SuppressWarnings("WeakerAccess")
1415
public class ConversionResult {
1516
private final ConversionResponse response;
1617

18+
@SuppressWarnings("unused")
1719
public ConversionResult(ConversionResponse responseFuture) {
1820
this.response = responseFuture;
1921
}
2022

23+
@SuppressWarnings("unused")
2124
public Integer fileCount() {
2225
return response.Files.length;
2326
}
2427

2528
public List<String> urls() {
26-
List<String> valueList = new ArrayList();
29+
@SuppressWarnings("unchecked") List<String> valueList = new ArrayList();
2730
for (ConversionResponseFile file: response.Files) valueList.add(file.Url);
2831
return valueList;
2932
}
3033

34+
@SuppressWarnings("unused")
3135
public Integer conversionCost() {
3236
return response.ConversionCost;
3337
}
@@ -40,12 +44,25 @@ public CompletableFuture<Path> saveFile(Path file) {
4044
return getFile(0).saveFile(file);
4145
}
4246

47+
@SuppressWarnings("WeakerAccess")
4348
public List<CompletableFuture<Path>> saveFiles(Path directory) {
4449
if (!Files.isDirectory(directory)) throw new RuntimeException("Directory expected, but received: " + directory.toString());
45-
List<CompletableFuture<Path>> paths = new ArrayList();
50+
List<CompletableFuture<Path>> paths = new ArrayList<>();
4651
for (int i = 0; i < response.Files.length; i++) {
4752
paths.add(getFile(i).saveFile(directory));
4853
}
4954
return paths;
5055
}
56+
57+
@SuppressWarnings("unused")
58+
public List<Path> saveFilesSync(Path directory) {
59+
List<CompletableFuture<Path>> futures = saveFiles(directory);
60+
return futures.stream().map(p -> {
61+
try {
62+
return p.get();
63+
} catch (InterruptedException | ExecutionException e) {
64+
throw new RuntimeException(e);
65+
}
66+
}).collect(Collectors.toList());
67+
}
5168
}

src/com/convertapi/ConversionResultFile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public ConversionResultFile(ConversionResponseFile conversionResponseFile) {
1717
this.conversionResponseFile = conversionResponseFile;
1818
}
1919

20+
@SuppressWarnings("WeakerAccess")
2021
public String getName() {
2122
return conversionResponseFile.FileName;
2223
}
@@ -25,14 +26,17 @@ public int getSize() {
2526
return conversionResponseFile.FileSize;
2627
}
2728

29+
@SuppressWarnings("WeakerAccess")
2830
public String getUrl() {
2931
return conversionResponseFile.Url;
3032
}
3133

34+
@SuppressWarnings("WeakerAccess")
3235
public CompletableFuture<InputStream> asStream() {
3336
return Http.requestGet(getUrl());
3437
}
3538

39+
@SuppressWarnings("WeakerAccess")
3640
public CompletableFuture<Path> saveFile(Path path) {
3741
return asStream().thenApplyAsync(s -> {
3842
try {

src/com/convertapi/ConvertApi.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616
import java.util.concurrent.CompletableFuture;
1717
import java.util.concurrent.ExecutionException;
1818

19+
@SuppressWarnings("WeakerAccess")
1920
public class ConvertApi {
21+
@SuppressWarnings("SpellCheckingInspection")
2022
private static final List<String> IGNORE_PARAMS = Arrays.asList( "storefile", "async", "jobid", "timeout");
2123

24+
@SuppressWarnings("unused")
2225
public static CompletableFuture<ConversionResult> convert(String fromFormat, String toFormat, Param[] params) {
2326
return convert(fromFormat, toFormat, params, Config.defaults());
2427
}
2528

2629
public static CompletableFuture<ConversionResult> convert(String fromFormat, String toFormat, Param[] params, Config config) {
2730
CompletableFuture<ConversionResponse> completableResponse = CompletableFuture.supplyAsync(() -> {
31+
@SuppressWarnings("SpellCheckingInspection")
2832
HttpUrl url = Http.getUrlBuilder(config)
2933
.addPathSegment(fromFormat)
3034
.addPathSegment("to")
@@ -58,6 +62,7 @@ public static CompletableFuture<ConversionResult> convert(String fromFormat, Str
5862
String bodyString;
5963
try {
6064
Response response = Http.getClient().newCall(request).execute();
65+
//noinspection ConstantConditions
6166
bodyString = response.body().string();
6267
if (response.code() != 200) {
6368
throw new ConversionException(bodyString, response.code());
@@ -69,9 +74,10 @@ public static CompletableFuture<ConversionResult> convert(String fromFormat, Str
6974
return new Gson().fromJson(bodyString, ConversionResponse.class);
7075
});
7176

72-
return completableResponse.thenApply(r -> new ConversionResult(r));
77+
return completableResponse.thenApply(ConversionResult::new);
7378
}
7479

80+
@SuppressWarnings("unused")
7581
public static User getUser() {
7682
return getUser(Config.defaults());
7783
}
@@ -86,6 +92,7 @@ public static User getUser(Config config) {
8692
String bodyString;
8793
try {
8894
Response response = Http.getClient().newCall(request).execute();
95+
//noinspection ConstantConditions
8996
bodyString = response.body().string();
9097
if (response.code() != 200) {
9198
throw new ConversionException(bodyString, response.code());
@@ -97,6 +104,7 @@ public static User getUser(Config config) {
97104
return new Gson().fromJson(bodyString, User.class);
98105
}
99106

107+
@SuppressWarnings("unused")
100108
public static CompletableFuture<ConversionResult> convert(Path fromFile, String toFormat) throws IOException {
101109
return convert(fromFile, toFormat, Config.defaults().getSecret());
102110
}
@@ -105,6 +113,7 @@ public static CompletableFuture<ConversionResult> convert(Path fromFile, String
105113
return convert(getFileExtension(fromFile), toFormat, new Param[]{new Param("file", fromFile)}, Config.defaults(secret));
106114
}
107115

116+
@SuppressWarnings("unused")
108117
public static void convert(String fromPathToFile, String toPathToFile) {
109118
convert(fromPathToFile, toPathToFile, Config.defaults().getSecret());
110119
}

src/com/convertapi/Http.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,31 @@
99
import java.io.InputStream;
1010
import java.util.concurrent.CompletableFuture;
1111

12-
public class Http {
13-
private static OkHttpClient client = new OkHttpClient();
12+
class Http {
13+
private static final OkHttpClient client = new OkHttpClient();
1414

15-
public static OkHttpClient getClient() {
15+
static OkHttpClient getClient() {
1616
return client;
1717
}
1818

19-
public static HttpUrl.Builder getUrlBuilder(Config config) {
19+
static HttpUrl.Builder getUrlBuilder(Config config) {
2020
return new HttpUrl.Builder()
2121
.scheme(config.getScheme())
2222
.host(config.getHost())
2323
.addQueryParameter("timeout", String.valueOf(config.getTimeout()))
2424
.addQueryParameter("secret", config.getSecret());
2525
}
2626

27-
public static CompletableFuture<InputStream> requestGet(String url) {
27+
static CompletableFuture<InputStream> requestGet(String url) {
2828
return CompletableFuture.supplyAsync(() -> {
2929
Request request = new Request.Builder().url(url).build();
30-
Response response = null;
30+
Response response;
3131
try {
3232
response = getClient().newCall(request).execute();
3333
} catch (IOException e) {
3434
throw new RuntimeException(e);
3535
}
36+
//noinspection ConstantConditions
3637
return response.body().byteStream();
3738
});
3839
}

src/com/convertapi/Param.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.convertapi;
22

3-
import okhttp3.*;
3+
import okhttp3.MediaType;
4+
import okhttp3.Request;
5+
import okhttp3.RequestBody;
6+
47
import javax.activation.MimetypesFileTypeMap;
5-
import java.io.*;
8+
import java.io.IOException;
69
import java.math.BigDecimal;
710
import java.nio.file.Files;
811
import java.nio.file.Path;
@@ -11,33 +14,40 @@
1114
import java.util.concurrent.CompletableFuture;
1215
import java.util.concurrent.ExecutionException;
1316

17+
@SuppressWarnings("WeakerAccess")
1418
public class Param {
15-
private String name;
19+
private final String name;
1620
private CompletableFuture<List<String>> value;
1721

22+
@SuppressWarnings("unused")
1823
private Param(String name) {
1924
this.name = name.toLowerCase();
2025
}
2126

27+
@SuppressWarnings("unused")
2228
public Param(String name, String value) {
2329
this(name.toLowerCase());
24-
List<String> valueList = new ArrayList();
30+
List<String> valueList = new ArrayList<>();
2531
valueList.add(value);
2632
this.value = CompletableFuture.completedFuture(valueList);
2733
}
2834

35+
@SuppressWarnings("unused")
2936
public Param(String name, int value) {
3037
this(name, String.valueOf(value));
3138
}
3239

40+
@SuppressWarnings("unused")
3341
public Param(String name, BigDecimal value) {
3442
this(name, String.valueOf(value));
3543
}
3644

45+
@SuppressWarnings("unused")
3746
public Param(String name, byte[] value, String fileFormat) {
3847
this(name, value, fileFormat, Config.defaults());
3948
}
4049

50+
@SuppressWarnings("WeakerAccess")
4151
public Param(String name, byte[] value, String fileFormat, Config config) {
4252
this(name);
4353
String fileName = "getFile." + fileFormat;
@@ -49,27 +59,31 @@ public Param(String name, Path value) throws IOException {
4959
this(name, value, Config.defaults());
5060
}
5161

62+
@SuppressWarnings("WeakerAccess")
5263
public Param(String name, Path value, Config config) throws IOException {
5364
this(name);
5465
String contentTypeString = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(value.toFile());
5566
this.value = upload(Files.readAllBytes(value), value.getFileName().toString(), MediaType.parse(contentTypeString), config);
5667
}
5768

58-
public Param(String name, ConversionResult value) throws ExecutionException, InterruptedException {
69+
@SuppressWarnings("unused")
70+
public Param(String name, ConversionResult value) {
5971
this(name, value, 0);
6072
this.value = CompletableFuture.completedFuture(value.urls());
6173
}
6274

63-
public Param(String name, ConversionResult value, int fileIndex) throws ExecutionException, InterruptedException {
75+
@SuppressWarnings("WeakerAccess")
76+
public Param(String name, ConversionResult value, int fileIndex) {
6477
this(name);
65-
List<String> valueList = new ArrayList();
78+
List<String> valueList = new ArrayList<>();
6679
valueList.add(value.getFile(fileIndex).getUrl());
6780
this.value = CompletableFuture.completedFuture(valueList);
6881
}
6982

70-
public Param(String name, CompletableFuture<ConversionResult> value) throws ExecutionException, InterruptedException {
83+
@SuppressWarnings("unused")
84+
public Param(String name, CompletableFuture<ConversionResult> value) {
7185
this(name);
72-
this.value = value.thenApply(r -> r.urls());
86+
this.value = value.thenApply(ConversionResult::urls);
7387
}
7488

7589
public String getName() {
@@ -84,12 +98,13 @@ private static CompletableFuture<List<String>> upload(byte[] data, String fileNa
8498
return CompletableFuture.supplyAsync(() -> {
8599
Request request = new Request.Builder()
86100
.url(Http.getUrlBuilder(config).addPathSegment("upload")
87-
.addQueryParameter("filename", fileName.toString())
101+
.addQueryParameter("filename", fileName)
88102
.build())
89103
.post(RequestBody.create(fileContentType, data))
90104
.build();
91105
try {
92-
List<String> valueList = new ArrayList<String>();
106+
List<String> valueList = new ArrayList<>();
107+
//noinspection ConstantConditions
93108
valueList.add(Http.getClient().newCall(request).execute().body().string());
94109
return valueList;
95110
} catch (IOException e) {

src/com/convertapi/model/ConversionResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.convertapi.model;
22

3+
@SuppressWarnings("CanBeFinal")
34
public class ConversionResponse {
45
public int ConversionCost = 0;
56
public ConversionResponseFile[] Files = null;

0 commit comments

Comments
 (0)