Ejemplo n.º 1
0
 /** Helper printing function */
 private static String byteArrayInString(byte[] data) {
   StringBuilder result = new StringBuilder();
   for (Byte b : data) {
     result.append(b.intValue()).append(" ");
   }
   return result.toString();
 }
Ejemplo n.º 2
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.º 3
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.º 4
0
 Record rdataFromString(Name name, short dclass, int ttl, MyStringTokenizer st, Name origin)
     throws TextParseException {
   SIGRecord rec = new SIGRecord(name, dclass, ttl);
   rec.covered = Type.value(st.nextToken());
   rec.alg = Byte.parseByte(st.nextToken());
   rec.labels = Byte.parseByte(st.nextToken());
   rec.origttl = TTL.parseTTL(st.nextToken());
   rec.expire = parseDate(st.nextToken());
   rec.timeSigned = parseDate(st.nextToken());
   rec.footprint = (short) Integer.parseInt(st.nextToken());
   rec.signer = Name.fromString(st.nextToken(), origin);
   if (st.hasMoreTokens()) rec.signature = base64.fromString(st.remainingTokens());
   return rec;
 }
Ejemplo n.º 5
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;
  }
  /**
   * Convert a byte array to a hex string
   *
   * @param bytes byte array to convert to a hex string
   * @return return a String in hex representing the byte array
   */
  public String toHexString(byte[] bytes) {
    StringBuffer result = new StringBuffer("0x");

    for (int i = 0; i < bytes.length; i++) {
      Byte aByte = new Byte(bytes[i]);
      Integer anInt = new Integer(aByte.intValue());
      String hexVal = Integer.toHexString(anInt.intValue());

      if (hexVal.length() > SIZE) hexVal = hexVal.substring(hexVal.length() - SIZE);

      result.append(
          (SIZE > hexVal.length() ? ZEROS.substring(0, SIZE - hexVal.length()) : "") + hexVal);
    }
    return (result.toString());
  }
  /**
   * Parses the arguments table from the GATK Report and creates a RAC object with the proper
   * initialization values
   *
   * @param table the GATKReportTable containing the arguments and its corresponding values
   * @return a RAC object properly initialized with all the objects in the table
   */
  private RecalibrationArgumentCollection initializeArgumentCollectionTable(GATKReportTable table) {
    final RecalibrationArgumentCollection RAC = new RecalibrationArgumentCollection();

    for (int i = 0; i < table.getNumRows(); i++) {
      final String argument = table.get(i, "Argument").toString();
      Object value = table.get(i, RecalUtils.ARGUMENT_VALUE_COLUMN_NAME);
      if (value.equals("null"))
        value =
            null; // generic translation of null values that were printed out as strings | todo --
                  // add this capability to the GATKReport

      if (argument.equals("covariate") && value != null)
        RAC.COVARIATES = value.toString().split(",");
      else if (argument.equals("standard_covs"))
        RAC.DO_NOT_USE_STANDARD_COVARIATES = Boolean.parseBoolean((String) value);
      else if (argument.equals("solid_recal_mode"))
        RAC.SOLID_RECAL_MODE = RecalUtils.SOLID_RECAL_MODE.recalModeFromString((String) value);
      else if (argument.equals("solid_nocall_strategy"))
        RAC.SOLID_NOCALL_STRATEGY =
            RecalUtils.SOLID_NOCALL_STRATEGY.nocallStrategyFromString((String) value);
      else if (argument.equals("mismatches_context_size"))
        RAC.MISMATCHES_CONTEXT_SIZE = Integer.parseInt((String) value);
      else if (argument.equals("indels_context_size"))
        RAC.INDELS_CONTEXT_SIZE = Integer.parseInt((String) value);
      else if (argument.equals("mismatches_default_quality"))
        RAC.MISMATCHES_DEFAULT_QUALITY = Byte.parseByte((String) value);
      else if (argument.equals("insertions_default_quality"))
        RAC.INSERTIONS_DEFAULT_QUALITY = Byte.parseByte((String) value);
      else if (argument.equals("deletions_default_quality"))
        RAC.DELETIONS_DEFAULT_QUALITY = Byte.parseByte((String) value);
      else if (argument.equals("maximum_cycle_value"))
        RAC.MAXIMUM_CYCLE_VALUE = Integer.parseInt((String) value);
      else if (argument.equals("low_quality_tail"))
        RAC.LOW_QUAL_TAIL = Byte.parseByte((String) value);
      else if (argument.equals("default_platform")) RAC.DEFAULT_PLATFORM = (String) value;
      else if (argument.equals("force_platform")) RAC.FORCE_PLATFORM = (String) value;
      else if (argument.equals("quantizing_levels"))
        RAC.QUANTIZING_LEVELS = Integer.parseInt((String) value);
      else if (argument.equals("recalibration_report"))
        RAC.existingRecalibrationReport = (value == null) ? null : new File((String) value);
      else if (argument.equals("binary_tag_name"))
        RAC.BINARY_TAG_NAME = (value == null) ? null : (String) value;
      else if (argument.equals("sort_by_all_columns"))
        RAC.SORT_BY_ALL_COLUMNS = Boolean.parseBoolean((String) value);
    }

    return RAC;
  }
  private RecalDatum getRecalDatum(
      final GATKReportTable reportTable, final int row, final boolean hasEstimatedQReportedColumn) {
    final long nObservations =
        asLong(reportTable.get(row, RecalUtils.NUMBER_OBSERVATIONS_COLUMN_NAME));
    final double nErrors = asDouble(reportTable.get(row, RecalUtils.NUMBER_ERRORS_COLUMN_NAME));
    // final double empiricalQuality = asDouble(reportTable.get(row,
    // RecalUtils.EMPIRICAL_QUALITY_COLUMN_NAME));

    // the estimatedQreported column only exists in the ReadGroup table
    final double estimatedQReported =
        hasEstimatedQReportedColumn
            ? (Double) reportTable.get(row, RecalUtils.ESTIMATED_Q_REPORTED_COLUMN_NAME)
            : // we get it if we are in the read group table
            Byte.parseByte(
                (String)
                    reportTable.get(
                        row,
                        RecalUtils
                            .QUALITY_SCORE_COLUMN_NAME)); // or we use the reported quality if we
                                                          // are in any other table

    final RecalDatum datum = new RecalDatum(nObservations, nErrors, (byte) 1);
    datum.setEstimatedQReported(estimatedQReported);
    // datum.setEmpiricalQuality(empiricalQuality); // don't set the value here because we will want
    // to recompute with a different conditional Q score prior value
    return datum;
  }
