8000 fix: refactor to use StandardCharsets (#1243) · rohitvvv/google-http-java-client@03ec798 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03ec798

Browse files
authored
fix: refactor to use StandardCharsets (googleapis#1243)
1 parent fa3966a commit 03ec798

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

google-http-client/src/main/java/com/google/api/client/http/AbstractHttpContent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
package com.google.api.client.http;
1616

17-
import com.google.api.client.util.Charsets;
1817
import com.google.api.client.util.IOUtils;
1918
import com.google.api.client.util.StreamingContent;
2019
import java.io.IOException;
2120
import java.nio.charset.Charset;
21+
import java.nio.charset.StandardCharsets;
2222

2323
/**
2424
* Abstract implementation of an HTTP content with typical options.
@@ -87,13 +87,13 @@ public AbstractHttpContent setMediaType(HttpMediaType mediaType) {
8787
}
8888

89< 8000 code>89
/**
90-
* Returns the charset specified in the media type or {@code Charsets#UTF_8} if not specified.
90+
* Returns the charset specified in the media type or ISO_8859_1 if not specified.
9191
*
9292
* @since 1.10
9393
*/
9494
protected final Charset getCharset() {
9595
return mediaType == null || mediaType.getCharsetParameter() == null
96-
? Charsets.ISO_8859_1
96+
? StandardCharsets.ISO_8859_1
9797
: mediaType.getCharsetParameter();
9898
}
9999

google-http-client/src/main/java/com/google/api/client/http/HttpResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.api.client.http;
1616

17-
import com.google.api.client.util.Charsets;
1817
import com.google.api.client.util.IOUtils;
1918
import com.google.api.client.util.LoggingInputStream;
2019
import com.google.api.client.util.Preconditions;
@@ -26,6 +25,7 @@
2625
import java.io.OutputStream;
2726
import java.lang.reflect.Type;
2827
import java.nio.charset.Charset;
28+
import java.nio.charset.StandardCharsets;
2929
import java.util.Locale;
3030
import java.util.logging.Level;
3131
import java.util.logging.Logger;
@@ -506,14 +506,14 @@ public String parseAsString() throws IOException {
506506
}
507507

508508
/**
509-
* Returns the {@link Charset} specified in the Content-Type of this response or the {@code
510-
* "ISO-8859-1"} charset as a default.
509+
* Returns the {@link Charset} specified in the Content-Type of this response or the ISO-8859-1
510+
* charset as a default.
511511
*
512512
* @since 1.10
513513
*/
514514
public Charset getContentCharset() {
515515
return mediaType == null || mediaType.getCharsetParameter() == null
516-
? Charsets.ISO_8859_1
516+
? StandardCharsets.ISO_8859_1
517517
: mediaType.getCharsetParameter();
518518
}
519519
}

google-http-client/src/main/java/com/google/api/client/http/UrlEncodedParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.api.client.http;
1616

1717
import com.google.api.client.util.ArrayValueMap;
18-
import com.google.api.client.util.Charsets;
1918
import com.google.api.client.util.ClassInfo;
2019
import com.google.api.client.util.Data;
2120
import com.google.api.client.util.FieldInfo;
@@ -34,6 +33,7 @@
3433
import java.io.StringWriter;
3534
import java.lang.reflect.Type;
3635
import java.nio.charset.Charset;
36+
impo 6D40 rt java.nio.charset.StandardCharsets;
3737
import java.util.ArrayList;
3838
import java.util.Arrays;
3939
import java.util.Collection;
@@ -72,7 +72,10 @@ public class UrlEncodedParser implements ObjectParser {
7272
* @since 1.13
7373
*/
7474
public static final String MEDIA_TYPE =
75-
new HttpMediaType(UrlEncodedParser.CONTENT_TYPE).setCharsetParameter(Charsets.UTF_8).build();
75+
new HttpMediaType(UrlEncodedParser.CONTENT_TYPE)
76+
.setCharsetParameter(StandardCharsets.UTF_8)
77+
.build();
78+
7679
/**
7780
* Parses the given URL-encoded content into the given data object of data key name/value pairs
7881
* using {@link #parse(Reader, Object)}.

google-http-client/src/main/java/com/google/api/client/json/JsonFactory.java

-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414

1515
package com.google.api.client.json;
1616

17-
import com.google.api.client.util.Charsets;
1817
import java.io.ByteArrayOutputStream;
1918
import java.io.IOException;
2019
import java.io.InputStream;
2120
import java.io.OutputStream;
2221
import java.io.Reader;
2322
import java.io.Writer;
2423
import java.nio.charset.Charset;
24+
import java.nio.charset.StandardCharsets;
2525

2626
/**
2727
* Abstract low-level JSON factory.
@@ -159,7 +159,7 @@ private String toString(Object item, boolean pretty) throws IOException {
159159
*/
160160
private ByteArrayOutputStream toByteStream(Object item, boolean pretty) throws IOException {
161161
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
162-
JsonGenerator generator = createJsonGenerator(byteStream, Charsets.UTF_8);
162+
JsonGenerator generator = createJsonGenerator(byteStream, StandardCharsets.UTF_8);
163163
if (pretty) {
164164
generator.enablePrettyPrint();
165165
}

google-http-client/src/main/java/com/google/api/client/testing/http/MockLowLevelHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import com.google.api.client.http.LowLevelHttpRequest;
1919
import com.google.api.client.http.LowLevelHttpResponse;
2020
import com.google.api.client.util.Beta;
21-
import com.google.api.client.util.Charsets;
2221
import com.google.api.client.util.IOUtils;
2322
import java.io.ByteArrayInputStream;
2423
import java.io.ByteArrayOutputStream;
2524
import java.io.IOException;
2625
import java.io.InputStream;
2726
import java.nio.charset.Charset;
27+
import java.nio.charset.StandardCharsets;
2828
import java.util.ArrayList;
2929
import java.util.Collections;
3030
import java.util.HashMap;
@@ -164,7 +164,7 @@ public String getContentAsString() throws IOException {
164164
HttpMediaType mediaType = contentType != null ? new HttpMediaType(contentType) : null;
165165
Charset charset =
166166
mediaType == null || mediaType.getCharsetParameter() == null
167-
? Charsets.ISO_8859_1
167+
? StandardCharsets.ISO_8859_1
168168
: mediaType.getCharsetParameter();
169169
return out.toString(charset.name());
170170
}

google-http-client/src/test/java/com/google/api/client/http/MultipartContentTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
package com.google.api.client.http;
1616

1717
import com.google.api.client.json.Json;
18-
import com.google.api.client.util.Charsets;
1918
import com.google.api.client.util.StringUtils;
2019
import java.io.ByteArrayOutputStream;
20+
import java.nio.charset.StandardCharsets;
2121
import junit.framework.TestCase;
2222

2323
/**
@@ -77,7 +77,7 @@ public void testRandomContent() throws Exception {
7777
ByteArrayOutputStream out = new ByteArrayOutputStream();
7878
content.writeTo(out);
7979
String expectedContent = expectedStringBuilder.toString();
80-
assertEquals(expectedContent, out.toString(Charsets.UTF_8.name()));
80+
assertEquals(expectedContent, out.toString(StandardCharsets.UTF_8.name()));
8181
assertEquals(StringUtils.getBytesUtf8(expectedContent).length, content.getLength());
8282
}
8383

@@ -128,7 +128,7 @@ private void subtestContent(String expectedContent, String boundaryString, Strin
128128
// write to string
129129
ByteArrayOutputStream out = new ByteArrayOutputStream();
130130
content.writeTo(out);
131-
assertEquals(expectedContent, out.toString(Charsets.UTF_8.name()));
131+
assertEquals(expectedContent, out.toString(StandardCharsets.UTF_8.name()));
132132
assertEquals(StringUtils.getBytesUtf8(expectedContent).length, content.getLength());
133133
assertEquals(
134134
boundaryString == null

0 commit comments

Comments
 (0)
0