コード例 #1
0
ファイル: ImageLoader.java プロジェクト: kavi707/FKF-App
  private Bitmap getBitmap(String url) {
    File f = fileCache.getFile(url);

    // from SD cache
    Bitmap b = decodeFile(f);
    if (b != null) return b;

    // from web
    try {
      Bitmap bitmap = null;
      URL imageUrl = new URL(url);
      HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
      conn.setConnectTimeout(30000);
      conn.setReadTimeout(30000);
      conn.setInstanceFollowRedirects(true);
      InputStream is = conn.getInputStream();
      OutputStream os = new FileOutputStream(f);
      Utils.CopyStream(is, os);
      os.close();
      bitmap = decodeFile(f);
      return bitmap;
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }
コード例 #2
0
  /**
   * 执行网络请求加载图片
   *
   * @param url
   * @param requiredSize
   * @return
   */
  private Bitmap getBitmap(String url, int requiredSize, PhotoToLoad photoToLoad) {
    File f = fileCache.getFile(url);
    // 先从文件缓存中查找是否有
    Bitmap b = decodeFile(f, requiredSize);
    if (b != null) return b;

    // 最后从指定的url中下载图片
    try {
      Bitmap bitmap = null;
      URL imageUrl = new URL(url);
      HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
      conn.setConnectTimeout(30000);
      conn.setReadTimeout(30000);
      conn.setInstanceFollowRedirects(true);
      InputStream is = conn.getInputStream();
      OutputStream os = new FileOutputStream(f);
      //            CopyStream(is, os, conn.getContentLength(), photoToLoad);

      photoToLoad.totalSize = conn.getContentLength();
      int buffer_size = 1024;
      byte[] bytes = new byte[buffer_size];
      for (; ; ) {
        int count = is.read(bytes, 0, buffer_size);

        if (count == -1) {
          break;
        }
        os.write(bytes, 0, count);

        if (null != photoToLoad.onImageLoaderListener) { // 如果设置了图片加载监听,则回调
          Message msg = rHandler.obtainMessage();
          photoToLoad.currentSize += count;
          msg.arg1 = IMAGE_LOADER_PROCESS;
          msg.obj = photoToLoad;
          rHandler.sendMessage(msg);
        }
      }

      is.close();
      os.close();
      bitmap = decodeFile(f, requiredSize);
      return bitmap;
    } catch (Exception ex) {
      Logger.w(TAG, ex);
      return null;
    }
  }
コード例 #3
0
 public void clearFileCache() {
   fileCache.clear();
 }
コード例 #4
0
 /** 清空文件缓存或内存缓存 */
 public void clearCache() {
   memoryCache.clear();
   fileCache.clear();
 }
コード例 #5
0
ファイル: WebChartJSPTag.java プロジェクト: no2key/WebChart
  public int doEndTag() throws JspException {
    try {
      HttpServletRequest request = (HttpServletRequest) (pageContext.getRequest());
      String file_ext = pageContext.getServletContext().getInitParameter("FileExtention");
      String dbfs_ext = pageContext.getServletContext().getInitParameter("DatabaseExtention");
      String db_name = pageContext.getServletContext().getInitParameter("DatabaseName");
      String db_query = pageContext.getServletContext().getInitParameter("DatabaseQuery");
      JspWriter out = pageContext.getOut();

      int KEEP_CACHE_TIME = 300;
      long current_time = System.currentTimeMillis();

      if (pagebody != null || pageurl != null || dbfsurl != null) {
        VariableTable vt = new VariableTable();
        vt.loadContent(FileCache.getFileContent(getPhysicalPath("/global" + file_ext)));
        vt.loadContent(FileCache.getFileContent(getPhysicalPath("default" + file_ext)));
        if (pageurl != null) vt.loadContent(FileCache.getFileContent(getPhysicalPath(pageurl)));
        if (dbfsurl != null) {
          VariableTable dbparam = new VariableTable();
          dbparam.add("path", java.sql.Types.VARCHAR);
          dbparam.setValue("path", dbfsurl);
          String pagebody = TextCache.getTextContent("source::" + dbfsurl);
          if (pagebody == null) {
            try {
              DBPooledConnection dbconn = DBLogicalManager.getPoolConnection(db_name);
              try {
                pagebody = DBOperation.getString(dbconn, db_query, dbparam);
                vt.loadContent(pagebody);
                TextCache.putContent(
                    System.currentTimeMillis(), "source::" + dbfsurl, pagebody, 20);
              } catch (java.sql.SQLException sqle) {
              }
              dbconn.close();
            } catch (java.lang.Exception sqle) {
            }
          } else {
            vt.loadContent(pagebody);
          }
        }
        if (pagebody != null) vt.loadContent(pagebody);
        getEnv(vt);
        vt.add("JSP.TAG", java.sql.Types.VARCHAR);
        vt.setValue("JSP.TAG", "YES");
        vt.add("REQUEST.URL", java.sql.Types.VARCHAR);
        vt.setValue("REQUEST.URL", request.getRequestURI());

        if (vt.exists("WEBCHART.KEEP_CACHE_TIME")) {
          KEEP_CACHE_TIME = vt.getInt("WEBCHART.KEEP_CACHE_TIME", 300);
          if (KEEP_CACHE_TIME < 5) KEEP_CACHE_TIME = 5;
        }
        java.io.File xsl_file = null;
        if (vt.getString("WEBCHART.XSLDOC") != null)
          xsl_file = new java.io.File(getPhysicalPath(vt.getString("WEBCHART.XSLDOC")));
        String cachekey = vt.parseString(vt.getString("WEBCHART.CACHE"));

        String cache_content = null;

        if (cachekey != null && !vt.exists("WEBCHART.FORCECACHE"))
          cache_content = TextCache.getTextContent(cachekey);

        if (cache_content == null) {
          java.io.StringWriter xmlbuf = new java.io.StringWriter();
          writeXMLHeader(xmlbuf, vt);
          xmlbuf.write("<root>\n");
          WebChart2.generateChart(xmlbuf, null, vt, file_ext);
          xmlbuf.write("</root>\n");

          java.io.StringWriter htmlbuf = new java.io.StringWriter();
          if (xsl_file != null && xsl_file.exists())
            BaseServlet.XML2HTML(
                htmlbuf,
                new java.io.StringReader(xmlbuf.toString()),
                new java.io.StringReader(FileCache.getFileContent(xsl_file)),
                FileCache.getFileContent(xsl_file));
          else
            BaseServlet.XML2HTML(
                htmlbuf,
                new java.io.StringReader(xmlbuf.toString()),
                new java.io.StringReader(StaticResource.getTextResource("defaultxsl")),
                StaticResource.getTextResource("defaultxsl"));
          cache_content = htmlbuf.toString();
          out.write(cache_content);
          if (cachekey != null)
            TextCache.putContent(current_time, cachekey, cache_content, KEEP_CACHE_TIME);
        } else {
          out.write(cache_content);
        }
      }
    } catch (IOException ioe) {
      throw new JspException("Error:    " + ioe.getMessage());
    }
    return EVAL_PAGE;
  }