|
1 | 1 | /*
|
2 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 | 3 | *
|
4 |
| - * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved. |
| 4 | + * Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved. |
5 | 5 | *
|
6 | 6 | * The contents of this file are subject to the terms of either the GNU
|
7 | 7 | * General Public License Version 2 only ("GPL") or the Common Development
|
|
43 | 43 | */
|
44 | 44 | package com.sun.codemodel.util;
|
45 | 45 |
|
46 |
| -import java.lang.reflect.Constructor; |
47 | 46 | import java.nio.charset.Charset;
|
48 | 47 | import java.nio.charset.CharsetEncoder;
|
49 | 48 |
|
50 | 49 | /**
|
51 | 50 | * Creates {@link CharsetEncoder} from a charset name.
|
52 | 51 | *
|
53 |
| - * Fixes a MS1252 handling bug in JDK1.4.2. |
54 |
| - * |
55 | 52 | * @author
|
56 | 53 | * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
|
57 | 54 | */
|
58 | 55 | public class EncoderFactory {
|
59 |
| - |
60 |
| - public static CharsetEncoder createEncoder( String encodin ) { |
| 56 | + |
| 57 | + public static CharsetEncoder createEncoder( String encodin ) { |
61 | 58 | Charset cs = Charset.forName(System.getProperty("file.encoding"));
|
62 | 59 | CharsetEncoder encoder = cs.newEncoder();
|
63 |
| - |
64 |
| - if( cs.getClass().getName().equals("sun.nio.cs.MS1252") ) { |
65 |
| - try { |
66 |
| - // at least JDK1.4.2_01 has a bug in MS1252 encoder. |
67 |
| - // specifically, it returns true for any character. |
68 |
| - // return a correct encoder to workaround this problem |
69 |
| - |
70 |
| - // statically binding to MS1252Encoder will cause a Link error |
71 |
| - // (at least in IBM JDK1.4.1) |
72 |
| - @SuppressWarnings("unchecked") |
73 |
| - Class<? extends CharsetEncoder> ms1252encoder = (Class<? extends CharsetEncoder>) Class.forName("com.sun.codemodel.util.MS1252Encoder"); |
74 |
| - Constructor<? extends CharsetEncoder> c = ms1252encoder.getConstructor(new Class[]{ |
75 |
| - Charset.class |
76 |
| - }); |
77 |
| - return c.newInstance(new Object[]{cs}); |
78 |
| - } catch( Throwable t ) { |
79 |
| - // if something funny happens, ignore it and fall back to |
80 |
| - // a broken MS1252 encoder. It's probably still better |
81 |
| - // than choking here. |
82 |
| - return encoder; |
83 |
| - } |
84 |
| - } |
85 |
| - |
86 | 60 | return encoder;
|
87 | 61 | }
|
88 | 62 | }
|
0 commit comments