Exemple #1
0
  @Override
  public void run() {
    // TODO Auto-generated method stub

    final String[] crawlerArgs = {
      searchwords, htmlpath, txtpath, xmlpath, ippath + "/plainIPs.txt", pagecount
    };

    int ifCrawlFlag = 0;

    if (ifCrawlFlag == 0) {
      try {
        Crawler c = new Crawler();
        c.excute(crawlerArgs, dir);
      } catch (IOException | URISyntaxException | InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    //
    System.out.println("now begin to classify the file:");
    emoClassifyUnity emo = new emoClassifyUnity();
    List<String[]> list2 = emo.emoClassify("./mycraw/" + dir + "/" + searchwords + ".xml");
    // save the  topic

    JdbcUtils db = new JdbcUtils();
    db.getConnection();
    String sql = "insert into topic(topic ,topicdescription,pdate) values (?,?,?)";
    String deltopicid = "delete from topic where topic=?";

    //
    List<Object> paramsdel = new ArrayList<Object>();
    paramsdel.add(topiclist[0]);
    try {
      db.updateBypreparedPreparedStatement(deltopicid, paramsdel);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //
    System.out.println(topiclist[0] + "---->>>" + topiclist[1]);
    List<Object> params = new ArrayList<Object>();
    params.add(topiclist[0]);
    params.add(topiclist[1]);
    java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
    params.add(currentDate);
    try {
      db.updateBypreparedPreparedStatement(sql, params);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    db.releasecon();
    //
    savetomysql(gettopicid(searchwords), list2);
    //
    String info = topiclist[0] + ":结束下载,分词,结果保存在数据库内";
    logwrite.write("./timerlog.txt", info);
  }
 public void updateChoices(boolean reportError, Form<?> form) {
   final String repoUriStr = repositoryUriModel.getObject();
   if (REPOSITORY.sample != null && REPOSITORY.sample.equals(repoUriStr)) {
     return;
   }
   List<String> branchNames = new ArrayList<>();
   if (repoUriStr != null) {
     try {
       RepositoryManager manager = this.manager.get();
       URI repoURI = new URI(repoUriStr);
       RepositoryResolver resolver = RepositoryResolver.lookup(repoURI);
       String repoName = resolver.getName(repoURI);
       RepositoryInfo repoInfo = manager.getByRepoName(repoName);
       String repoId = repoInfo.getId();
       List<Ref> branchRefs = manager.listBranches(repoId);
       for (Ref branch : branchRefs) {
         branchNames.add(branch.localName());
       }
     } catch (IOException | URISyntaxException e) {
       if (reportError) {
         form.error("Could not list branches: " + e.getMessage());
       }
       branchNames = new ArrayList<String>();
     }
     String current = (String) choice.getModelObject();
     if (current != null && !branchNames.contains(current)) {
       branchNames.add(0, current);
     }
   }
   choice.setChoices(branchNames);
 }
 private void onDownload() {
   try {
     Desktop.getDesktop().browse(new URI(downloadURL));
   } catch (IOException | URISyntaxException e) {
     e.printStackTrace();
   }
   dispose();
 }
 public String getJavaagentLocation() throws CoreException {
   URL entry = getBundle().getEntry("com.ifedorenko.m2e.sourcelookup.javaagent.jar");
   try {
     return new File(FileLocator.toFileURL(entry).toURI()).getCanonicalPath();
   } catch (IOException | URISyntaxException e) {
     throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e));
   }
 }
Exemple #5
0
 /**
  * Gets the current version of the Benchmark from the benchmark.properties file.
  *
  * @return The version # (as a String). An empty string if its not defined in that file.
  * @throws Exception
  */
 public String getbenchmarkVersion() { // throws Exception {
   Properties benchMprops = new Properties();
   try {
     File propsFile =
         new File(this.getClass().getClassLoader().getResource(VERSION_FILE).toURI().getPath());
     benchMprops.load(new FileInputStream(propsFile));
     String v = benchMprops.getProperty("benchmark-version");
     if (v == null) return "";
     return v;
   } catch (IOException | URISyntaxException e) {
     System.out.println("Can't load version # from properties file.");
     e.printStackTrace();
     return "";
   }
 }
 /**
  * Sends an friend request to an other user. An Riot API key is required for this.
  *
  * @param name The name of the Friend you want to add (case insensitive)
  * @param friendGroup The FriendGroup you want to put this user in.
  * @return True if succesful otherwise false.
  */
 public boolean addFriendByName(String name, FriendGroup friendGroup) {
   if (getRiotApi() != null) {
     try {
       final StringBuilder buf = new StringBuilder();
       buf.append("sum");
       buf.append(getRiotApi().getSummonerId(name));
       buf.append("@pvp.net");
       addFriendById(buf.toString(), name, friendGroup);
       return true;
     } catch (IOException | URISyntaxException e) {
       e.printStackTrace();
       return false;
     }
   }
   return false;
 }
 private static Boolean isInMemory() {
   if (inMemory == null) {
     Properties properties = new Properties();
     URL resource = PropertiesReader.class.getClassLoader().getResource("properties.properties");
     if (resource != null) {
       try (InputStream input = new FileInputStream(Paths.get(resource.toURI()).toFile())) {
         properties.load(input);
         String property = properties.getProperty("inMemory");
         URL = properties.getProperty("URL");
         LOGIN = properties.getProperty("LOGIN");
         PASSWORD = properties.getProperty("PASSWORD");
         DRIVER_CLASS = properties.getProperty("DRIVER_CLASS");
         if (property != null) {
           inMemory = Boolean.parseBoolean(property);
         }
         System.out.println(inMemory);
       } catch (IOException | URISyntaxException e) {
         e.printStackTrace();
       }
     }
   }
   return (inMemory != null && inMemory);
 }
  private void processGet(ChannelHandlerContext context, FullHttpRequest request) {
    try {
      File file = getRequestedFile(request.getUri());

      RandomAccessFile raf = new RandomAccessFile(file, "r");
      long fileLength = raf.length();

      HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
      HttpHeaders.setContentLength(response, fileLength);
      setContentTypeHeader(response, file);

      context.write(response);

      context.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength));

      // Write the end marker.
      ChannelFuture future = context.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
      future.addListener(ChannelFutureListener.CLOSE);

    } catch (IOException | URISyntaxException e) {
      context.writeAndFlush(getBadRequest(e.getMessage()));
    }
  }
