1 16 package org.apache.axis.components.encoding; 17 18 import org.apache.axis.i18n.Messages; 19 20 import java.io.IOException ; 21 import java.io.Writer ; 22 23 30 class UTF16Encoder extends AbstractXMLEncoder { 31 35 public String getEncoding() { 36 return XMLEncoderFactory.ENCODING_UTF_16; 37 } 38 39 45 public void writeEncoded(Writer writer, String xmlString) 46 throws IOException { 47 if (xmlString == null) { 48 return; 49 } 50 int length = xmlString.length(); 51 char character; 52 for (int i = 0; i < length; i++) { 53 character = xmlString.charAt( i ); 54 switch (character) { 55 case '&': 58 writer.write(AMP); 59 break; 60 case '"': 61 writer.write(QUOTE); 62 break; 63 case '<': 64 writer.write(LESS); 65 break; 66 case '>': 67 writer.write(GREATER); 68 break; 69 case '\n': 70 writer.write(LF); 71 break; 72 case '\r': 73 writer.write(CR); 74 break; 75 case '\t': 76 writer.write(TAB); 77 break; 78 default: 79 if (character < 0x20) { 80 throw new IllegalArgumentException (Messages.getMessage( 81 "invalidXmlCharacter00", 82 Integer.toHexString(character), 83 xmlString)); 84 } else if (character > 0xFFFF) { 85 writer.write((0xD7C0 + (character >> 10))); 86 writer.write((0xDC00 | character & 0x3FF)); 87 } else { 88 writer.write(character); 89 } 90 break; 91 } 92 } 93 } 94 } 95 | Popular Tags |