diff options
author | aclement <aclement> | 2011-04-04 18:17:39 +0000 |
---|---|---|
committer | aclement <aclement> | 2011-04-04 18:17:39 +0000 |
commit | c7c8841b2efaa4ba6f35f1b005542d5242561693 (patch) | |
tree | cdf786f491539371f748b4f0f669cb2fb9979198 /tests/multiIncremental/pr290741/base/src/demo | |
parent | 766083c477c47ae7de6d8799c3e44b2b1ed0f1b3 (diff) | |
download | aspectj-c7c8841b2efaa4ba6f35f1b005542d5242561693.tar.gz aspectj-c7c8841b2efaa4ba6f35f1b005542d5242561693.zip |
290741: encoding option on ICompilerConfiguration
Diffstat (limited to 'tests/multiIncremental/pr290741/base/src/demo')
-rwxr-xr-x | tests/multiIncremental/pr290741/base/src/demo/Converter.java | 34 | ||||
-rwxr-xr-x | tests/multiIncremental/pr290741/base/src/demo/ConverterTest.java | 44 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/multiIncremental/pr290741/base/src/demo/Converter.java b/tests/multiIncremental/pr290741/base/src/demo/Converter.java new file mode 100755 index 000000000..3eb98695d --- /dev/null +++ b/tests/multiIncremental/pr290741/base/src/demo/Converter.java @@ -0,0 +1,34 @@ +package demo; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; + +/** + * @author oliver + * @since 18.11.2005 + */ +public class Converter { + + /** + * You may get problems using String.getBytes("UTF-8") on a non UTF-8 + * environment. Here is an alternative for it from + * http://mindprod.com/jgloss/encoding.html. + * + * @param text + * @return + * @throws UnsupportedEncodingException + */ + public static byte[] utf8encode(String text) throws UnsupportedEncodingException { + //return text.getBytes("UTF-8"); + Charset cs = Charset.forName("UTF8"); + CharBuffer ss = CharBuffer.wrap(text); + ByteBuffer bb = cs.encode(ss); + int limit = bb.limit(); // how many chars in buffer + byte[] b = new byte[ limit ]; + bb.get( b, 0 /* offset */, limit ); + return b; + } + +} diff --git a/tests/multiIncremental/pr290741/base/src/demo/ConverterTest.java b/tests/multiIncremental/pr290741/base/src/demo/ConverterTest.java new file mode 100755 index 000000000..b7a4c0093 --- /dev/null +++ b/tests/multiIncremental/pr290741/base/src/demo/ConverterTest.java @@ -0,0 +1,44 @@ +package demo; + +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; + +public class ConverterTest { + + /** + * For signature we need an UTF-8 environment - don't ask my why. + * + * @since 29-Jun-06 + * @see http://mindprod.com/jgloss/encoding.html + */ +/* + String encoding = System.getProperty("file.encoding"); + String outEncoding = new OutputStreamWriter(System.out).getEncoding(); + System.out.println("file.encoding=" + encoding + " # system property"); + System.out.println("System.out encoding = " + outEncoding); + } +*/ + + public static void run() throws Exception { + /** + * Do we really get the right bytes here if the encoding is wrong? + * @throws UnsupportedEncodingException + */ + //String name = "B\u00f6hm"; // this works + String name = "Böhm"; + System.out.println("Hello, my name is Mr. " + name); + byte[] bytes = Converter.utf8encode(name); + assertEquals(66, bytes[0]); + assertEquals(-61, bytes[1]); + assertEquals(-74, bytes[2]); + assertEquals(104, bytes[3]); + assertEquals(109, bytes[4]); + } + + public static void assertEquals(int i, int b) throws Exception { + if (i!=b) { +throw new RuntimeException("different"); + } + } + +} |