Exemple #9
0
  private static void assureKeywordsAreScrapped() {
    if (RASCAL_KEYWORDS.isEmpty()) {
      synchronized (RASCAL_KEYWORDS) {
        if (!RASCAL_KEYWORDS.isEmpty()) {
          return;
        }

        String rascalGrammar = "";
        try (Reader grammarReader =
            URIResolverRegistry.getInstance()
                .getCharacterReader(
                    ValueFactoryFactory.getValueFactory()
                        .sourceLocation("std", "", "/lang/rascal/syntax/Rascal.rsc"))) {
          StringBuilder res = new StringBuilder();
          char[] chunk = new char[8 * 1024];
          int read;
          while ((read = grammarReader.read(chunk, 0, chunk.length)) != -1) {
            res.append(chunk, 0, read);
          }
          rascalGrammar = res.toString();
        } catch (IOException | URISyntaxException e) {
          e.printStackTrace();
        }
        if (!rascalGrammar.isEmpty()) {
          /*
           * keyword RascalKeywords
           * = "o"
           * | "syntax"
           * | "keyword"
           * | "lexical"
           * ...
           * ;
           */
          Pattern findKeywordSection =
              Pattern.compile(
                  "^\\s*keyword([^=]|\\s)*=(?<keywords>([^;]|\\s)*);", Pattern.MULTILINE);
          Matcher m = findKeywordSection.matcher(rascalGrammar);
          if (m.find()) {
            String keywords = "|" + m.group("keywords");
            Pattern keywordEntry = Pattern.compile("\\s*[|]\\s*[\"](?<keyword>[^\"]*)[\"]");
            m = keywordEntry.matcher(keywords);
            while (m.find()) {
              RASCAL_KEYWORDS.add(m.group("keyword"));
            }
          }
          /*
           * syntax BasicType
          = \value: "value"
          | \loc: "loc"
          | \node: "node"
           */
          Pattern findBasicTypeSection =
              Pattern.compile(
                  "^\\s*syntax\\s*BasicType([^=]|\\s)*=(?<keywords>([^;]|\\s)*);",
                  Pattern.MULTILINE);
          m = findBasicTypeSection.matcher(rascalGrammar);
          if (m.find()) {
            String keywords = "|" + m.group("keywords");
            Pattern keywordEntry = Pattern.compile("\\s*[|][^:]*:\\s*[\"](?<keyword>[^\"]*)[\"]");
            m = keywordEntry.matcher(keywords);
            while (m.find()) {
              RASCAL_KEYWORDS.add(m.group("keyword"));
            }
          }
        }
        if (RASCAL_KEYWORDS.isEmpty()) {
          RASCAL_KEYWORDS.add("syntax");
        }
      }
    }
  }