Ejemplo n.º 9
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.º 10
0
  public static List readWatchableObjects(DataInputStream par0DataInputStream) throws IOException {
    ArrayList arraylist = null;

    for (byte byte0 = par0DataInputStream.readByte();
        byte0 != 127;
        byte0 = par0DataInputStream.readByte()) {
      if (arraylist == null) {
        arraylist = new ArrayList();
      }

      int i = (byte0 & 0xe0) >> 5;
      int j = byte0 & 0x1f;
      WatchableObject watchableobject = null;

      switch (i) {
        case 0:
          watchableobject = new WatchableObject(i, j, Byte.valueOf(par0DataInputStream.readByte()));
          break;

        case 1:
          watchableobject =
              new WatchableObject(i, j, Short.valueOf(par0DataInputStream.readShort()));
          break;

        case 2:
          watchableobject =
              new WatchableObject(i, j, Integer.valueOf(par0DataInputStream.readInt()));
          break;

        case 3:
          watchableobject =
              new WatchableObject(i, j, Float.valueOf(par0DataInputStream.readFloat()));
          break;

        case 4:
          watchableobject = new WatchableObject(i, j, Packet.readString(par0DataInputStream, 64));
          break;

        case 5:
          short word0 = par0DataInputStream.readShort();
          byte byte1 = par0DataInputStream.readByte();
          short word1 = par0DataInputStream.readShort();
          watchableobject = new WatchableObject(i, j, new ItemStack(word0, byte1, word1));
          break;

        case 6:
          int k = par0DataInputStream.readInt();
          int l = par0DataInputStream.readInt();
          int i1 = par0DataInputStream.readInt();
          watchableobject = new WatchableObject(i, j, new ChunkCoordinates(k, l, i1));
          break;
      }

      arraylist.add(watchableobject);
    }

    return arraylist;
  }
