Skip to content

Commit d687f3e

Browse files
committed
improve the code
1 parent f39968e commit d687f3e

20 files changed

+49
-43
lines changed

scribejava-core/src/main/java/com/github/scribejava/core/builder/AbstractServiceBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class AbstractServiceBuilder<T extends AbstractServiceBuilder> {
3232
* @param callback callback url. Must be a valid url or 'oob' for out of band OAuth
3333
* @return the {@link ServiceBuilder} instance for method chaining
3434
*/
35+
@SuppressWarnings("unchecked")
3536
public T callback(String callback) {
3637
Preconditions.checkNotNull(callback, "Callback can't be null");
3738
this.callback = callback;
@@ -44,6 +45,7 @@ public T callback(String callback) {
4445
* @param apiKey The api key for your application
4546
* @return the {@link ServiceBuilder} instance for method chaining
4647
*/
48+
@SuppressWarnings("unchecked")
4749
public T apiKey(String apiKey) {
4850
Preconditions.checkEmptyString(apiKey, "Invalid Api key");
4951
this.apiKey = apiKey;
@@ -56,6 +58,7 @@ public T apiKey(String apiKey) {
5658
* @param apiSecret The api secret for your application
5759
* @return the {@link ServiceBuilder} instance for method chaining
5860
*/
61+
@SuppressWarnings("unchecked")
5962
public T apiSecret(String apiSecret) {
6063
Preconditions.checkEmptyString(apiSecret, "Invalid Api secret");
6164
this.apiSecret = apiSecret;
@@ -68,6 +71,7 @@ public T apiSecret(String apiSecret) {
6871
* @param scope The OAuth scope
6972
* @return the {@link ServiceBuilder} instance for method chaining
7073
*/
74+
@SuppressWarnings("unchecked")
7175
public T scope(String scope) {
7276
Preconditions.checkEmptyString(scope, "Invalid OAuth scope");
7377
this.scope = scope;
@@ -80,6 +84,7 @@ public T scope(String scope) {
8084
* @param state The OAuth state
8185
* @return the {@link ServiceBuilder} instance for method chaining
8286
*/
87+
@SuppressWarnings("unchecked")
8388
public T state(String state) {
8489
Preconditions.checkEmptyString(state, "Invalid OAuth state");
8590
this.state = state;
@@ -92,24 +97,28 @@ public T state(String state) {
9297
* @param type SignatureType
9398
* @return the {@link ServiceBuilder} instance for method chaining
9499
*/
100+
@SuppressWarnings("unchecked")
95101
public T signatureType(SignatureType type) {
96102
Preconditions.checkNotNull(type, "Signature type can't be null");
97103
this.signatureType = type;
98104
return (T) this;
99105
}
100106

107+
@SuppressWarnings("unchecked")
101108
public T debugStream(OutputStream stream) {
102109
Preconditions.checkNotNull(stream, "debug stream can't be null");
103110
this.debugStream = stream;
104111
return (T) this;
105112
}
106113

114+
@SuppressWarnings("unchecked")
107115
public T grantType(String grantType) {
108116
Preconditions.checkEmptyString(grantType, "Invalid OAuth grantType");
109117
this.grantType = grantType;
110118
return (T) this;
111119
}
112120

121+
@SuppressWarnings("unchecked")
113122
public T debug() {
114123
debugStream(System.out);
115124
return (T) this;

scribejava-core/src/main/java/com/github/scribejava/core/model/AbstractRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class AbstractRequest {
2828
private final Map<String, String> headers = new HashMap<>();
2929
private boolean connectionKeepAlive;
3030
private boolean followRedirects = true;
31-
private OAuthService service;
31+
private final OAuthService service;
3232

3333
private String payload;
3434
private String charset;

scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ Response doSend() throws IOException {
4545
connection.setRequestMethod(verb.name());
4646
final OAuthConfig config = getService().getConfig();
4747
if (config.getConnectTimeout() != null) {
48-
connection.setConnectTimeout(config.getConnectTimeout().intValue());
48+
connection.setConnectTimeout(config.getConnectTimeout());
4949
}
5050
if (config.getReadTimeout() != null) {
51-
connection.setReadTimeout(config.getReadTimeout().intValue());
51+
connection.setReadTimeout(config.getReadTimeout());
5252
}
5353
addHeaders();
5454
if (hasBodyContent()) {

scribejava-core/src/main/java/com/github/scribejava/core/model/Parameter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
*/
88
public class Parameter implements Comparable<Parameter> {
99

10-
private static final String UTF = "UTF8";
11-
1210
private final String key;
1311
private final String value;
1412

scribejava-core/src/main/java/com/github/scribejava/core/services/Base64Encoder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ public abstract class Base64Encoder {
44

55
private static Base64Encoder instance;
66

7-
public static synchronized Base64Encoder getInstance() {
8-
if (instance == null) {
9-
instance = createEncoderInstance();
7+
public static Base64Encoder getInstance() {
8+
synchronized (Base64Encoder.class) {
9+
if (instance == null) {
10+
instance = createEncoderInstance();
11+
}
1012
}
1113
return instance;
1214
}

scribejava-core/src/main/java/com/github/scribejava/core/services/RSASha1SignatureService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class RSASha1SignatureService implements SignatureService {
1414
private static final String RSA_SHA1 = "SHA1withRSA";
1515
private static final String UTF8 = "UTF-8";
1616

17-
private PrivateKey privateKey;
17+
private final PrivateKey privateKey;
1818

1919
public RSASha1SignatureService(PrivateKey privateKey) {
2020
this.privateKey = privateKey;

scribejava-core/src/main/java/com/github/scribejava/core/utils/OAuthEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public abstract class OAuthEncoder {
2727

2828
public static String encode(String plain) {
2929
Preconditions.checkNotNull(plain, "Cannot encode null object");
30-
String encoded = "";
30+
String encoded;
3131
try {
3232
encoded = URLEncoder.encode(plain, CHARSET);
3333
} catch (UnsupportedEncodingException uee) {

scribejava-core/src/main/java/com/github/scribejava/core/utils/StreamUtils.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public static String getStreamContents(InputStream is) {
2323
try {
2424
final char[] buffer = new char[0x10000];
2525
final StringBuilder out = new StringBuilder();
26-
final Reader in = new InputStreamReader(is, "UTF-8");
27-
int read;
28-
do {
29-
read = in.read(buffer, 0, buffer.length);
30-
if (read > 0) {
31-
out.append(buffer, 0, read);
32-
}
33-
} while (read >= 0);
34-
in.close();
26+
try (Reader in = new InputStreamReader(is, "UTF-8")) {
27+
int read;
28+
do {
29+
read = in.read(buffer, 0, buffer.length);
30+
if (read > 0) {
31+
out.append(buffer, 0, read);
32+
}
33+
} while (read >= 0);
34+
}
3535
return out.toString();
3636
} catch (IOException ioe) {
3737
throw new IllegalStateException("Error while reading response body", ioe);

scribejava-core/src/test/java/com/github/scribejava/core/extractors/JsonTokenExtractorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
public class JsonTokenExtractorTest {
88

9-
private String response = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'";
10-
private JsonTokenExtractor extractor = new JsonTokenExtractor();
9+
private static final String RESPONSE = "'{ \"access_token\":\"I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X\"}'";
10+
private final JsonTokenExtractor extractor = new JsonTokenExtractor();
1111

1212
@Test
1313
public void shouldParseResponse() {
14-
final Token token = extractor.extract(response);
14+
final Token token = extractor.extract(RESPONSE);
1515
assertEquals(token.getToken(), "I0122HHJKLEM21F3WLPYHDKGKZULAUO4SGMV3ABKFTDT3T3X");
1616
}
1717

scribejava-core/src/test/java/com/github/scribejava/core/extractors/TokenExtractor20Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class TokenExtractor20Test {
1111
private TokenExtractor20Impl extractor;
1212

1313
@Before
14-
public void setup() {
14+
public void setUp() {
1515
extractor = new TokenExtractor20Impl();
1616
}
1717

0 commit comments

Comments
 (0)