/**
   * @param args
   * @throws IOException
   * @throws FileNotFoundException
   */
  public static void main(String[] args) throws IOException {
    FileUtils.makeDirectory(ConfigConstant.TEMP_VOCABULARY_OUTPUT_DIR);
    // read one by one line from the review tips location and extract the
    // words
    Set<String> vocubalary = new HashSet<>();
    for (String fileNames :
        FileUtils.getAllFiles(ConfigConstant.TEMP_REVIEW_TIPS_ML_TOPIC_DATA_OUT_LOCATIONS)) {

      updateVocabulary(
          FileUtils.getFullPath(
              ConfigConstant.TEMP_REVIEW_TIPS_ML_TOPIC_DATA_OUT_LOCATIONS, fileNames),
          vocubalary);
    }

    // remove all words that appeared very less often
    vocabDist.forEach(
        (word, value) -> {
          if (value <= DEFAULT_WORD_COUNT_ALLOWED) {
            vocubalary.remove(word);
          }
        });

    vocabDist.clear();

    // write the remaining files
    writeToFile(
        new TreeSet<String>(vocubalary),
        ConfigConstant.TEMP_RAW_ORIGINAL_VOCABULRAY_TEXT_LOCATIONS);
  }
示例#2
0
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   switch (requestCode) {
     case TAKE_PICTURE:
       if (Bimp.tempSelectBitmap.size() < 9 && resultCode == RESULT_OK) {
         //                    dataList = new ArrayList<ImageItem>();
         String fileName = String.valueOf(System.currentTimeMillis());
         //                    String a=tempFile.toString();
         //                    System.out.println(a);
         //                    Bitmap bm = (Bitmap) data.getExtras().get("data");
         BitmapFactory.Options opts = new BitmapFactory.Options();
         opts.inJustDecodeBounds = true;
         Bitmap bm = BitmapFactory.decodeFile(tempFile.toString(), opts);
         try {
           File file = FileUtils.saveBitmap(bm, fileName, tempFile.toString());
           ImageItem takePhoto = new ImageItem();
           takePhoto.setImagePath(file.toString());
           takePhoto.setBitmap(bm);
           Bimp.tempSelectBitmap.add(takePhoto);
         } catch (Exception e) {
           Toast.makeText(ReplyPhoto.this, "手机可运行内存不足,照片保存失败,请清理后操作", Toast.LENGTH_SHORT).show();
         }
       }
       break;
   }
 }
示例#3
0
  public void delete(String userIds, String filePath) throws Exception {
    String[] userIdArr = userIds.split(",");
    for (int i = 0; i < userIdArr.length; i++) {
      this.userDao.deleteByPrimaryKey(userIdArr[i]);

      String userFilePath = filePath + "/" + userIdArr[i];
      FileUtils.deleteDirectory(new File(userFilePath));
    }
  }
  private static void writeToFile(Set<String> vocabulary, String tempVocabulrayTextLocations)
      throws IOException {

    FileUtils.writeLinesToFile(vocabulary, tempVocabulrayTextLocations);
  }
示例#5
0
  public JSONObject register(Map map) throws Exception {
    boolean isSuccess = true;
    String errorMsg = "";

    User paramUser = new User();
    BeanUtils.populate(paramUser, map);
    paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd"));
    paramUser.setStatus("1");
    if ((StringUtils.isEmpty(SessionUtils.getUserRole()))
        || ("3".equals(SessionUtils.getUserRole()))) {
      paramUser.setRole("3");
    }

    String userId = map.get("userId").toString();

    String password = map.get("password").toString();

    String repassword = map.get("repassword").toString();

    String verifyCode = map.get("verifyCode").toString();
    String verifyCodeInSession = map.get("verifyCodeInSession").toString();

    if ("1".equals(SessionUtils.getUserRole())) {
      if ((!"2".equals(paramUser.getRole())) && (!"3".equals(paramUser.getRole()))) {
        isSuccess = false;
        errorMsg = "角色设置错误.";
      }
    } else if (!"3".equals(paramUser.getRole())) {
      isSuccess = false;
      errorMsg = "角色设置错误.";
    }

    if (!password.equals(repassword)) {
      isSuccess = false;
      errorMsg = "两次输入的密码不一致.";
    }

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      errorMsg = "验证码错误.";
    }

    List<User> userList = selectByCriteria(new User());
    if (userList != null) {
      for (User user : userList) {
        if (userId.equals(user.getUserId())) {
          isSuccess = false;
          errorMsg = "账号已存在.";
          break;
        }
        if (paramUser.getEmail().equals(user.getEmail())) {
          isSuccess = false;
          errorMsg = "邮箱已被使用.";
          break;
        }
      }
    }

    if (isSuccess) {
      insert(paramUser);

      Map userMetaMap = new HashMap();
      userMetaMap.put("theme", (String) map.get("theme"));
      userMetaMap.put("homePage", (String) map.get("homePage"));
      userMetaMap.put("showTodo", (String) map.get("showTodo"));
      userMetaMap.put("showNote", (String) map.get("showNote"));
      userMetaMap.put("showPicture", (String) map.get("showPicture"));
      userMetaMap.put("showAccount", (String) map.get("showAccount"));
      userMetaMap.put("showFeed", (String) map.get("showFeed"));
      userMetaMap.put("showDocument", (String) map.get("showDocument"));
      if ("3".equals(paramUser.getRole())) userMetaMap.put("showSystem", "off");
      else {
        userMetaMap.put("showSystem", "on");
      }
      this.userMetaService.insert(userId, userMetaMap);

      String uploadFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/document", new String[] {userId}));
      FileUtils.createDirs(uploadFilePath);

      String uploadPicturePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/picture", new String[] {userId}));
      FileUtils.createDirs(uploadPicturePath);

      FileUtils.createDirs(uploadPicturePath + "/" + "thumbnail");

      String feedFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/feed", new String[] {userId}));
      FileUtils.createDirs(feedFilePath);
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", errorMsg);
    return res;
  }