Ejemplo n.º 11
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.º 12
0
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // For each test
    StringBuffer sb = new StringBuffer();
    for (byte T = Byte.parseByte(br.readLine()); T > 0; --T) {

      // INPUT
      byte N = Byte.parseByte(br.readLine());
      int[] A = new int[N];
      N = 0;
      for (String s : br.readLine().split(" ")) {
        A[N++] = Integer.parseInt(s);
      }

      sb.append(solve(A, N) ? YES : NO);
    }
    System.out.print(sb);
  }
Ejemplo n.º 13
0
 public boolean giveItem(String name, int id, int quant, int data) throws Exception {
   try {
     byte realData = Byte.valueOf(String.valueOf(data));
     Player p = getPlayerExact(name);
     MaterialData materialData = new MaterialData(id, realData);
     p.getInventory().addItem(materialData.toItemStack(quant));
     p.saveData();
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
Ejemplo n.º 14
0
 public boolean giveItemDrop(String name, int id, int quant, int data) throws Exception {
   try {
     Player p = getPlayerExact(name);
     ItemStack stack = new ItemStack(id, quant);
     stack.setData(new MaterialData(id, Byte.valueOf(String.valueOf(data)).byteValue()));
     p.getWorld().dropItem(p.getLocation(), stack);
     p.saveData();
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
Ejemplo n.º 15
0
 /** {@inheritDoc} */
 @SuppressWarnings({"SuspiciousMethodCalls"})
 public boolean retainAll(Collection<?> collection) {
   boolean modified = false;
   TByteIterator iter = iterator();
   while (iter.hasNext()) {
     if (!collection.contains(Byte.valueOf(iter.next()))) {
       iter.remove();
       modified = true;
     }
   }
   return modified;
 }
  public static void main(String[] args) throws IOException {
    StringBuffer sb = new StringBuffer();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // For each test case
    for (byte T = Byte.parseByte(br.readLine()); T > 0; --T) {

      // Solve
      sb.append(getMinDeletions(br.readLine().toCharArray()) + "\n");
    }
    System.out.print(sb);
  }
Ejemplo n.º 17
0
  /*
   * Read a single pair of (X,Y) values from the ADXL202EVB board.
   * TODO: Better return value, or declare as throwing exception for errs
   */
  public static double[] chipRead() {
    double[] retval = {0.0, 0.0};
    byte[] rawBuf = {0, 0, 0, 0};
    int[] vals = {0, 0};

    try {
      // Read is triggered by sending 'G' to board
      outputStream.write('G');

      // Wait for all 4 result bytes to arrive
      // TODO: Finite wait w/error return if data never arrives
      while (inputStream.available() < 4) {
        Thread.sleep(1);
      }

      inputStream.read(rawBuf, 0, 4);

      // Convert from raw bytes to 16-bit signed integers, carefully
      Byte bTmp = new Byte(rawBuf[0]);
      vals[0] = bTmp.intValue() * 256;
      bTmp = new Byte(rawBuf[1]);
      vals[0] += bTmp.intValue();

      bTmp = new Byte(rawBuf[2]);
      vals[1] = bTmp.intValue() * 256;
      bTmp = new Byte(rawBuf[3]);
      vals[1] += bTmp.intValue();

      // See ADXL202EVB specs for details on conversion
      retval[0] = (((vals[0] / 100.0) - 50.0) / 12.5);
      retval[1] = (((vals[1] / 100.0) - 50.0) / 12.5);

      System.out.println("X: " + retval[0] + " Y: " + retval[1]);

    } catch (Exception ioe) {
      System.out.println("Error on data transmission");
    }
    return (retval);
  }
Ejemplo n.º 18
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.º 19
0
 /**
  * Parses the quantization table from the GATK Report and turns it into a map of original =>
  * quantized quality scores
  *
  * @param table the GATKReportTable containing the quantization mappings
  * @return an ArrayList with the quantization mappings from 0 to MAX_SAM_QUAL_SCORE
  */
 private QuantizationInfo initializeQuantizationTable(GATKReportTable table) {
   final Byte[] quals = new Byte[QualityUtils.MAX_SAM_QUAL_SCORE + 1];
   final Long[] counts = new Long[QualityUtils.MAX_SAM_QUAL_SCORE + 1];
   for (int i = 0; i < table.getNumRows(); i++) {
     final byte originalQual = (byte) i;
     final Object quantizedObject = table.get(i, RecalUtils.QUANTIZED_VALUE_COLUMN_NAME);
     final Object countObject = table.get(i, RecalUtils.QUANTIZED_COUNT_COLUMN_NAME);
     final byte quantizedQual = Byte.parseByte(quantizedObject.toString());
     final long quantizedCount = Long.parseLong(countObject.toString());
     quals[originalQual] = quantizedQual;
     counts[originalQual] = quantizedCount;
   }
   return new QuantizationInfo(Arrays.asList(quals), Arrays.asList(counts));
 }
  public static void main(String[] args) throws IOException {
    StringBuffer sb = new StringBuffer();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // INPUT
    for (byte T = Byte.parseByte(br.readLine()); T > 0; --T) {
      String[] input = br.readLine().split(" ");
      int A = Integer.parseInt(input[0]);
      int B = Integer.parseInt(input[1]);

      // SOLVE
      int C = (int) (Math.floor(Math.sqrt(B)) - Math.ceil(Math.sqrt(A)) + 1);
      sb.append(C + "\n");
    }

    // OUTPUT
    System.out.print(sb);
  }
 @Test
 public void test_uint8_t() throws IOException {
   for (Integer exp : expected_uint8) {
     UnsignedByte result = binFileReader.uint8_t();
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " asInt()",
         (Integer) Byte.toUnsignedInt(exp.byteValue()),
         result.asInt());
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " getSignedValue()",
         (Byte) exp.byteValue(),
         result.getSignedValue());
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " toString()",
         Integer.toString((((exp < 0 ? exp + 256 : exp)))),
         result.toString());
   }
 }
Ejemplo n.º 22
0
  public byte[] getBytes() {
    try {
      BufferedReader in = new BufferedReader(new FileReader(drive));
      String bytes = in.readLine();
      in.close();
      byte[] toReturn = new byte[bytes.length()];
      for (int k = 0; k < toReturn.length; k++) {
        toReturn[k] = Byte.decode(bytes.substring(k, k + 1));
      }

      return toReturn;
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
Ejemplo n.º 23
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);
 }
 @Test
 public void test_manuel_uint8_t() throws IOException {
   // 73 4B C3 BC
   // 115, 75, -61, -68
   byte[] input = {115, 75, -61, -68};
   int[] expected = {0x73, 0x4B, 0xC3, 0xBC};
   BinFileReader binFileReader =
       new BinFileReader(new BufferedInputStream(new ByteArrayInputStream(input)));
   for (int i = 0; i < input.length; i++) {
     UnsignedByte result = binFileReader.uint8_t();
     Integer exp = expected[i];
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " asInt()",
         (Integer) Byte.toUnsignedInt(exp.byteValue()),
         result.asInt());
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " getSignedValue()",
         (Byte) exp.byteValue(),
         result.getSignedValue());
   }
 }
Ejemplo n.º 25
0
 public static void test5() {
   int score = 0;
   int total = 3;
   ps.println("\n** Testing negate()... ");
   Byte b = new Byte(5);
   b.negate();
   if (b.toString().equals("11111011")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.negate();
   if (b.toString().equals("00000101")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   b.set(0);
   b.negate();
   if (b.toString().equals("00000000")) {
     ps.println("PASS");
     score++;
   } else ps.println("FAIL");
   report(score, total);
 }
Ejemplo n.º 26
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.º 27
0
  public static void test13() {
    int score = 0;
    int total = 3;
    ps.println("\n** Testing equals()... ");
    Byte b = new Byte(109);
    if (b.equals(new Byte(109)) && new Byte(109).equals(b)) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");
    b.add(1);
    if (!b.equals(new Byte(109)) && !(new Byte(109).equals(b))) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");
    b.set(-19);
    if (!b.equals(new Byte(109)) && !(new Byte(109).equals(b))) {
      ps.println("PASS");
      score++;
    } else ps.println("FAIL");

    report(score, total);
  }
Ejemplo n.º 28
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.º 29
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.º 30
0
 private static Byte negate(Byte v) {
   return new Byte((byte) -v.byteValue());
 }