Skip to content

Commit 873286c

Browse files
committed
Fixed deprecation warnings
1 parent b652ed3 commit 873286c

File tree

6 files changed

+24
-43
lines changed

6 files changed

+24
-43
lines changed

build.gradle

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ task sourcesJar(type: Jar) {
3333
from sourceSets.main.allSource
3434
}
3535

36+
tasks.withType(JavaCompile) {
37+
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
38+
}
39+
3640
task javadocJar(type: Jar) {
3741
archiveClassifier.set("javadoc")
3842
from javadoc
@@ -148,19 +152,3 @@ signing {
148152
useInMemoryPgpKeys(signingKey, signingPassword)
149153
sign publishing.publications.mavenJava
150154
}
151-
152-
test {
153-
maxHeapSize = "1024m"
154-
}
155-
156-
// credit: http://stackoverflow.com/a/22681854/305340
157-
tasks.withType(JavaCompile) {
158-
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked"
159-
doFirst {
160-
if (System.env.JDK8_HOME != null) {
161-
options.bootClasspath = "$System.env.JDK8_HOME/jre/lib/rt.jar"
162-
options.bootClasspath += "$File.pathSeparator$System.env.JDK8_HOME/jre/lib/jce.jar"
163-
// and other specific JDK jars
164-
}
165-
}
166-
}

src/main/java/com/opentok/Broadcast.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.fasterxml.jackson.databind.ObjectMapper;
1515

1616
import java.util.ArrayList;
17+
import java.util.Collection;
1718
import java.util.List;
1819
import java.util.Map;
1920

@@ -125,12 +126,13 @@ public String getStatus() {
125126
* stream's status.
126127
*/
127128
@JsonProperty("broadcastUrls")
129+
@SuppressWarnings("unchecked")
128130
private void unpack(Map<String,Object> broadcastUrls) {
129131
if (broadcastUrls == null) return;
130-
hls = (String)broadcastUrls.get("hls");
131-
ArrayList<Map<String,String>> rtmpResponse = (ArrayList<Map<String,String>>)broadcastUrls.get("rtmp");
132-
if (rtmpResponse == null || rtmpResponse.size() == 0) return;
133-
for ( Map<String,String> element : rtmpResponse) {
132+
hls = (String) broadcastUrls.get("hls");
133+
Iterable<Map<String,String>> rtmpResponse = (Iterable<Map<String,String>>)broadcastUrls.get("rtmp");
134+
if (rtmpResponse == null) return;
135+
for (Map<String,String> element : rtmpResponse) {
134136
Rtmp rtmp = new Rtmp();
135137
rtmp.setId(element.get("id"));
136138
rtmp.setServerUrl(element.get("serverUrl"));

src/main/java/com/opentok/OpenTok.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ public ArchiveList listArchives(String sessionId, int offset, int count) throws
424424
return archiveListReader.readValue(archives);
425425
} catch (JsonProcessingException e) {
426426
throw new RequestException("Exception mapping json: " + e.getMessage());
427-
} catch (IOException e) {
428-
throw new RequestException("Exception mapping json: " + e.getMessage());
429427
}
430428
}
431429

@@ -842,8 +840,6 @@ public StreamList listStreams(String sessionId) throws OpenTokException {
842840
return streamListReader.readValue(streams);
843841
} catch (JsonProcessingException e) {
844842
throw new RequestException("Exception mapping json: " + e.getMessage());
845-
} catch (IOException e) {
846-
throw new RequestException("Exception mapping json: " + e.getMessage());
847843
}
848844
}
849845

@@ -871,8 +867,6 @@ public Sip dial(String sessionId, String token, SipProperties properties) throws
871867
return sipReader.readValue(sip);
872868
} catch (JsonProcessingException e) {
873869
throw new RequestException("Exception mapping json: " + e.getMessage());
874-
} catch (IOException e) {
875-
throw new RequestException("Exception mapping json: " + e.getMessage());
876870
}
877871
}
878872

