Examples of cnMessageFactory


Examples of org.zyp.cn8583.cnMessageFactory

  /** Creates a message factory from an XML config file( full path and filename). */
  public static cnMessageFactory createFromXMLConfigFile(String filepath) throws IOException {
    // InputStream ins = cnMessageFactory.class.getClassLoader().getResourceAsStream(path);
    InputStream ins = new FileInputStream(filepath);
    cnMessageFactory mfact = new cnMessageFactory();
    if (ins != null) {
        log.debug("parsing config from xml file: [" + filepath + "]");
      try {
        parse(mfact, ins);
      } finally {
View Full Code Here

Examples of org.zyp.cn8583.cnMessageFactory

    return mfact;
  }

  /** Creates a message factory from the file located at the specified URL. */
  public static cnMessageFactory createFromUrl(URL url) throws IOException {
    cnMessageFactory mfact = new cnMessageFactory();
    InputStream stream = url.openStream();
    try {
      parse(mfact, stream);
    } finally {
      stream.close();
View Full Code Here

Examples of org.zyp.cn8583.cnMessageFactory

  public static void main(String[] args) throws Exception {
    // ������־
    org.apache.log4j.PropertyConfigurator.configure("j8583cn_log.properties");
    // ����j8583cn���ĸ�ʽ�����ļ�������һ�����Ĺ�������
    cnMessageFactory mfact = cnConfigParser.createFromXMLConfigFile("config.xml");
    mfact.setUseCurrentDate(false)// ������ field 7
    // ����ϵͳ���ٺŵ�������������field 11��
    mfact.setSystemTraceNumberGenerator(new cnSimpleSystemTraceNumGen((int)(System.currentTimeMillis() % 100000)));
   
    //Create a new message
    cnMessage m = mfact.newMessagefromTemplate("0200")// ����ģ�崴������ʼ��һ�����Ķ���
    m.setBinary(false);    // ������ʹ�ö�����

    if(m.setMessageHeaderData(0, new String("0123456789").getBytes()) == false) {
      System.out.println("���ñ���ͷ����");
      System.exit(-1);
    }
    m.setValue(4, new BigDecimal("501.25"), cnType.AMOUNT, 0);
    m.setValue(12, new Date(), cnType.TIME, 0);
    m.setValue(15, new Date(), cnType.DATE4, 0);
    m.setValue(17, new Date(), cnType.DATE_EXP, 0);
    m.setValue(37, 12345678, cnType.NUMERIC, 12);
    m.setValue(41, "TEST-TERMINAL", cnType.ALPHA, 16);
   
    FileOutputStream fout = new FileOutputStream("messagedata.out");
    m.write(fout, 4, 10)// �ѱ���д���ļ������ڱ���ǰ�����ϱ�ʾ�������ij��ȵ��ĸ������ַ�(10���Ʊ�ʾ)��
    fout.close();
   
    System.out.println("\n NEW MESSAGE:");
    print(m);
   
    // �������һ�����Ĵ����ô������ļ��У� 
    System.out.println("\n PARSE MESSAGE FROM FILE");
    byte[] buf = new byte[4];
    FileInputStream fin = new FileInputStream("messagedata.out");
    fin.read(buf)// ���ĸ��ֽڵ����ݣ������ij�����Ϣ������
    int len = (buf[0] - 0x30) * 1000   // ǧλ
        + (buf[1] - 0x30) * 100   // ��λ
        + (buf[2] - 0x30) * 10     // ʮλ
        + buf[3] - 0x30;      // ��λ
    buf = new byte[len];
    fin.read(buf)// �ӵ�����ֽڶ�ȡlen���ֽڵ����ݵ�buf��
    fin.close();
   
    mfact.setUseBinary(false);
    m = mfact.parseMessage(buf, mfact.getHeaderLengthAttr("0200"))// ����
    print(m);
   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.