Esempio n. 1
0
 public String getGetResult() {
   String webUrl = url;
   Collection<Parameter> c = parametersMap.values();
   Iterator<Parameter> it = c.iterator();
   for (; it.hasNext(); ) {
     if (webUrl.indexOf("?") == -1) webUrl += "?";
     else webUrl += "&";
     Parameter parameter = it.next();
     webUrl += parameter.getKey() + "=" + parameter.getValue();
   }
   String result = HttpClientUtil.GetUrlContent(url, encoding);
   DateUtils.PrintTimeGap(webUrl, start, new Date());
   return result;
 }
Esempio n. 2
0
  public String getPostResult() {
    String webUrl = url;
    List<Parameter> parameters = new ArrayList<Parameter>();

    Collection<Parameter> c = parametersMap.values();
    Iterator<Parameter> it = c.iterator();
    for (; it.hasNext(); ) {
      Parameter parameter = it.next();
      parameters.add(parameter);
    }
    System.out.println("JsonUtil = " + JsonUtil.Object2Json(parameters));
    String result = HttpClientUtil.PostUrlContent(url, parameters, encoding);

    String log = DateUtils.PrintTimeGap(webUrl, start, new Date());
    System.out.println(log);
    return result;
  }
Esempio n. 3
0
  /**
   * 写入图片至文件夹中
   *
   * @param 从Excel中读取的图片对象
   * @return 文件存入成功的完整路径
   */
  public static String writeImageToFile(PictureData pictureData, String fileName) {
    if (null != pictureData) {
      // 数据流
      byte[] byteData = pictureData.getData();

      // 文件后辍
      String ext = pictureData.suggestFileExtension();

      FileOutputStream out = null;
      try {
        // 按日期命名文件夹2014-09-02
        String pathDate = DateUtils.getNow(DateUtils.SIMPLE_DEFAULT_FORMAT);

        // 获取当前工程子目录
        String webPath = ExcelFileUtils.getExcelModelPath(FILE_TEMP_DIR);

        // 判断路径是否存在,存在则直接返回
        String path = mkdir(webPath, pathDate);

        // 存储的文件名
        String tmpFileName =
            "/" + fileName + UNDER_LINE + (System.currentTimeMillis()) + POINT + ext;
        File file = null;
        if (StringUtils.isNotEmpty(path)) {
          file = new File(path + tmpFileName);
          out = new FileOutputStream(file);
          out.write(byteData);
        }

        return null == file ? null : FILE_TEMP_DIR + pathDate + tmpFileName;

      } catch (Exception e) {
        LOG.error(e.getMessage());
      } finally {
        if (null != out) {
          try {
            out.close();
          } catch (IOException e) {
            LOG.error(e.getMessage());
          }
        }
      }
    }
    return null;
  }