Encodings.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 4085160 4139951 5005831
* @summary Test that required character encodings are supported
*/
public class Encodings {
static boolean equals(byte[] a, byte[] b) {
for (int i = 0; i < a.length; i++)
if (a[i] != b[i]) return false;
return true;
}
throws Exception
{
/* String(byte[] bs, String enc) */
/* String(byte[] bs, Charset charset) */
/* String(byte[] bs, int off, int len, Charset charset) */
} else {
}
/* InputStreamReader */
char[] cs = new char[n];
for (int i = 0; i < n;) {
int m;
i += m;
}
if (!bidir) {
return;
}
/* String.getBytes(String enc) */
/* String.getBytes(Charset charset) */
// Calls to String.getBytes(Charset) shouldn't automatically
// use the cached thread-local encoder.
// Replace the thread-local encoder with this one.
// Incidental test.
throw new RuntimeException("unequal length: "
} else {
boolean diff = false;
// Expect different byte[] between UTF-16LE and UTF-16BE
// even though encoder was previously cached by last call
// to getBytes().
diff = true;
}
if (!diff)
throw new RuntimeException("byte arrays equal");
}
}
/* OutputStreamWriter */
w.close();
}
}
new byte[] { 'a', 'b',
(byte)(0xe0 | (0x0f & (0x1e09 >> 12))),
(byte)(0x80 | (0x3f & (0x1e09 >> 6))),
(byte)(0x80 | (0x3f & 0x1e09)) });
new byte[] { 0, 'a', 0, 'b', 0x1e, 0x09 });
new byte[] { 'a', 0, 'b', 0, 0x09, 0x1e });
/* UTF-16 accepts both byte orders on input but always uses big-endian
* on output, so test all three cases
*/
new byte[] { (byte)0xfe, (byte)0xff, 0, 'a', 0, 'b', 0x1e, 0x09 });
new byte[] { (byte)0xff, (byte)0xfe, 'a', 0, 'b', 0, 0x09, 0x1e },
false);
}
}