1 21 22 package nu.xom.tests; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.ByteArrayOutputStream ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.UnsupportedEncodingException ; 29 30 import nu.xom.Builder; 31 import nu.xom.Document; 32 import nu.xom.Element; 33 import nu.xom.ParsingException; 34 import nu.xom.Serializer; 35 36 52 public class EBCDICTest extends XOMTestCase { 53 54 public final static char NEL = 0x85; 55 56 public EBCDICTest(String name) { 57 super(name); 58 } 59 60 private Document doc; 61 private String data; 62 63 protected void setUp() { 64 Element root = new Element("r"); 65 doc = new Document(root); 66 data = "\u0085"; 67 root.appendChild(data); 68 } 69 70 71 public void testEBCDIC037() 73 throws ParsingException, UnsupportedEncodingException { 74 75 Builder builder = new Builder(); 76 ByteArrayOutputStream out = new ByteArrayOutputStream (); 77 try { 78 Serializer serializer = new Serializer(out, "Cp037"); 80 serializer.write(doc); 81 serializer.flush(); 82 out.flush(); 83 out.close(); 84 byte[] result = out.toByteArray(); 85 86 for (int i = 0; i < result.length; i++) { 90 if (result[i] == 0x15) fail("Bad NEL output"); 91 } 92 93 InputStream in = new ByteArrayInputStream (result); 94 Document reparsed = builder.build(in); 95 assertEquals(doc, reparsed); 96 } 97 catch (UnsupportedEncodingException ex) { 98 throw ex; 99 } 100 catch (IOException ex) { 101 ex.printStackTrace(); 102 } 103 104 } 105 106 107 } 108 | Popular Tags |