src/main/java/com/opentok/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public String generateToken(TokenOptions tokenOptions) throws OpenTokException {
117117
Role role = tokenOptions.getRole();
118118
double expireTime = tokenOptions.getExpireTime(); // will be 0 if nothing was explicitly set
119119
String data = tokenOptions.getData(); // will be null if nothing was explicitly set
120-
Long create_time = new Long(System.currentTimeMillis() / 1000).longValue();
120+
long create_time = System.currentTimeMillis() / 1000;
121121

122122
StringBuilder dataStringBuilder = new StringBuilder();
123123
Random random = new Random();

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,8 +1215,7 @@ public HttpClient build() {
12151215

12161216
config = configBuilder.build();
12171217
// NOTE: not thread-safe, config could be modified by another thread here?
1218-
HttpClient client = new HttpClient(this);
1219-
return client;
1218+
return new HttpClient(this);
12201219
}
12211220

12221221
// credit: https://github.com/AsyncHttpClient/async-http-client/blob/b52a8de5d6a862b5d1652d62f87ce774cbcff156/src/main/java/com/ning/http/client/ProxyServer.java#L99-L127
@@ -1284,9 +1283,10 @@ public TokenAuthRequestFilter(int apiKey, String apiSecret) {
12841283
public <T> FilterContext<T> filter(FilterContext<T> ctx) throws FilterException {
12851284
try {
12861285
return new FilterContext.FilterContextBuilder<T>(ctx)
1287-
.request(new RequestBuilder(ctx.getRequest())
1288-
.addHeader(authHeader, TokenGenerator.generateToken(apiKey, apiSecret))
1289-
.build())
1286+
.request(ctx.getRequest().toBuilder()
1287+
.addHeader(authHeader, TokenGenerator.generateToken(apiKey, apiSecret))
1288+
.build()
1289+
)
12901290
.build();
12911291
} catch (OpenTokException e) {
12921292
e.printStackTrace();

src/test/java/com/opentok/test/Helpers.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import javax.crypto.spec.SecretKeySpec;
2121
import java.io.UnsupportedEncodingException;
2222
import java.net.URLDecoder;
23+
import java.nio.charset.StandardCharsets;
2324
import java.security.InvalidKeyException;
2425
import java.security.NoSuchAlgorithmException;
2526
import java.security.SignatureException;
@@ -31,21 +32,17 @@
3132
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
3233
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
3334
import static com.opentok.util.Crypto.signData;
34-
import static com.opentok.util.TokenGenerator.ISSUED_AT;
35-
import static com.opentok.util.TokenGenerator.ISSUER;
36-
import static com.opentok.util.TokenGenerator.ISSUER_TYPE;
37-
import static com.opentok.util.TokenGenerator.PROJECT_ISSUER_TYPE;
38-
import static org.junit.Assert.assertTrue;
35+
import static com.opentok.util.TokenGenerator.*;
3936

4037
public class Helpers {
4138

4239
public static final String JTI = "jti";
4340

4441
public static Map<String, String> decodeToken(String token) throws UnsupportedEncodingException {
45-
Map<String, String> tokenData = new HashMap<String, String>();
42+
Map<String, String> tokenData = new HashMap<>();
4643
token = token.substring(4);
4744
byte[] buffer = Base64.decodeBase64(token);
48-
String decoded = new String(buffer, "UTF-8");
45+
String decoded = new String(buffer, StandardCharsets.UTF_8);
4946
String[] decodedParts = decoded.split(":");
5047
for (String part : decodedParts) {
5148
tokenData.putAll(decodeFormData(part));
@@ -57,7 +54,7 @@ public static boolean verifyTokenSignature(String token, String apiSecret) throw
5754
UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
5855
token = token.substring(4);
5956
byte[] buffer = Base64.decodeBase64(token);
60-
String decoded = new String(buffer, "UTF-8");
57+
String decoded = new String(buffer, StandardCharsets.UTF_8);
6158
String[] decodedParts = decoded.split(":");
6259
String signature = decodeToken(token).get("sig");
6360
return (signature.equals(signData(decodedParts[1], apiSecret)));
@@ -79,10 +76,10 @@ public static void verifyUserAgent() {
7976
}
8077

8178
private static Map<String, String> decodeFormData(String formData) throws UnsupportedEncodingException {
82-
Map<String, String> decodedFormData = new HashMap<String, String>();
79+
Map<String, String> decodedFormData = new HashMap<>();
8380
String[] pairs = formData.split("\\&");
84-
for (int i = 0; i < pairs.length; i++) {
85-
String[] fields = pairs[i].split("=");
81+
for (String pair : pairs) {
82+
String[] fields = pair.split("=");
8683
String name = URLDecoder.decode(fields[0], "UTF-8");
8784
String value = URLDecoder.decode(fields[1], "UTF-8");
8885
decodedFormData.put(name, value);

0 commit comments

Comments
 (0)