1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| package xx;
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.math.BigDecimal; import java.math.BigInteger;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.impl.piccolo.xml.XMLStreamReader; import org.openuri.easypo.LineItem; import org.openuri.easypo.PurchaseOrderDocument;
public class Test { public static void main(String[] args) throws IOException, XmlException {
String u = "\uD840\uDC08asasa";
System.out.println(u + "+ " + u.length()); System.out.println(Character.isHighSurrogate(u.charAt(0))); System.out.println("isSupplementaryCodePoint " + Character.isSupplementaryCodePoint(u.charAt(0))); System.out.println((int) u.charAt(1)); System.out.println("codePoint = > " + (int) u.codePointAt(0) + ", 0x" + Integer.toHexString(u.codePointAt(0)));
System.out.println("@@@ " + u.codePointCount(0, u.length()));
String s = String.valueOf(Character.toChars(0x200D9)); System.out.println("<<< " + Character.isSupplementaryCodePoint(0x200D9)); char[] chars = s.toCharArray(); for (char c : chars) { System.out.format("BB => %x\n", (short) c); }
System.out.format("hex -> decimal %s\n", 0x2F81A);
InputStream in = new FileInputStream("C:/easypo.xml"); byte[] bufferd = new byte[4096]; int length = 0; StringBuilder sb = new StringBuilder(); while ((length = in.read(bufferd)) != -1) { sb.append(new String(bufferd, 0, length, "UTF-16BE")); }
OutputStream os = new FileOutputStream("C:/out2.txt"); os.write(0xfe); os.write(0xff);
StringBuilder sb2 = new StringBuilder(); for (int i = 1; i < sb.length() - 1; i++) {
if (Character.isHighSurrogate(sb.charAt(i)) || Character.isLowSurrogate(sb.charAt(i))) {
String code = Integer.toHexString(sb.charAt(i)); os.write(Integer.decode("0x" + code.substring(0, 2))); os.write(Integer.decode("0x" + code.substring(2, 4)));
code = Integer.toHexString(sb.charAt(i + 1)); os.write(Integer.decode("0x" + code.substring(0, 2))); os.write(Integer.decode("0x" + code.substring(2, 4)));
i++; } else { if (Character.isDefined(sb.charAt(i))) sb2.append(sb.charAt(i)); } }
File poXmlFile = new File("C:/easypo.xml");
String updatedPoXml = addLineItem(sb2.toString(), s, "5", "20.00", "6");
os.close();
}
private static String addLineItem(String purchaseOrder, String itemDescription, String perUnitOuncesString, String itemPriceString, String itemQuantityString) throws XmlException, IOException { PurchaseOrderDocument poDoc = null;
XMLStreamReader reader = new XMLStreamReader(); poDoc = PurchaseOrderDocument.Factory.parse(purchaseOrder);
BigDecimal perUnitOunces = new BigDecimal(perUnitOuncesString); BigDecimal itemPrice = new BigDecimal(itemPriceString); BigInteger itemQUAntity = new BigInteger(itemQuantityString);
LineItem newItem = poDoc.getPurchaseOrder().addNewLineItem(); newItem.setDescription(itemDescription); newItem.setPerUnitOunces(perUnitOunces); newItem.setPrice(itemPrice); newItem.setQuantity(itemQuantity);
return poDoc.toString(); } }
|