Ejemplo n.º 1
0
 /**
  * Constructor for the XttRefObj object
  *
  * @param fullname Description of the Parameter
  * @param en Description of the Parameter
  * @param cid Description of the Parameter
  * @param treeNode Description of the Parameter
  * @param index Description of the Parameter
  */
 public XttRefObj(
     String fullname,
     JopEngine en,
     int cid, /*String showableClassName,*/
     DefaultMutableTreeNode treeNode,
     int index) {
   this.index = index;
   this.fullname = fullname;
   XttRefObj.en = en;
   this.cid = cid;
   //    this.showableClassName = showableClassName;
   if (index < 0) {
     Logg.logg("Fel vid försök att debugga", 0);
     return;
   }
   CdhrObjAttr oa = AttrObj[index];
   Logg.logg("XttRefObj konstruktor", 6);
   if (oa != null) {
     objAttribute = new XttObjAttr(oa);
     objAttribute.treeNode = treeNode;
     objAttribute.showName = false;
     en.add(this);
   } else {
     Logg.logg("Kan ej debugga " + fullname + " cid: " + cid + " på index " + index, 0);
   }
 }
Ejemplo n.º 2
0
  /**
   * Gets the xttObjAttr attribute of the XttRefObj object
   *
   * @return The xttObjAttr value
   */
  public XttObjAttr getXttObjAttr() {

    Logg.logg("XttRefObj: getXttObjAttr", 6);
    String s = null;
    String suffix;
    suffix = this.setTypeIdString(objAttribute.type, objAttribute.size);
    s = this.fullname + "." + objAttribute.name + suffix;
    objAttribute.fullName = s;
    Logg.logg("XttRefObj:  Name " + s, 6);
    return objAttribute;
  }
Ejemplo n.º 3
0
 /**
  * Description of the Method
  *
  * @param animationOnly Description of the Parameter
  */
 public void dynamicUpdate(boolean animationOnly) {
   if (animationOnly) {
     Logg.logg("XttRefObj: animationOnly", 6);
     return;
   }
   this.setObjectAttributeValue(objAttribute);
 }
Ejemplo n.º 4
0
 public void run() {
   try {
     HttpURLConnection httpConnection = (HttpURLConnection) new URL(this.url).openConnection();
     httpConnection.setRequestMethod("GET");
     httpConnection.setRequestProperty(
         "RANGE", "bytes=" + this.offset + "-" + (this.offset + this.length - 1));
     Logg.out("RANGE bytes=" + this.offset + "-" + (this.offset + this.length - 1));
     BufferedInputStream bis = new BufferedInputStream(httpConnection.getInputStream());
     byte[] buff = new byte[1024];
     int bytesRead;
     File newFile = new File(fileName);
     RandomAccessFile raf = new RandomAccessFile(newFile, "rw");
     while ((bytesRead = bis.read(buff, 0, buff.length)) != -1) {
       raf.seek(this.offset);
       raf.write(buff, 0, bytesRead);
       this.offset = this.offset + bytesRead;
       downloadedLength += bytesRead;
     }
     raf.close();
     bis.close();
     isDownloadCompleted = true;
     httpConnection.disconnect();
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
   if (downListener != null && getDownloadRate() - oldRate >= 1) {
     oldRate = getDownloadRate();
     downListener.onCompleteRateChanged(getDownloadRate());
   }
   if (isAllDownLoadCompleted() && downListener != null) {
     downListener.onDownloadCompleted(targetFile);
   }
 }
Ejemplo n.º 5
0
 /**
  * @param url 下载文件地址
  * @param fileName 另存文件名
  * @param offset 本线程下载偏移量
  * @param length 本线程下载长度
  */
 protected DownloadThread(String url, String file, long offset, long length) {
   this.url = url;
   this.fileName = file;
   this.offset = offset;
   this.length = length;
   Logg.out("偏移量=" + offset + ";字节数=" + length);
 }
Ejemplo n.º 6
0
  /**
   * 计算文件大小, 并开启线程下载
   *
   * @param path
   * @param targetFile
   */
  private void doDownload(String path, String targetFile) {
    try {
      HttpURLConnection httpConnection = (HttpURLConnection) new URL(path).openConnection();
      httpConnection.setRequestMethod("HEAD");
      int responseCode = httpConnection.getResponseCode();
      if (responseCode >= 400) {
        Logg.out("Web服务器响应错误!");
        return;
      }
      String sHeader;
      for (int i = 1; ; i++) {
        sHeader = httpConnection.getHeaderFieldKey(i);
        if (sHeader != null && sHeader.equals("Content-Length")) {
          Logg.out("文件大小ContentLength:" + httpConnection.getContentLength());
          fileSize = Long.parseLong(httpConnection.getHeaderField(sHeader));
          break;
        }
      }
      httpConnection.disconnect();

      // 生成文件
      File newFile = new File(targetFile);
      RandomAccessFile raf = new RandomAccessFile(newFile, "rw");
      raf.setLength(fileSize);
      raf.close();

      // 计算需要多少个线程,并开启线程下载
      threadCount = (int) (fileSize / unitSize);

      Logg.out("共启动 " + (fileSize % unitSize == 0 ? threadCount : threadCount + 1) + " 个线程");

      if (fileSize > 20 * 1024 * 1000) { // 如果文件远大于20M, 建议使用单线程下载
        new SingleDownloadThread().start();
      } else {
        long offset = 0;
        if (fileSize <= unitSize) { // 如果远程文件尺寸小于等于unitSize
          downloadThreads = new DownloadThread[1];
          downloadThreads[0] = new DownloadThread(path, targetFile, offset, fileSize);
          downloadThreads[0].start();
        } else { // 如果远程文件尺寸大于unitSize
          if (fileSize % unitSize != 0) {
            downloadThreads = new DownloadThread[threadCount + 1];
          } else {
            downloadThreads = new DownloadThread[threadCount];
          }
          for (int i = 0; i < threadCount; i++) {
            downloadThreads[i] = new DownloadThread(path, targetFile, offset, unitSize);
            downloadThreads[i].start();
            offset = offset + unitSize;
          }
          if (fileSize % unitSize != 0) { // 如果不能整除,则需要再创建一个线程下载剩余字节
            downloadThreads[threadCount] =
                new DownloadThread(path, targetFile, offset, fileSize - unitSize * threadCount);
            downloadThreads[threadCount].start();
          }
        }
      }
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 7
0
    @Override
    public void run() {
      try {
        URL url = new URL(path);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(5 * 1000);
        connection.setRequestMethod("GET");
        connection.setRequestProperty(
            "Accept",
            "image/gif, image/jpeg, image/pjpeg, application/x-shockwave-flash,"
                + " application/xaml+xml, application/vnd.ms-xpsdocument,"
                + " application/x-ms-xbap, application/x-ms-app lication, "
                + "application/cnd.ms- excel, application/vnd.ms-powerpoint, "
                + "application/msword, */*");
        connection.setRequestProperty("Accept-Language", "zh_CN");
        connection.setRequestProperty("Charset", "UTF-8");
        connection.setRequestProperty(
            "User-Agent",
            "Mozilla/4.0(compatible; MSIE 7.0; Windows NT 5.2; "
                + "Trident/4.0; . NET CTR 1.1.4322; .NET CLR 2.0.50727; "
                + ".NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; "
                + ".NET CLR 3.5.30729)");
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.connect();
        InputStream inputStream = connection.getInputStream();

        // 设置文件的长度
        // 生成文件
        File newFile = new File(targetFile);
        RandomAccessFile raf = new RandomAccessFile(newFile, "rw");
        raf.setLength(fileSize);
        for (long i = 0; i < fileSize; i++) {
          raf.seek(i);
          raf.write(0);
        }
        raf.close();

        OutputStream outputStream = new FileOutputStream(targetFile);
        long fileSize = connection.getContentLength();
        Logg.out("fileSize=" + connection.getContentLength());

        byte[] buffer = new byte[1024];
        int hasRead = -1;
        while ((hasRead = inputStream.read(buffer, 0, buffer.length)) != -1) {
          outputStream.write(buffer, 0, hasRead);
          outputStream.flush();
          length += hasRead;
          int rate = (int) ((length * 100) / fileSize);
          if (downListener != null && rate - oldRate >= 1) {
            oldRate = rate;
            downListener.onCompleteRateChanged(rate);
          }
        }
        inputStream.close();
        outputStream.close();
        connection.disconnect();
        if (downListener != null) {
          downListener.onDownloadCompleted(targetFile);
        }
      } catch (MalformedURLException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
public class Reporter {
  private File file = null;
  private final Logger log = Logg.createLogger();

  public Reporter() {
    String datetimeString = new SimpleDateFormat("MM-dd-yyyy_hh.mm.ss").format(new Date());
    String fileName = ("report" + "-" + datetimeString + ".html");
    log.info("Reporting file name:" + fileName);
    file = new File("./reports/" + fileName);
  }

  public void generateReport() {
    FileWriter fstream = null;
    try {
      log.info("Generating static part of the report");
      file.createNewFile();
      fstream = new FileWriter(file);

      BufferedWriter out = new BufferedWriter(fstream);

      out.write("<html>");
      out.write("<head>");
      out.write("</head>");
      out.write("<body>");
      out.write("<h1 align=center>My Test Report</h1>");
      out.write("<br>");

      /** Creating tables in HTML for Test Status */
      // out.write("<table align=center id=customers border=1 width=100%>");
      out.write("<table cellspacing=0 cellpadding=4 border=2 bordercolor=#224466 width=100%>");
      out.write("<tr>");
      out.write("<th width=5%>Sr No</th>");
      out.write("<th width=15%>Module</th>");
      out.write("<th>Test Case ID</th>");
      out.write("<th>Test Name and Steps</th>");
      out.write("<th>Status</th>");
      out.write("<th>Comments</th>");
      out.write("</tr>");
      out.write("<tr>");
      out.write("</tr>");
      out.flush();
      out.close();
      log.info("Generated static part of the report");
    } catch (IOException e) {
      // fstream.close();
    }
  }

  public void sendStatusToReport(
      int SR_NO, String Module, String TC_ID, String TestName, String Status, String Comments) {
    FileWriter fstream = null;
    try {
      fstream = new FileWriter(file, true);
      BufferedWriter out = new BufferedWriter(fstream);
      out.write("<tr>");
      out.write("<td align=\"center\">" + SR_NO + "</b></td>");
      out.write("<td align=\"center\">" + Module + "</b></td>");
      out.write("<td align=\"center\">" + TC_ID + "</b></td>");
      out.write("<td>" + TestName + "</b></td>");
      out.write("<td align=\"center\">" + Status + "</b></td>");
      out.write("<td>" + Comments + "</b></td>");
      out.write("</tr>");
      out.flush();
      out.close();
    } catch (IOException e) {
      // fstream.close();
    }
  }
}
Ejemplo n.º 9
0
public class Reporter {
  private static File file = null;
  private static final Logger log = Logg.createLogger();
  private static String datetimeString;

  static {
    datetimeString = new SimpleDateFormat("MM-dd-yyyy_hh.mm.ss").format(new Date());
    String fileName = ("report" + "-" + datetimeString + ".html");
    log.info(Utilities.getCurrentThreadId() + "Reporting file name:" + fileName);
    file = new File("./reports/" + fileName);
    FileWriter fstream = null;
    try {
      log.info(Utilities.getCurrentThreadId() + "Generating static part of the customized report");
      file.createNewFile();
      fstream = new FileWriter(file);

      BufferedWriter out = new BufferedWriter(fstream);

      out.write("<html>");
      out.write("<head>");
      out.write("</head>");
      out.write("<body>");
      out.write("<h1 align=center>Health Care First</h1>");
      out.write("<br>");

      /** Creating tables in HTML for Test Status */
      // out.write("<table align=center id=customers border=1 width=100%>");
      out.write("<table cellspacing=0 cellpadding=4 border=2 bordercolor=#224466 width=100%>");
      out.write("<tr>");
      out.write("<th width=15%>Module</th>");
      out.write("<th>Test Case ID</th>");
      out.write("<th>Test Name and Steps</th>");
      out.write("<th>Status</th>");
      out.write("<th>Comments</th>");
      out.write("</tr>");
      out.write("<tr>");
      out.write("</tr>");
      out.flush();
      out.close();
      log.info(Utilities.getCurrentThreadId() + "Generated static part of the report");
    } catch (IOException e) {
      // fstream.close();
    }
  }

  public static void sendStatusToReport(
      String Module, String TC_ID, String TestName, String Status, String Comments) {
    FileWriter fstream = null;
    try {
      fstream = new FileWriter(file, true);
      BufferedWriter out = new BufferedWriter(fstream);
      out.write("<tr>");
      out.write("<td align=\"center\">" + Module + "</b></td>");
      out.write("<td align=\"center\">" + TC_ID + "</b></td>");
      out.write("<td>" + TestName + "</b></td>");
      out.write("<td align=\"center\">" + Status + "</b></td>");
      out.write("<td>" + Comments + "</b></td>");
      out.write("</tr>");
      out.flush();
      out.close();
    } catch (IOException e) {
      // fstream.close();
    }
  }

  public static void sendFinalCountToReport(String total, String pass, String fail) {
    FileWriter fstream = null;
    try {
      fstream = new FileWriter(file, true);
      BufferedWriter out = new BufferedWriter(fstream);
      out.write("<table cellspacing=0 cellpadding=4 border=2 bordercolor=#224466 width=25%>");
      out.write("<tr>");
      out.write("<th width=5%>Total</th>");
      out.write("<th width=5%>Pass</th>");
      out.write("<th width=5%>Fail</th>");
      out.write("</tr>");
      out.write("<tr>");
      out.write("<td align=\"center\">" + total + "</b></td>");
      out.write("<td align=\"center\">" + pass + "</b></td>");
      out.write("<td align=\"center\">" + fail + "</b></td>");
      out.write("</tr>");
      out.flush();
      out.close();
    } catch (IOException e) {
      // fstream.close();
    }
  }
}