mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8183743: Umbrella: add overloads that take a Charset parameter
Reviewed-by: alanb, rriggs
This commit is contained in:
parent
f065141ddc
commit
4f080a83af
28 changed files with 1959 additions and 131 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,6 +25,7 @@
|
|||
|
||||
package java.io;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
@ -223,14 +224,27 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
|
||||
/**
|
||||
* Converts the buffer's contents into a string by decoding the bytes using
|
||||
* the named {@link java.nio.charset.Charset charset}. The length of the new
|
||||
* {@code String} is a function of the charset, and hence may not be equal
|
||||
* to the length of the byte array.
|
||||
* the named {@link java.nio.charset.Charset charset}.
|
||||
*
|
||||
* <p> This method is equivalent to {@code #toString(charset)} that takes a
|
||||
* {@link java.nio.charset.Charset charset}.
|
||||
*
|
||||
* <p> An invocation of this method of the form
|
||||
*
|
||||
* <pre> {@code
|
||||
* ByteArrayOutputStream b = ...
|
||||
* b.toString("UTF-8")
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* behaves in exactly the same way as the expression
|
||||
*
|
||||
* <pre> {@code
|
||||
* ByteArrayOutputStream b = ...
|
||||
* b.toString(StandardCharsets.UTF_8)
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p> This method always replaces malformed-input and unmappable-character
|
||||
* sequences with this charset's default replacement string. The {@link
|
||||
* java.nio.charset.CharsetDecoder} class should be used when more control
|
||||
* over the decoding process is required.
|
||||
*
|
||||
* @param charsetName the name of a supported
|
||||
* {@link java.nio.charset.Charset charset}
|
||||
|
@ -245,6 +259,26 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
return new String(buf, 0, count, charsetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the buffer's contents into a string by decoding the bytes using
|
||||
* the specified {@link java.nio.charset.Charset charset}. The length of the new
|
||||
* {@code String} is a function of the charset, and hence may not be equal
|
||||
* to the length of the byte array.
|
||||
*
|
||||
* <p> This method always replaces malformed-input and unmappable-character
|
||||
* sequences with the charset's default replacement string. The {@link
|
||||
* java.nio.charset.CharsetDecoder} class should be used when more control
|
||||
* over the decoding process is required.
|
||||
*
|
||||
* @param charset the {@linkplain java.nio.charset.Charset charset}
|
||||
* to be used to decode the {@code bytes}
|
||||
* @return String decoded from the buffer's contents.
|
||||
* @since 10
|
||||
*/
|
||||
public synchronized String toString(Charset charset) {
|
||||
return new String(buf, 0, count, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a newly allocated string. Its size is the current size of
|
||||
* the output stream and the valid contents of the buffer have been
|
||||
|
@ -257,9 +291,10 @@ public class ByteArrayOutputStream extends OutputStream {
|
|||
*
|
||||
* @deprecated This method does not properly convert bytes into characters.
|
||||
* As of JDK 1.1, the preferred way to do this is via the
|
||||
* {@code toString(String enc)} method, which takes an encoding-name
|
||||
* argument, or the {@code toString()} method, which uses the
|
||||
* platform's default character encoding.
|
||||
* {@link #toString(String charsetName)} or {@link #toString(Charset charset)}
|
||||
* method, which takes an encoding-name or charset argument,
|
||||
* or the {@code toString()} method, which uses the platform's default
|
||||
* character encoding.
|
||||
*
|
||||
* @param hibyte the high byte of each resulting Unicode character.
|
||||
* @return the current contents of the output stream, as a string.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue