/**
   * write out the header of the report's content
   *
   * @param bw the writer to use
   * @throws IOException if an error occurs
   */
  protected void writeHtmlBodyHeader(BufferedWriter bw) throws IOException {
    bw.write("<body>" + Dump.newLine());
    bw.write(Dump.newLine());

    bw.write("<h1>" + NAME + "</h1>" + Dump.newLine());

    bw.write("<a href=\"../index.html\">Main</a>" + Dump.newLine());
    bw.write("<p>" + Dump.newLine());
  }
Example #2
0
  public static void main(String[] args) {
    if (args.length == 0) {
      help();
      return;
    }

    // Consumes the command
    String command = args[0];
    String[] commandArgs = new String[args.length - 1];
    System.arraycopy(args, 1, commandArgs, 0, args.length - 1);

    if (command != null && !command.isEmpty()) {
      switch (command.toLowerCase()) {
        case "console":
          Console.main(commandArgs);
          break;
        case "dump":
          Dump.main(commandArgs);
          break;
        default:
          help();
      }
    } else {
      help();
    }
  }
  /**
   * 1:ANSI X9.8 Format(不带主账号) 06
   *
   * @param password
   * @param pinKey
   * @return
   * @throws Exception
   */
  public static String pinEncode(String password, byte[] pinKey) throws Exception {
    int passwordLength = password.length();
    String pin_fmt = StringUtils.rightPad("0" + passwordLength + password, 16, "F");
    byte[] pinBLOCK = DumpUtils.hexToBytes(pin_fmt);
    System.out.println("无主帐号pinBlock:" + Dump.getHexDump(pinBLOCK));

    byte[] des3Info = DesUtils.tripDesEncrypt(pinBLOCK, pinKey);
    return DumpUtils.bytesToHex(des3Info);
  }
  /**
   * 1:ANSI X9.8 Format(带主账号)
   *
   * @param password
   * @param pinKey
   * @param pan
   * @return
   * @throws Exception
   */
  public static String pinEncode(String password, byte[] pinKey, String pan) throws Exception {
    int passwordLength = password.length();
    int panLength = pan.length();
    String pin_fmt = StringUtils.rightPad("0" + passwordLength + password, 16, "F");
    byte[] pinBLOCK = DumpUtils.hexToBytes(pin_fmt);
    String pin_str = "0000" + pan.substring(3, 15);
    System.out.println("pinBlock:" + pin_str);
    byte[] panByte = DumpUtils.hexToBytes(pin_str);
    for (int i = 0; i < panByte.length; i++) {
      pinBLOCK[i] ^= panByte[i];
    }
    System.out.println("有主帐号pinBlock:" + Dump.getHexDump(pinBLOCK));

    byte[] des3Info = DesUtils.tripDesEncrypt(pinBLOCK, pinKey);
    return DumpUtils.bytesToHex(des3Info);
  }
Example #5
0
  public void packetReceived(byte[] packet) {
    // XXX: hack: with the new packetsource format, packet does not
    // contain a crc field, so numElements_data() will be wrong. But we
    // access the data area via dataSet/dataGet, so we're ok.

    // this is where the source comes in to create the correct packet

    final TOSMsg msg = messageFactory.createTOSMsg(packet);

    if (DEBUG) Dump.dump("Received message", packet);

    if (drop_bad_crc && msg.get_crc() != 0x01) {
      // Drop message
      if (DISPLAY_ERROR_MSGS) Dump.dump("Dropping packet with bad CRC", packet);
      return;
    }

    if (groupId == MoteIF.ANY_GROUP_ID || msg.get_group() == groupId) {
      Integer type = new Integer(msg.get_type());
      Vector vec = (Vector) templateTbl.get(type);
      if (vec == null) {
        if (DEBUG)
          Dump.dump(
              "Received packet with type " + msg.get_type() + ", but no listeners registered",
              packet);
        return;
      }
      int length = msg.get_length();

      Enumeration en = vec.elements();
      while (en.hasMoreElements()) {
        msgTemplate temp = (msgTemplate) en.nextElement();

        Message received;

        // Erk - end up cloning the message multiple times in case
        // different templates used for different listeners
        try {
          received = temp.template.clone(length);
          received.dataSet(msg.dataGet(), msg.offset_data(0), 0, length);
        } catch (ArrayIndexOutOfBoundsException e) {
          /*
           * Note: this will not catch messages whose length is
           * incorrect, but less than DATA_LENGTH (see AM.h) + 2
           */
          error(temp, "invalid length message received (too long)");
          continue;
        } catch (Exception e) {
          error(temp, "couldn't clone message!");
          continue;
        }

        /*
         * Messages that are longer than the template might have a
         * variable-sized array at their end
         */
        if (temp.template.dataGet().length > length) {
          error(temp, "invalid length message received (too short)");
          continue;
        }
        temp.listener.messageReceived(msg.get_addr(), received);
      }

    } else {
      if (DISPLAY_ERROR_MSGS) Dump.dump("Dropping packet with bad group ID", packet);
    }
  }