示例#6
0
  public String uploadFile(
      String Url,
      String category_id,
      String username,
      String content,
      String location,
      String xiaoquid) {
    StringBuilder sb2 = new StringBuilder();
    String BOUNDARY = "ARCFormBoundarymmd8a874lsor";
    String PREFIX = "--", LINEND = "\r\n";
    // String MULTIPART_FROM_DATA = "multipart/form-data";
    final String endline = "--" + BOUNDARY + "--\r\n"; // 数据结束标志
    String CHARSET = "UTF-8";
    URL httpurl;
    try {
      httpurl = new URL(Url);
      HttpURLConnection conn = (HttpURLConnection) httpurl.openConnection();

      conn.setDoOutput(true);
      conn.setDoInput(true);
      conn.setUseCaches(false);
      conn.setRequestMethod("POST");
      conn.setRequestProperty("Connection", "Keep-Alive");
      conn.setRequestProperty("Charset", "utf-8");
      conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY);

      DataOutputStream outStream = new DataOutputStream(conn.getOutputStream());
      StringBuilder sb = new StringBuilder();
      sb.append(PREFIX);
      sb.append(BOUNDARY);
      sb.append(LINEND);
      sb.append("Content-Disposition: form-data; name=\"" + "category_id" + "\"" + LINEND);
      sb.append(LINEND);
      sb.append(68);
      sb.append(LINEND);
      sb.append(PREFIX);
      sb.append(BOUNDARY);
      sb.append(LINEND);

      sb.append("Content-Disposition: form-data; name=\"" + "username" + "\"" + LINEND);
      sb.append(LINEND);
      sb.append(username);
      sb.append(LINEND);
      sb.append(PREFIX);
      sb.append(BOUNDARY);
      sb.append(LINEND);
      sb.append("Content-Disposition: form-data; name=\"" + "xiaoquid" + "\"" + LINEND);
      sb.append(LINEND);
      sb.append(xiaoquid);
      sb.append(LINEND);
      sb.append(PREFIX);
      sb.append(BOUNDARY);
      sb.append(LINEND);

      sb.append("Content-Disposition: form-data; name=\"" + "content" + "\"" + LINEND);
      sb.append(LINEND);
      sb.append(content);
      sb.append(LINEND);
      sb.append(PREFIX);
      sb.append(BOUNDARY);
      sb.append(LINEND);

      sb.append("Content-Disposition: form-data; name=\"" + "location" + "\"" + LINEND);
      sb.append(LINEND);
      sb.append(location);
      sb.append(LINEND);

      outStream.write(sb.toString().getBytes());

      for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
        String filePath = Bimp.tempSelectBitmap.get(i).getImagePath();
        String fileName = String.valueOf(System.currentTimeMillis());
        Bitmap bm = BitmapFactory.decodeFile(filePath.toString());
        File file = FileUtils.saveBitmap(bm, fileName, filePath.toString());
        filePath = file.toString();
        String name = "imgFile" + i;
        StringBuilder sb1 = new StringBuilder();
        sb1.append("--");
        sb1.append(BOUNDARY);
        sb1.append("\r\n");
        sb1.append(
            "Content-Disposition: form-data; name=\""
                + name
                + "\"; filename=\""
                + "123.jpg"
                + "\""
                + LINEND);
        sb1.append("Content-Type: image/jpg; charset=" + CHARSET + LINEND);
        sb1.append(LINEND);
        outStream.write(sb1.toString().getBytes());

        InputStream is = new FileInputStream(filePath);
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = is.read(buffer)) != -1) {
          outStream.write(buffer, 0, len);
        }
        is.close();
        outStream.write(LINEND.getBytes());
      }
      outStream.write(endline.getBytes());
      byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes();
      outStream.write(end_data);
      outStream.flush();
      int res = conn.getResponseCode();
      InputStream in = null;
      if (res == 201 || res == 200) {
        in = conn.getInputStream();
        int ch;
        while ((ch = in.read()) != -1) {
          sb2.append((char) ch);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      String str = "失败";
      return str;
    }
    return sb2.toString();
  }