796
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
|
796
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
5506
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
796
|
22 |
*/
|
|
23 |
|
|
24 |
/* @test
|
|
25 |
@bug 4122961
|
|
26 |
@summary Verify that converters don't drop characters on buffer boundaries
|
|
27 |
|
|
28 |
This is a slightly modified version of the attachment supplied with the
|
|
29 |
bug report.
|
|
30 |
*/
|
|
31 |
import java.io.*;
|
|
32 |
|
|
33 |
public class TestConverterDroppedCharacters {
|
|
34 |
public static void main(String args[])
|
|
35 |
throws java.io.IOException, java.io.UnsupportedEncodingException,
|
|
36 |
java.io.FileNotFoundException
|
|
37 |
{
|
|
38 |
/* Try misc. encodings, many are broken. */
|
|
39 |
tryEncoding("Big5");
|
|
40 |
tryEncoding("CNS11643");
|
|
41 |
tryEncoding("Cp1006");
|
|
42 |
tryEncoding("Cp1381");
|
|
43 |
tryEncoding("Cp33722");
|
|
44 |
tryEncoding("GB2312");
|
|
45 |
tryEncoding("KSC5601");
|
|
46 |
tryEncoding("SJIS");
|
|
47 |
tryEncoding("UTF8");
|
|
48 |
}
|
|
49 |
|
|
50 |
static void tryEncoding(String encoding)
|
|
51 |
throws java.io.IOException, java.io.UnsupportedEncodingException,
|
|
52 |
java.io.FileNotFoundException
|
|
53 |
{
|
|
54 |
String filename = "OUTPUT";
|
|
55 |
int goesBadAfter = 8193;
|
|
56 |
int i;
|
|
57 |
char data[] = new char[goesBadAfter+1];
|
|
58 |
|
|
59 |
System.out.println("Testing " + encoding);
|
|
60 |
|
|
61 |
/* Create some data */
|
|
62 |
for(i = 0; i < goesBadAfter; i++) {
|
|
63 |
data[i] = (char)((i % 0x7f) + 1);
|
|
64 |
}
|
|
65 |
|
|
66 |
/* Write the data out to a file. */
|
|
67 |
FileOutputStream fout = new FileOutputStream(filename);
|
|
68 |
OutputStreamWriter ow = new OutputStreamWriter(fout, encoding);
|
|
69 |
BufferedWriter fd = new BufferedWriter(ow);
|
|
70 |
fd.write(data,0,goesBadAfter);
|
|
71 |
fd.close();
|
|
72 |
|
|
73 |
/* Now read it back with the same encoding. */
|
|
74 |
char buf[] = new char[goesBadAfter+1];
|
|
75 |
FileInputStream fin = new FileInputStream("OUTPUT");
|
|
76 |
InputStreamReader ir = new InputStreamReader(fin, encoding);
|
|
77 |
ir.read(buf,0,goesBadAfter);
|
|
78 |
ir.close();
|
|
79 |
|
|
80 |
/* And check to see if what we wrote is what we got back. */
|
|
81 |
for(i = 0; i < goesBadAfter; i++) {
|
|
82 |
if (data[i] != buf[i]) {
|
|
83 |
System.out.println("ERROR with encoding " + encoding
|
|
84 |
+ ": Data wrong at position " + i + " "
|
|
85 |
+ "in: " + (int)data[i] + " "
|
|
86 |
+ "out: " + (int)buf[i]);
|
|
87 |
throw new RuntimeException();
|
|
88 |
}
|
|
89 |
}
|
|
90 |
System.out.println("Successfully tested " + encoding);
|
|
91 |
}
|
|
92 |
}
|