Skip to content

Commit d314003

Browse files
committed
Clean up + removed deprecated JsonParser methods
1 parent 2bedd01 commit d314003

15 files changed

Lines changed: 16 additions & 30 deletions

File tree

api/src/main/java/xyz/gianlu/librespot/api/handlers/PlayerHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private enum Command {
147147
NEXT("next"), PREV("prev"), SET_VOLUME("set-volume"),
148148
VOLUME_UP("volume-up"), VOLUME_DOWN("volume-down"), CURRENT("current");
149149

150-
private String name;
150+
private final String name;
151151

152152
Command(String name) {
153153
this.name = name;

core/src/main/java/xyz/gianlu/librespot/BytesArrayList.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ public int read(@NotNull byte[] b, int off, int len) {
118118

119119
int i = 0;
120120
while (true) {
121-
if (sub >= elementData.length)
122-
return i;
123-
124121
int copy = Math.min(len - i, elementData[sub].length - offset);
125122
System.arraycopy(elementData[sub], offset, b, off + i, copy);
126123
i += copy;

core/src/main/java/xyz/gianlu/librespot/core/ApResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* @author Gianlu
2323
*/
2424
public class ApResolver {
25-
private static final JsonParser PARSER = new JsonParser();
2625
private static final String BASE_URL = "http://apresolve.spotify.com/";
2726
private static final Map<String, List<String>> pool = new HashMap<>(3);
2827
private static final Logger LOGGER = Logger.getLogger(ApResolver.class);
@@ -54,7 +53,7 @@ private static Map<String, List<String>> request(@NotNull String... types) throw
5453
conn.connect();
5554

5655
try {
57-
JsonObject obj = PARSER.parse(new InputStreamReader(conn.getInputStream())).getAsJsonObject();
56+
JsonObject obj = JsonParser.parseReader(new InputStreamReader(conn.getInputStream())).getAsJsonObject();
5857
HashMap<String, List<String>> map = new HashMap<>();
5958
for (String type : types)
6059
map.put(type, getUrls(obj, type));

core/src/main/java/xyz/gianlu/librespot/core/FacebookAuthenticator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
public class FacebookAuthenticator implements Closeable {
2525
private static final URL LOGIN_SPOTIFY;
26-
private static final JsonParser PARSER = new JsonParser();
2726
private static final Logger LOGGER = Logger.getLogger(FacebookAuthenticator.class);
2827
private static final byte[] EOL = new byte[]{'\r', '\n'};
2928

@@ -44,7 +43,7 @@ public class FacebookAuthenticator implements Closeable {
4443
HttpURLConnection conn = (HttpURLConnection) LOGIN_SPOTIFY.openConnection();
4544
try {
4645
conn.connect();
47-
JsonObject obj = PARSER.parse(new InputStreamReader(conn.getInputStream())).getAsJsonObject();
46+
JsonObject obj = JsonParser.parseReader(new InputStreamReader(conn.getInputStream())).getAsJsonObject();
4847
credentialsUrl = obj.get("credentials_url").getAsString();
4948
String loginUrl = obj.get("login_url").getAsString();
5049
LOGGER.info(String.format("Visit %s in your browser.", loginUrl));
@@ -73,7 +72,7 @@ public void close() throws IOException {
7372
}
7473

7574
private void authData(@NotNull String json) {
76-
JsonObject obj = PARSER.parse(json).getAsJsonObject();
75+
JsonObject obj = JsonParser.parseString(json).getAsJsonObject();
7776
if (!obj.get("error").isJsonNull()) {
7877
LOGGER.fatal("Error during authentication: " + obj.get("error"));
7978
return;

core/src/main/java/xyz/gianlu/librespot/core/SearchManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
public class SearchManager {
1818
private static final String BASE_URL = "hm://searchview/km/v4/search/";
19-
private static final JsonParser PARSER = new JsonParser();
2019
private final Session session;
2120

2221
public SearchManager(@NotNull Session session) {
@@ -34,7 +33,7 @@ public JsonObject request(@NotNull SearchRequest req) throws IOException {
3433

3534
if (resp.statusCode != 200) throw new SearchException(resp.statusCode);
3635

37-
return (JsonObject) PARSER.parse(new InputStreamReader(resp.payload.stream()));
36+
return JsonParser.parseReader(new InputStreamReader(resp.payload.stream())).getAsJsonObject();
3837
}
3938

4039
public static class SearchException extends IOException {

core/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ static Inner from(@NotNull AbsConfiguration configuration) {
643643
*/
644644
public static class Builder {
645645
private final Inner inner;
646+
private final AuthConfiguration authConf;
646647
private Authentication.LoginCredentials loginCredentials = null;
647-
private AuthConfiguration authConf;
648648

649649
public Builder(@NotNull Connect.DeviceType deviceType, @NotNull String deviceName, @NotNull AbsConfiguration configuration) {
650650
this.inner = new Inner(deviceType, deviceName, configuration);

core/src/main/java/xyz/gianlu/librespot/core/TimeProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
public final class TimeProvider {
2424
private static final AtomicLong offset = new AtomicLong(0);
2525
private static final Logger LOGGER = Logger.getLogger(TimeProvider.class);
26-
private static final JsonParser PARSER = new JsonParser();
2726
private static Method method = Method.NTP;
2827

2928
private TimeProvider() {
@@ -99,7 +98,7 @@ private static void updateMelody(@NotNull Session session) {
9998
ResponseBody body = resp.body();
10099
if (body == null) throw new IllegalStateException();
101100

102-
JsonObject obj = PARSER.parse(body.string()).getAsJsonObject();
101+
JsonObject obj = JsonParser.parseString(body.string()).getAsJsonObject();
103102
long diff = obj.get("timestamp").getAsLong() - System.currentTimeMillis();
104103
synchronized (offset) {
105104
offset.set(diff);

core/src/main/java/xyz/gianlu/librespot/crypto/DiffieHellman.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public class DiffieHellman {
1313
private static final BigInteger GENERATOR = BigInteger.valueOf(2);
14-
private static final byte PRIME_BYTES[] = {
14+
private static final byte[] PRIME_BYTES = {
1515
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xc9, (byte)
1616
(byte) 0x0f, (byte) 0xda, (byte) 0xa2, (byte) 0x21, (byte) 0x68, (byte) 0xc2, (byte) 0x34, (byte) 0xc4, (byte) 0xc6, (byte)
1717
(byte) 0x62, (byte) 0x8b, (byte) 0x80, (byte) 0xdc, (byte) 0x1c, (byte) 0xd1, (byte) 0x29, (byte) 0x02, (byte) 0x4e, (byte)

core/src/main/java/xyz/gianlu/librespot/dealer/DealerClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
* @author Gianlu
2929
*/
3030
public class DealerClient implements Closeable {
31-
private static final JsonParser PARSER = new JsonParser();
3231
private static final Logger LOGGER = Logger.getLogger(DealerClient.class);
3332
private final Looper looper = new Looper();
3433
private final Session session;
@@ -314,7 +313,7 @@ public void onOpen(@NotNull WebSocket ws, @NotNull Response response) {
314313

315314
@Override
316315
public void onMessage(@NotNull WebSocket ws, @NotNull String text) {
317-
JsonObject obj = PARSER.parse(text).getAsJsonObject();
316+
JsonObject obj = JsonParser.parseString(text).getAsJsonObject();
318317

319318
waitForListeners();
320319

core/src/main/java/xyz/gianlu/librespot/mercury/JsonMercuryRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @author Gianlu
1313
*/
1414
public class JsonMercuryRequest<W extends JsonWrapper> {
15-
private static final JsonParser PARSER = new JsonParser();
1615
final RawMercuryRequest request;
1716
private final Class<W> wrapperClass;
1817

@@ -24,7 +23,7 @@ public class JsonMercuryRequest<W extends JsonWrapper> {
2423
@NotNull
2524
public W instantiate(@NotNull MercuryClient.Response resp) {
2625
try {
27-
JsonElement elm = PARSER.parse(new InputStreamReader(resp.payload.stream()));
26+
JsonElement elm = JsonParser.parseReader(new InputStreamReader(resp.payload.stream()));
2827
return wrapperClass.getConstructor(JsonObject.class).newInstance(elm.getAsJsonObject());
2928
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
3029
throw new IllegalArgumentException(ex);

0 commit comments

Comments
 (0)