Example #6
0
  boolean dodata(ServletTest testcase) throws Exception {
    boolean pass = true;
    String baseline;
    // Create request and response objects
    Mocker mocker = new Mocker("dap4", testcase.makeurl(RequestMode.DAP), this);
    byte[] byteresult = null; // output

    // See if the servlet can process this
    try {
      byteresult = mocker.execute();
    } catch (Throwable t) {
      System.out.println(testcase.xfail ? "XFail" : "Fail");
      t.printStackTrace();
      return testcase.xfail;
    }

    if (prop_debug || DEBUG) {
      DapDump.dumpbytestream(byteresult, ByteOrder.nativeOrder(), "TestServlet.dodata");
    }

    if (!testcase.xfail && prop_generate) {
      // Dump the serialization into a file; this also includes the dmr
      String target = testcase.generatepath + ".raw";
      writefile(target, byteresult);
    }

    if (DEBUG) {
      System.out.println("///////////////////");
      ByteBuffer datab = ByteBuffer.wrap(byteresult).order(ByteOrder.nativeOrder());
      DapDump.dumpbytes(datab, true);
      System.out.println("///////////////////");
      System.out.flush();
    }

    // Setup a ChunkInputStream
    ByteArrayInputStream bytestream = new ByteArrayInputStream(byteresult);

    ChunkInputStream reader =
        new ChunkInputStream(bytestream, RequestMode.DAP, ByteOrder.nativeOrder());

    String sdmr = reader.readDMR(); // Read the DMR
    if (prop_visual) visual(testcase.title + ".dmr.dap", sdmr);

    Dump printer = new Dump();
    String sdata =
        printer.dumpdata(reader, testcase.checksumming, reader.getByteOrder(), testcase.template);

    if (prop_visual) visual(testcase.title + ".dap", sdata);

    if (!testcase.xfail && prop_baseline) writefile(testcase.baselinepath + ".dap", sdata);

    if (prop_diff) {
      // compare with baseline
      // Read the baseline file
      System.out.println("Note Comparison:");
      String baselinecontent = readfile(testcase.baselinepath + ".dap");
      pass = compare(baselinecontent, sdata);
      System.out.println(pass ? "Pass" : "Fail");
    }

    return pass;
  }
  /**
   * write out the report's content
   *
   * @param bw the writer to use
   * @throws IOException if an error occurs
   */
  protected void writeHtmlBodyContent(BufferedWriter bw) throws IOException {
    bw.write("<table>" + Dump.newLine());

    bw.write("  <tr>" + Dump.newLine());
    bw.write("     <th>Class</th>" + Dump.newLine());
    bw.write("     <th>Depends On</th>" + Dump.newLine());
    bw.write("  </tr>" + Dump.newLine());

    SortedMap<String, SortedSet<String>> result = new TreeMap<String, SortedSet<String>>();
    boolean odd = true;

    for (Archive archive : archives) {
      if (archive.getType() == ArchiveTypes.JAR) {
        SortedMap<String, SortedSet<String>> classDependencies = archive.getClassDependencies();

        Iterator<Map.Entry<String, SortedSet<String>>> dit =
            classDependencies.entrySet().iterator();
        while (dit.hasNext()) {
          Map.Entry<String, SortedSet<String>> entry = dit.next();
          String clz = entry.getKey();
          SortedSet<String> deps = entry.getValue();

          SortedSet<String> newDeps = new TreeSet<String>();

          for (String dep : deps) {
            if (!dep.equals(clz)) {
              newDeps.add(dep);
            }
          }

          result.put(clz, newDeps);
        }
      }
    }

    Iterator<Map.Entry<String, SortedSet<String>>> rit = result.entrySet().iterator();

    while (rit.hasNext()) {
      Map.Entry<String, SortedSet<String>> entry = rit.next();
      String clz = entry.getKey();
      SortedSet<String> deps = entry.getValue();

      if (odd) {
        bw.write("  <tr class=\"rowodd\">" + Dump.newLine());
      } else {
        bw.write("  <tr class=\"roweven\">" + Dump.newLine());
      }
      bw.write("     <td>" + clz + "</a></td>" + Dump.newLine());
      bw.write("     <td>");

      Iterator<String> sit = deps.iterator();
      while (sit.hasNext()) {
        String dep = sit.next();
        bw.write(dep);

        if (sit.hasNext()) {
          bw.write(", ");
        }
      }

      bw.write("</td>" + Dump.newLine());
      bw.write("  </tr>" + Dump.newLine());

      odd = !odd;
    }

    bw.write("</table>" + Dump.newLine());
  }
