Ejemplo n.º 1
0
 public static void test12() {
   int score = 0;
   int total = 4;
   ps.println("\n** Testing rol() and ror()... ");
   Byte b = new Byte(109);
   ps.println(b);
   b.ror();
   ps.println(b);
   if (b.toString().equals("10110110")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.rol();
   if (b.toString().equals("01101101")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.rol();
   if (b.toString().equals("11011010")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   for (int i = 0; i < 8; i++) b.ror();
   if (b.toString().equals("11011010")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 2
0
 public static void test1() {
   int score = 0;
   int total = 4;
   ps.println("** Testing constructor: new Byte(int n)... ");
   ps.println("** Testing version 1 of set(n)...");
   ps.println("** Testing toString()...");
   Byte b = new Byte(10);
   if (b.toString().equals("00001010")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b = new Byte(0);
   if (b.toString().equals("00000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.set(127);
   if (b.toString().equals("01111111")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.set(0);
   if (b.toString().equals("00000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 3
0
 public static void test10() {
   int score = 0;
   int total = 4;
   ps.println("\n** Testing subtract(Byte other)... ");
   Byte b1 = new Byte(5);
   Byte b2 = new Byte(2);
   b1.subtract(b2);
   if (b1.toString().equals("00000011") && b2.toString().equals("00000010")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b2.subtract(b1);
   if (b1.toString().equals("00000011") && b2.toString().equals("11111111")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b1.set(-127);
   b2.set(1);
   b1.subtract(b2);
   if (b1.toString().equals("10000000") && b2.toString().equals("00000001")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b1.set(1);
   b2.set(-126);
   b1.subtract(b2);
   if (b1.toString().equals("01111111") && b2.toString().equals("10000010")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 4
0
 public static void test6() {
   int score = 0;
   int total = 2;
   ps.println("\n** Testing version 2 of set(n)...");
   Byte b = new Byte();
   b.set(-10);
   if (b.toString().equals("11110110")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.set(-128);
   if (b.toString().equals("10000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 5
0
  public static void test11() {
    int score = 0;
    int total = 4;
    ps.println("\n** Testing xor(Byte other)... ");
    Byte b1 = new Byte(5);
    Byte b2 = new Byte(-10);
    b1.xor(b2);
    if (b1.toString().equals("11110011") && b2.toString().equals("11110110")) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");
    b2.xor(b2);
    if (b2.toString().equals("00000000")) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");
    b2.set(0);
    b1.xor(b2);
    if (b1.toString().equals("11110011") && b2.toString().equals("00000000")) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");
    b1.set(5);
    b2.set(-1);
    b1.xor(b2);
    if (b1.toString().equals("11111010") && b2.toString().equals("11111111")) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");

    report(score, total);
  }
Ejemplo n.º 6
0
 public static void test2() {
   int score = 0;
   int total = 1;
   ps.println("\n** Testing constructor: new Byte()...");
   Byte b = new Byte();
   if (b.toString().equals("00000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 7
0
 public static void test9() {
   int score = 0;
   int total = 3;
   ps.println("\n** Testing decimalValue()... ");
   Byte b = new Byte(5);
   if (b.decimalValue() == 5 && b.toString().equals("00000101")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.set(-3);
   if (b.decimalValue() == -3 && b.toString().equals("11111101")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b = new Byte();
   if (b.decimalValue() == 0 && b.toString().equals("00000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 8
0
 public static void test3() {
   int score = 0;
   int total = 3;
   ps.println("\n** Testing add(Byte other)... ");
   Byte b1 = new Byte(12);
   Byte b2 = new Byte(5);
   b1.add(b2);
   if (b1.toString().equals("00010001") && b2.toString().equals("00000101")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b1 = new Byte(126);
   b2 = new Byte(0);
   b1.add(b2);
   if (b1.toString().equals("01111110") && b2.toString().equals("00000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b2.set(1);
   b1.add(b2);
   if (b1.toString().equals("01111111") && b2.toString().equals("00000001")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 9
0
 public static void test8() {
   int score = 0;
   int total = 3;
   ps.println("\n** Testing subtract(int n)... ");
   Byte b = new Byte();
   b.subtract(5);
   if (b.toString().equals("11111011")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.subtract(-6);
   if (b.toString().equals("00000001")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.subtract(0);
   if (b.toString().equals("00000001")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 10
0
 public static void test4() {
   int score = 0;
   int total = 3;
   ps.println("\n** Testing add(int n)... ");
   Byte b = new Byte(10);
   b.add(3);
   if (b.toString().equals("00001101")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.add(114);
   if (b.toString().equals("01111111")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.add(0);
   if (b.toString().equals("01111111")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 11
0
  private void setBytes(byte[] bytes) {
    String string = "";
    for (int k = 0; k < bytes.length; k++) {
      string = string.concat(Byte.toString(bytes[k]));
    }

    try {
      BufferedWriter out = new BufferedWriter(new PrintWriter(new FileWriter(drive)));
      out.write(string);
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 12
0
 public static void test7() {
   int score = 0;
   int total = 3;
   ps.println("\n** REesting constructor: new Byte(int n)... ");
   ps.println("** REtesting add (Byte b)...");
   ps.println("** REtesting add (int n)...");
   Byte b = new Byte(-10);
   if (b.toString().equals("11110110")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.add(new Byte(-3));
   if (b.toString().equals("11110011")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.add(-4);
   if (b.toString().equals("11101111")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 13
0
  // Gets a property and converts it into byte.
  static byte getByteProperty(String propName, byte defaultValue) {

    String temp = getConfigValue(propName);
    byte result = defaultValue;
    if (temp != null) {
      result = Byte.parseByte(temp);
      Logger.info("{DB}-" + propName + ":" + result);
    } else {

      result = Byte.parseByte(properties.getProperty(propName, Byte.toString(defaultValue)).trim());
      Logger.info("{FILE}-" + propName + ":" + result);
    }

    return result;
  }
Ejemplo n.º 14
0
 public void write_octet(byte value, java.lang.String tag) {
   Byte obj = new Byte(value);
   write_open_tag(tag);
   write_pcdata(obj.toString());
   write_close_tag(tag);
 }
Ejemplo n.º 15
0
 // ========================================================================//
 // ============================ PRIVATE METHODS ===========================//
 // ========================================================================//
 // Gets a property and converts it into byte.
 static byte getByteProperty(String propName, byte defaultValue) {
   return Byte.parseByte(properties.getProperty(propName, Byte.toString(defaultValue)).trim());
 }
Ejemplo n.º 16
0
  /**
   * Loads configuration parameters from the file with the given name. Sets private variable to the
   * loaded values.
   */
  public static void loadProperties(String fileName) throws IOException {
    // System.out.println("Reading configuration file " + fileName + "...");
    Logger.info("Reading configuration file " + fileName + "...");
    FileInputStream propsFile = new FileInputStream(fileName);
    properties.load(propsFile);
    propsFile.close();

    try {
      String gateway_name = properties.getProperty("gateway_name", "");
      // if ("".equalsIgnoreCase(gateway_name)) {
      Logger.info("Reading configuration file");
      // } else {
      // Logger.info("retrieveConfigGW from DB :" + gateway_name);
      // preference = ConfigGW.retrieveConfigGW(gateway_name);
      // }

    } catch (Exception e1) {
      // TODO Auto-generated catch block
      Logger.info("retrieveConfigGW " + e1.toString() + "...");
      e1.printStackTrace();
    }

    // System.out.println("Setting default parameters...");
    // Alert va Log config

    Logger.info("Setting parameters...");
    ALERT = getIntProperty("ALERT", 1);
    ALERT_CONTACT = getStringProperty("ALERT_CONTACT", ALERT_CONTACT);

    ALERT_EMSQUEUE = getIntProperty("ALERT_EMSQUEUE", ALERT_EMSQUEUE);
    ALERT_FROMSMSC = getIntProperty("ALERT_FROMSMSC", ALERT_FROMSMSC);
    ALERT_TOSMSC = getIntProperty("ALERT_TOSMSC", ALERT_TOSMSC);
    ALERT_RESPONSESMSC = getIntProperty("ALERT_RESPONSESMSC", ALERT_RESPONSESMSC);

    byte ton;
    byte npi;
    String addr;

    // Thread MO- MT - Respond
    nTheardMO = getIntProperty("num_thread_mo", 1);
    nTheardMT = getIntProperty("num_thread_mt", 1);
    nTheardResp = getIntProperty("num_thread_respond", 1);
    nLogQueue = getIntProperty("log_queue", 1);
    WriteLog = getIntProperty("write_log", 1);
    ViewConsole = getIntProperty("view_console", 1);

    nAddNewTheardMO = getIntProperty("add_thread_mo", 0);
    nAddNewTheardMT = getIntProperty("add_thread_mt", 0);
    nAddNewTheardResp = getIntProperty("add_thread_respond", 0);
    nAddNewBuildEMS = getIntProperty("add_build_ems", 0);
    nAddNewSendLog = getIntProperty("add_thread_send_log", 0);
    nAddNewMOSim = getIntProperty("add_thread_mo_sim", 0);

    nTheardMOSim = getIntProperty("num_thread_mo_sim", 1);
    nBuildEMS = getIntProperty("num_build_ems", 1);
    nGetMTfromDB = getIntProperty("num_get_mt_from_db", 1);
    nSendLog = getIntProperty("num_thread_send_log", 1);

    ipAddress = getStringProperty("ip_address");
    port = getIntProperty("port", port);
    systemId = getStringProperty("system_id"); // username
    password = getStringProperty("password");
    ketqua = getStringProperty("ketqua");
    Channel = getStringProperty("channel");
    // The address range this smpp gateway will serve
    ton = getByteProperty("addr_ton", addressRange.getTon());
    npi = getByteProperty("addr_npi", addressRange.getNpi());
    addr = getStringProperty("addr_range", addressRange.getAddressRange());
    addressRange.setTon(ton);
    addressRange.setNpi(npi);
    try {
      addressRange.setAddressRange(addr);
    } catch (WrongLengthOfStringException e) {
      System.out.println("The length of address_range parameter is wrong.");
    }

    // The source address for this gateway
    src_addr_ton = getByteProperty("source_addr_ton", src_addr_ton);
    src_addr_npi = getByteProperty("source_addr_npi", src_addr_npi);

    sourceAddressList = parseString(properties.getProperty("source_addr", ""));

    if (sourceAddressList != null && sourceAddressList.size() > 0) {
      Logger.info("This gateway will process: " + sourceAddressList);
    } else {
      Logger.info("Warning: No source address is specified!");
    }

    // The default destination address
    dest_addr_ton = getByteProperty("dest_addr_ton", dest_addr_ton);
    dest_addr_npi = getByteProperty("dest_addr_npi", dest_addr_npi);
    addr = getStringProperty("destination_addr", "");

    serviceType = getStringProperty("service_type", serviceType);
    systemType = getStringProperty("system_type", systemType);

    // bind mode
    String strTemp = getStringProperty("bind_mode", bindMode);
    if (!strTemp.equalsIgnoreCase("t")
        && !strTemp.equalsIgnoreCase("r")
        && !strTemp.equalsIgnoreCase("tr")) {
      Logger.info(
          "Wrong value of bind_mode parameter in "
              + "the configuration file "
              + fileName
              + "--> Setting the default: t");
      strTemp = "t";
    }
    bindMode = strTemp;

    // Tham so Lottery
    ketqua = null;
    bLottery = false;
    bLog = false;

    // Receiving mode
    String syncMode = getStringProperty("sync_mode", (asynchronous ? "async" : "sync"));
    if (syncMode.equalsIgnoreCase("sync")) {
      asynchronous = false;
    } else if (syncMode.equalsIgnoreCase("async")) {
      asynchronous = true;
    } else {
      asynchronous = false;
    }
    // receive timeout in the cfg file is in seconds, we need milliseconds
    // also conversion from -1 which indicates infinite blocking
    // in the cfg file to Data.RECEIVE_BLOCKING which indicates infinite
    // blocking in the library is needed.
    int rcvTimeout = 0;
    rcvTimeout = getIntProperty("receive_timeout", rcvTimeout);
    if (rcvTimeout == -1) {
      receiveTimeout = Data.RECEIVE_BLOCKING; // infinite blocking
    } else {
      receiveTimeout = rcvTimeout * 1000; // secs -> millisecs
    }
    PayLoadUDH =
        Byte.toString((byte) 0x06)
            + Byte.toString((byte) 0x05)
            + Byte.toString((byte) 0x04)
            + Byte.toString((byte) 0x13)
            + Byte.toString((byte) 0x88)
            + Byte.toString((byte) 0x00)
            + Byte.toString((byte) 0x00);

    NumOfRetries = getIntProperty("num_retries", NumOfRetries);
    RetriesTime = getIntProperty("retries_time", RetriesTime);
    maxNumOfSend = getIntProperty("max_num_of_send", maxNumOfSend);
    logToFile = getIntProperty("log_to_file", logToFile);
    logToConsole = getIntProperty("log_to_console", logToConsole);
    logToFolder = getStringProperty("log_to_folder", logToFolder);
    MODatafile = getStringProperty("file_mo_data", MODatafile);
    logFullMessage = getIntProperty("log_full_message", logFullMessage);

    telnetServerPort = getIntProperty("telnet_server_port", telnetServerPort);
    telnetAllowedIp = parseIPaddresses(properties.getProperty("telnet_allowed_ip", ""));

    timeRebind = getIntProperty("time_rebind", timeRebind / 1000) * 1000;
    timeResend = getIntProperty("time_resend", timeResend);
    timeOut = getIntProperty("time_out", timeResend);
    timeEnquireLink = getIntProperty("time_enquire_link", timeEnquireLink / 1000) * 1000;

    maxSMPerSecond = getIntProperty("max_sm_per_sec", maxSMPerSecond);
    mobileOperator = getStringProperty("mobile_operator", mobileOperator).toUpperCase();

    String sTemp = getStringProperty("report_required", "0");
    if ("1".equals(sTemp)) {
      reportRequired = true;
    }
    sTemp = getStringProperty("cdr_enabled", "0");
    if ("1".equals(sTemp)) {
      cdrEnabled = true;
    }
    cdroutFolder = getStringProperty("cdrout_folder", cdroutFolder);
    cdrsentFolder = getStringProperty("cdrsent_folder", cdrsentFolder);
    LogFolder = getStringProperty("log_path", LogFolder);
    cdrfileExtension = getStringProperty("cdrfile_extension", cdrfileExtension);
    receiveLogFolder = getStringProperty("receive-log-folder", receiveLogFolder);
    sendLogFolder = getStringProperty("send-log-folder", sendLogFolder);
    // User for Viettel operator
    VIETTEL_MODE = getStringProperty("vt-mode", VIETTEL_MODE);
    SEND_MODE = getStringProperty("send_mode", SEND_MODE);
    prefix_requestid = getStringProperty("prefix_requestid", prefix_requestid);

    BLACKLIST = getStringProperty("BLACKLIST", BLACKLIST);

    // public static String[] LIST_DB_SEND_LOG = { "gateway" };
    // /public static String[] LIST_DB_CDR_QUEUE = { "gateway" };
    // public static String[] LIST_DB_SEND_QUEUE = { "gateway" };
    // public static String[] LIST_DB_ALERT = { "gateway" };
    // public static String[] LIST_TABLE_SEND_QUEUE = { "0" };
    // public static String[] LIST_DB_CONFIG = { "gateway" };
    // public static String[] LIST_DB_RECEIVE_QUEUE = { "gateway" };

    String sLIST_DB_SEND_LOG = properties.getProperty("LIST_DB_SEND_LOG", "gateway");
    LIST_DB_SEND_LOG = parseString(sLIST_DB_SEND_LOG, ",");

    String sLIST_DB_CDR_QUEUE = properties.getProperty("LIST_DB_CDR_QUEUE", "gateway");
    LIST_DB_CDR_QUEUE = parseString(sLIST_DB_CDR_QUEUE, ",");

    String sLIST_DB_SEND_QUEUE = properties.getProperty("LIST_DB_SEND_QUEUE", "gateway");
    LIST_DB_SEND_QUEUE = parseString(sLIST_DB_SEND_QUEUE, ",");

    String sLIST_DB_ALERT = properties.getProperty("LIST_DB_ALERT", "alert");
    LIST_DB_ALERT = parseString(sLIST_DB_ALERT, ",");

    String sLIST_TABLE_SEND_QUEUE = properties.getProperty("LIST_TABLE_SEND_QUEUE", "0");
    LIST_TABLE_SEND_QUEUE = parseString(sLIST_TABLE_SEND_QUEUE, ",");

    String sLIST_DB_CONFIG = properties.getProperty("LIST_DB_CONFIG", "gateway");
    LIST_DB_CONFIG = parseString(sLIST_DB_CONFIG, ",");

    String sLIST_DB_RECEIVE_QUEUE = properties.getProperty("LIST_DB_RECEIVE_QUEUE", "gateway");
    LIST_DB_RECEIVE_QUEUE = parseString(sLIST_DB_RECEIVE_QUEUE, ",");

    String sList_service = "";
    sList_service = properties.getProperty("LIST_SERVICEID", sList_service);
    if ("".equalsIgnoreCase(sList_service)) {
      arrLIST_SERVICEID = VALID_SERVICEID;
    } else {
      arrLIST_SERVICEID = parseString(sList_service, ",");
    }
    strLIST_SERVICEID = "";
    for (int ii = 0; ii < arrLIST_SERVICEID.length; ii++) {
      strLIST_SERVICEID = strLIST_SERVICEID + "," + "'" + arrLIST_SERVICEID[ii].trim() + "'";
    }
    strLIST_SERVICEID = strLIST_SERVICEID.substring(1);

    // Prefixes and message for each source_address
    /*
     * if (sourceAddressList != null && sourceAddressList.size() > 0) { for
     * (Iterator it = sourceAddressList.iterator(); it.hasNext();) { String
     * sNumber = (String) it.next(); Collection cPrefixes =
     * parseString(getStringProperty("prefix_" + sNumber)); if (cPrefixes !=
     * null && cPrefixes.size() > 0) { prefixMap.put(sNumber, cPrefixes); }
     * else { System.out.println("Warning: No prefix is specified for " +
     * sNumber); } String sMessage = getStringProperty("message_" +
     * sNumber); if (sMessage != null) { messageMap.put(sNumber, sMessage);
     * } else { System.out.println("Warning: No message is specified for " +
     * sNumber); } } }
     */
  }
Ejemplo n.º 17
0
 /**
  * Writes the given byte in XML format. <br>
  * <b>Note: Java specific type</b>
  *
  * @param b to write
  */
 public void writeByte(byte b) {
   this.writeValue(ByteStrategy.NAME, Byte.toString(b));
 }