OSDN Git Service

modifications for Java1.5
[bm-asn1/bm-asn1.git] / jp / bitmeister / asn1 / type / StringType.java
index 21bd5c6..3992440 100644 (file)
  */
 package jp.bitmeister.asn1.type;
 
+import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.util.regex.Pattern;
 
 import jp.bitmeister.asn1.exception.ASN1IllegalArgument;
+import jp.bitmeister.asn1.exception.ASN1RuntimeException;
 import jp.bitmeister.asn1.processor.ASN1Visitor;
 import jp.bitmeister.asn1.type.builtin.OCTET_STRING;
 
@@ -44,7 +46,13 @@ public abstract class StringType extends OCTET_STRING {
         */
        public void set(String value) {
                checkCharacters(value);
-               set(value.getBytes(charset()));
+               try {
+                       set(value.getBytes(charset().displayName()));
+               } catch (UnsupportedEncodingException e) {
+                       ASN1RuntimeException ex = new ASN1RuntimeException();
+                       ex.setMessage("Character set unsupported.", e, getClass(), null, this);
+                       throw ex;
+               }
        }
 
        /**
@@ -54,7 +62,13 @@ public abstract class StringType extends OCTET_STRING {
         * @return The string value assigned to this instance.
         */
        public String stringValue() {
-               return new String(value(), charset());
+               try {
+                       return new String(value(), charset().displayName());
+               } catch (UnsupportedEncodingException e) {
+                       ASN1RuntimeException ex = new ASN1RuntimeException();
+                       ex.setMessage("Character set unsupported.", e, getClass(), null, this);
+                       throw ex;
+               }
        }
 
        /**