Example #8
0
/**
 * Factory for command line tools to call different functions
 *
 * @author Muhammad Shamim
 * @since 1/30/2015
 */
public class CLTFactory {

  // Commenting some out because we're not going to release all these when we release CLT
  private static final String[] commandLineToolUsages = {
    //        "addGWNorm",    "addGWNorm <input_HiC_file> <min resolution>",
    //        "addNorm",      "addNorm <input_HiC_file> [0 for no frag, 1 for no single frag]",
    //        "bigWig",       "bigWig <bigWig path or URL> <window size in bp> [chr] [start base]
    // [end base]",
    //        "binToPairs",   "binToPairs <input_HiC_file> <output_HiC_file>",
    //        "bpToFrag",     "bpToFrag <fragmentFile> <inputBedFile> <outputFile>",
    //        "calcKR",       "calcKR <input_HiC_file>",
    //        "fragmentToBed","fragmentToBed <fragmentFile>",
    //        "pairsToBin",   "pairsToBin <input_HiC_file> <output_HiC_file> <genomeID>",
    //        "db",           "db <frag|annot|update> [items]",
    Dump.getUsage(),
    PreProcessing.getBasicUsage(),
    APA.getBasicUsage(),
    Arrowhead.getBasicUsage(),
    HiCCUPS.getBasicUsage(),
    HiCCUPSDiff.getBasicUsage(),
    ValidateFile.getUsage()
  };

  public static void generalUsage() {

    System.out.println("Juicebox and Juicer Command Line Tools Usage:");
    for (String usage : commandLineToolUsages) {
      System.out.println("\t\t" + usage);
    }
    System.out.println("Type juicebox <commandName> for more detailed usage instructions");
  }

  public static JuiceboxCLT getCLTCommand(String cmd) {

    cmd = cmd.toLowerCase();

    if (cmd.equals("pre")) {
      return new PreProcessing();
    } else if (cmd.equals("dump")) {
      return new Dump();
    } else if (cmd.equals("validate")) {
      return new ValidateFile();
    } else if (cmd.equals("addGWNorm".toLowerCase())) {
      return new AddGWNorm();
    } else if (cmd.equals("addNorm".toLowerCase())) {
      return new AddNorm();
    } else if (cmd.equals("apa")) {
      return new APA();
    } else if (cmd.equals("compare")) {
      return new CompareLists();
    } else if (cmd.equals("arrowhead")) {
      return new Arrowhead();
    } else if (cmd.equals("bigWig".toLowerCase())) {
      return new BigWig();
    } else if (cmd.equals("binToPairs".toLowerCase())) {
      return new BinToPairs();
    } else if (cmd.equals("bpToFrag".toLowerCase())) {
      return new BPToFragment();
    } else if (cmd.equals("calcKR".toLowerCase())) {
      return new CalcKR();
    } else if (cmd.equals("fragmentToBed".toLowerCase())) {
      return new FragmentToBed();
    } else if (cmd.equals("hiccups")) {
      return new HiCCUPS();
    } else if (cmd.equals("motifs")) {
      return new MotifFinder();
    } else if (cmd.equals("pairsToBin".toLowerCase())) {
      return new PairsToBin();
    } else if (cmd.equals("db")) {
      return new SQLDatabase();
    } else if (cmd.equals("hiccupsdiff")) {
      return new HiCCUPSDiff();
    } else if (cmd.equals("ab_compdiff")) {
      return new ABCompartmentsDiff();
    }

    return null;
  }
}