Replace Charset.forName("UTF-8") on StandartCharsets.UTF_8 (#30113)
This commit is contained in:
parent
c737f1a8e6
commit
fbc09c55f7
3 changed files with 16 additions and 22 deletions
|
|
@ -40,6 +40,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -255,11 +256,7 @@ public abstract class ByteString implements Iterable<Byte> {
|
|||
* @return new {@code ByteString}
|
||||
*/
|
||||
public static ByteString copyFromUtf8(String text) {
|
||||
try {
|
||||
return new LiteralByteString(text.getBytes("UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("UTF-8 not supported?", e);
|
||||
}
|
||||
return new LiteralByteString(text.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
|
|
@ -323,7 +320,7 @@ public abstract class ByteString implements Iterable<Byte> {
|
|||
// Helper method that takes the chunk size range as a parameter.
|
||||
public static ByteString readFrom(InputStream streamToDrain, int minChunkSize,
|
||||
int maxChunkSize) throws IOException {
|
||||
Collection<ByteString> results = new ArrayList<ByteString>();
|
||||
Collection<ByteString> results = new ArrayList<>();
|
||||
|
||||
// copy the inbound bytes into a list of chunks; the chunk size
|
||||
// grows exponentially to support both short and long streams.
|
||||
|
|
@ -408,7 +405,7 @@ public abstract class ByteString implements Iterable<Byte> {
|
|||
public static ByteString copyFrom(Iterable<ByteString> byteStrings) {
|
||||
Collection<ByteString> collection;
|
||||
if (!(byteStrings instanceof Collection)) {
|
||||
collection = new ArrayList<ByteString>();
|
||||
collection = new ArrayList<>();
|
||||
for (ByteString byteString : byteStrings) {
|
||||
collection.add(byteString);
|
||||
}
|
||||
|
|
@ -736,7 +733,7 @@ public abstract class ByteString implements Iterable<Byte> {
|
|||
throw new IllegalArgumentException("Buffer size < 0");
|
||||
}
|
||||
this.initialCapacity = initialCapacity;
|
||||
this.flushedBuffers = new ArrayList<ByteString>();
|
||||
this.flushedBuffers = new ArrayList<>();
|
||||
this.buffer = new byte[initialCapacity];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue