コード例 #1
0
ファイル: MimeLookUp.java プロジェクト: mohan82/RPMComparator
 public static Multimap<String, String> populateMimeMap(Multimap<String, String> mimeFileMap) {
   MimeLineProcessor mimeLineProcessor = new MimeLineProcessor(mimeFileMap);
   try {
     return Resources.readLines(
         Resources.getResource(MIME_TYPE_FILE_PATH), Charset.defaultCharset(), mimeLineProcessor);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #2
0
 private static String readLines(final Class<?> contextClass, final String resourceName) {
   try {
     List<String> readLines =
         Resources.readLines(
             Resources.getResource(contextClass, resourceName), Charset.defaultCharset());
     return Joiner.on("\n").join(readLines);
   } catch (IOException e) {
     return APP_NAME;
   }
 }
コード例 #3
0
 private void addIgnoreWords() throws IOException {
   hunspellDict.addWord(SpellingCheckRule.LANGUAGETOOL);
   hunspellDict.addWord(SpellingCheckRule.LANGUAGETOOL_FX);
   URL ignoreUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(getIgnoreFileName());
   List<String> ignoreLines = Resources.readLines(ignoreUrl, Charsets.UTF_8);
   for (String ignoreLine : ignoreLines) {
     if (!ignoreLine.startsWith("#")) {
       hunspellDict.addWord(ignoreLine);
     }
   }
 }
コード例 #4
0
 private static String readLines(final Class<?> contextClass, final String resourceName) {
   try {
     List<String> readLines =
         Resources.readLines(
             Resources.getResource(contextClass, resourceName), Charset.defaultCharset());
     final String aboutText = Joiner.on("\n").join(readLines);
     return aboutText;
   } catch (IOException e) {
     return "This is a simple app";
   }
 }
 private static String readLines(final String resourceName) {
   try {
     List<String> readLines =
         Resources.readLines(
             Resources.getResource(QuickStartApplication.class, resourceName),
             Charset.defaultCharset());
     final String aboutText = Joiner.on("\n").join(readLines);
     return aboutText;
   } catch (IOException e) {
     return "This is Quick Start";
   }
 }
コード例 #6
0
 /** 按行读取task3.properties文件 自然序不能从Properties类中取得,Properties类从reader读取资源文件对文件中的Entry按key排序 */
 public List<String> getNatureOrder(String propertiesURL) {
   List<String> natureOrderList = new ArrayList<String>();
   try {
     URL url = new URL(propertiesURL);
     List<String> content = Resources.readLines(url, Charset.forName("UTF-8"));
     for (String tempStr : content) {
       natureOrderList.add(tempStr.replaceAll("\\d+", "").trim());
     }
   } catch (IOException e) {
     logger.warn("properties file read error", e);
   }
   return natureOrderList;
 }
コード例 #7
0
  private void readMapFile(String rulesFile) throws IOException {
    File file = new File(rulesFile);
    URL rulesResource;
    if (file.exists()) {
      rulesResource = file.toURI().toURL();
    } else {
      rulesResource = Resources.getResource(rulesFile);
    }
    Resources.readLines(
        rulesResource,
        Charsets.UTF_8,
        new LineProcessor<Void>() {
          @Override
          public Void getResult() {
            return null;
          }

          @Override
          public boolean processLine(String input) throws IOException {
            String line = Iterables.getFirst(Splitter.on('#').limit(2).split(input), "").trim();
            if (line.length() == 0) {
              return true;
            }
            List<String> parts = Lists.newArrayList(Splitter.on(" ").trimResults().split(line));
            if (parts.size() > 2) {
              throw new RuntimeException("Invalid config file line " + input);
            }
            Modifier m = new Modifier();
            m.setTargetAccess(parts.get(0));
            List<String> descriptor =
                Lists.newArrayList(Splitter.on(".").trimResults().split(parts.get(1)));
            if (descriptor.size() == 1) {
              m.modifyClassVisibility = true;
            } else {
              String nameReference = descriptor.get(1);
              int parenIdx = nameReference.indexOf('(');
              if (parenIdx > 0) {
                m.desc = nameReference.substring(parenIdx);
                m.name = nameReference.substring(0, parenIdx);
              } else {
                m.name = nameReference;
              }
            }
            modifiers.put(descriptor.get(0).replace('/', '.'), m);
            return true;
          }
        });
    System.out.printf(
        "Loaded %d rules from AccessTransformer config file %s\n", modifiers.size(), rulesFile);
  }
コード例 #8
0
  @Test
  public void testScan() throws Exception {

    AbstractRedisDialect dialect = RedisTestHelper.getDialect(getProvider());
    assumeTrue(dialect.isClusterMode());

    // pre-computed key file.
    URL resource = Resources.getResource("redis-cluster-slothashes.txt");
    List<String> lines = Resources.readLines(resource, StandardCharsets.ISO_8859_1);

    OgmSession session = openSession();
    session.getTransaction().begin();

    // given
    int availableKeys = 0;
    for (String line : lines) {

      if (line.startsWith("#") || line.trim().isEmpty()) {
        continue;
      }

      String key = line.substring(0, line.indexOf(' ')).trim();

      Band record = new Band(key, key);
      session.persist(record);
      availableKeys++;
    }
    session.getTransaction().commit();

    final AtomicInteger counter = new AtomicInteger();

    dialect.forEachTuple(
        new ModelConsumer() {
          @Override
          public void consume(TuplesSupplier supplier) {
            try (ClosableIterator<Tuple> closableIterator = supplier.get(null)) {
              while (closableIterator.hasNext()) {
                counter.incrementAndGet();
              }
            }
          }
        },
        null,
        new DefaultEntityKeyMetadata("Band", new String[] {"id"}));

    assertEquals(availableKeys, counter.get());
  }
コード例 #9
0
  /**
   * 执行wc命令 wc -l 1.txt; ***|wc -l;
   *
   * @return
   * @throws Exception
   */
  public Integer execute() throws Exception {
    List<String> tempList = Command.resultList;
    Integer lineNum = 0;
    if (getOptions().size() == 0) {
      logger.info("please input the option");
      System.exit(0);
    } else if (getOptions().size() == 1) {
      // wc -l 的情况
      if (getOptions().get(0).equals("-l")) {
        if (getArgs().size() == 0) {
          if (tempList.size() == 0) {
            logger.warn("{} {}无效命令", getCommandName(), getOptions());
            throw new IllegalArgumentException(getCommandName().concat(getOptions().toString()));
          } else {
            lineNum = tempList.size();
          }
        } else if (getArgs().size() == 1) { // wc -l 1.txt
          URL url = Resources.getResource(getArgs().get(0));
          lineNum =
              Resources.readLines(
                  url,
                  Charset.forName("UTF-8"),
                  new LineProcessor<Integer>() {
                    Integer lines = 0;

                    public boolean processLine(String line) throws IOException {
                      lines++;
                      return true;
                    }

                    public Integer getResult() {
                      return lines;
                    }
                  });
        }
      } else {
        logger.warn("{} {}无效命令", getCommandName(), getOptions());
        throw new IllegalArgumentException(getCommandName().concat(getOptions().toString()));
      }
    }

    logger.debug("{}", lineNum);
    return lineNum;
  }
コード例 #10
0
ファイル: Utils.java プロジェクト: Enigmachine/btcjwork2
 /**
  * Reads and joins together with LF char (\n) all the lines from given file. It's assumed that
  * file is in UTF-8.
  */
 public static String getResourceAsString(URL url) throws IOException {
   List<String> lines = Resources.readLines(url, Charsets.UTF_8);
   return Joiner.on('\n').join(lines);
 }