com.google.common.io.Files#readLines ( )源码实例Demo

下面列出了com.google.common.io.Files#readLines ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gecco   文件: FileProxys.java
public FileProxys() {
	try {
		proxys = new ConcurrentHashMap<String, Proxy>();
		proxyQueue = new ConcurrentLinkedQueue<Proxy>();
		URL url = Resources.getResource("proxys");
		File file = new File(url.getPath());
		List<String> lines = Files.readLines(file, Charsets.UTF_8);
		if(lines.size() > 0) {
			for(String line : lines) {
				line = line.trim();
				if(line.startsWith("#")) {
					continue;
				}
				String[] hostPort = line.split(":");
				if(hostPort.length == 2) {
					String host = hostPort[0];
					int port = NumberUtils.toInt(hostPort[1], 80);
					addProxy(host, port);
				}
			}
		}
	} catch(Exception ex) {
		log.info("proxys not load");
	}
}
 
源代码2 项目: bromium   文件: DslStepsDumperTest.java
@Test
public void correctlyHandlesNoAliases() throws IOException {
    Map<String, String> firstStep = new HashMap<>();
    firstStep.put(EVENT, clickLoginButtonActionName);

    TestScenarioSteps testScenarioSteps = new TestScenarioSteps();
    testScenarioSteps.add(firstStep);

    Map<String, ApplicationActionConfiguration> actionConfigurationMap = createNoAliasesMockConfiguration();

    StepsDumper stepsDumper = new DslStepsDumper(actionConfigurationMap);
    stepsDumper.dump(testScenarioSteps, outputFilename);

    List<String> lines = Files.readLines(outputFile, Charsets.UTF_8);
    assertEquals(1, lines.size());
    assertEquals("clickLoginButtonActionName: Click login button ", lines.get(0));
}
 
源代码3 项目: xml-combiner   文件: XmlCombinerTest.java
@Test
public void shouldSupportReadingAndStoringFiles() throws IOException, ParserConfigurationException, SAXException,
		TransformerException {
	// given
	Path input = Paths.get("target/test.in");
	Path output = Paths.get("target/test.out");
	Files.write("<config/>", input.toFile(), StandardCharsets.UTF_8);

	// when
	XmlCombiner combiner = new XmlCombiner();
	combiner.combine(input);
	combiner.buildDocument(output);
	List<String> lines = Files.readLines(output.toFile(), StandardCharsets.UTF_8);

	// then
	assertThat(lines).hasSize(1);
	assertThat(lines.iterator().next()).contains("<config/>");
}
 
源代码4 项目: brooklyn-server   文件: ResourceUtilsTest.java
@Test
public void testWriteStreamToTempFile() throws Exception {
    File tempFileLocal = Os.writeToTempFile(new ByteArrayInputStream("mycontents".getBytes()), "resourceutils-test", ".txt");
    try {
        List<String> lines = Files.readLines(tempFileLocal, Charsets.UTF_8);
        assertEquals(lines, ImmutableList.of("mycontents"));
    } finally {
        tempFileLocal.delete();
    }
}
 
源代码5 项目: bazel   文件: JacocoCoverageRunner.java
/**
 * Returns an immutable list containing all the file paths found in mainFile. It uses the
 * javaRunfilesRoot prefix for every found file to compute its absolute path.
 */
private static ImmutableList<File> getFilesFromFileList(File mainFile, String javaRunfilesRoot)
    throws IOException {
  List<String> metadataFiles = Files.readLines(mainFile, UTF_8);
  ImmutableList.Builder<File> convertedMetadataFiles = new Builder<>();
  for (String metadataFile : metadataFiles) {
    convertedMetadataFiles.add(new File(javaRunfilesRoot + "/" + metadataFile));
  }
  return convertedMetadataFiles.build();
}
 
源代码6 项目: javaide   文件: Project.java
private void extractAospMinSdkVersion() {
    // Is the SDK level specified by a Makefile?
    boolean found = false;
    File makefile = new File(mDir, "Android.mk"); //$NON-NLS-1$
    if (makefile.exists()) {
        try {
            List<String> lines = Files.readLines(makefile, Charsets.UTF_8);
            Pattern p = Pattern.compile("LOCAL_SDK_VERSION\\s*:=\\s*(.*)"); //$NON-NLS-1$
            for (String line : lines) {
                line = line.trim();
                Matcher matcher = p.matcher(line);
                if (matcher.matches()) {
                    found = true;
                    String version = matcher.group(1);
                    if (version.equals("current")) { //$NON-NLS-1$
                        mManifestMinSdk = findCurrentAospVersion();
                    } else {
                        mManifestMinSdk = SdkVersionInfo.getVersion(version,
                                mClient.getTargets());
                    }
                    break;
                }
            }
        } catch (IOException ioe) {
            mClient.log(ioe, null);
        }
    }

    if (!found) {
        mManifestMinSdk = findCurrentAospVersion();
    }
}
 
源代码7 项目: Dolphin   文件: DefaultProcReader.java
@Override
public List<String> listProcesses(File cgroupFile) throws IOException {
    File cgroupProcsFile = new File(cgroupFile, CGROUP_PROCS);
    if (!cgroupProcsFile.exists()) {
        throw new FileNotFoundException(cgroupProcsFile.getAbsolutePath() + "is not exist!");
    }

    return Files.readLines(cgroupProcsFile, Charset.defaultCharset());
}
 
源代码8 项目: javaide   文件: CreateMainDexList.java
@TaskAction
public void output() throws IOException, ProcessException {
    if (getAllClassesJarFile() == null) {
        throw new NullPointerException("No input file");
    }


    // manifest components plus immediate dependencies must be in the main dex.
    File _allClassesJarFile = getAllClassesJarFile();
    Set<String> mainDexClasses = callDx(_allClassesJarFile, getComponentsJarFile());

    // add additional classes specified via a jar file.
    File _includeInMainDexJarFile = getIncludeInMainDexJarFile();
    if (_includeInMainDexJarFile != null) {
        // proguard shrinking is overly aggressive when it comes to removing
        // interface classes: even if an interface is implemented by a concrete
        // class, if no code actually references the interface class directly
        // (i.e., code always references the concrete class), proguard will
        // remove the interface class when shrinking.  This is problematic,
        // as the runtime verifier still needs the interface class to be
        // present, or the concrete class won't be valid.  Use a
        // ClassReferenceListBuilder here (only) to pull in these missing
        // interface classes.  Note that doing so brings in other unnecessary
        // stuff, too; next time we're low on main dex space, revisit this!
        mainDexClasses.addAll(callDx(_allClassesJarFile, _includeInMainDexJarFile));
    }


    if (mainDexListFile != null) {
        Set<String> mainDexList = new HashSet<String>(Files.readLines(mainDexListFile, Charsets.UTF_8));
        mainDexClasses.addAll(mainDexList);
    }


    String fileContent = Joiner.on(System.getProperty("line.separator")).join(mainDexClasses);

    Files.write(fileContent, getOutputFile(), Charsets.UTF_8);
}
 
源代码9 项目: Kylin   文件: BasicService.java
public DataSource getOLAPDataSource(String project) {

        project = ProjectInstance.getNormalizedProjectName(project);

        DataSource ret = olapDataSources.get(project);
        if (ret == null) {
            logger.debug("Creating a new data source");
            logger.debug("OLAP data source pointing to " + getConfig());

            File modelJson = OLAPSchemaFactory.createTempOLAPJson(project, getConfig());

            try {
                List<String> text = Files.readLines(modelJson, Charset.defaultCharset());
                logger.debug("The new temp olap json is :");
                for (String line : text)
                    logger.debug(line);
            } catch (IOException e) {
                e.printStackTrace(); // logging failure is not critical
            }

            DriverManagerDataSource ds = new DriverManagerDataSource();
            Properties props = new Properties();
            props.setProperty(OLAPQuery.PROP_SCAN_THRESHOLD, String.valueOf(KylinConfig.getInstanceFromEnv().getScanThreshold()));
            ds.setConnectionProperties(props);
            ds.setDriverClassName("net.hydromatic.optiq.jdbc.Driver");
            ds.setUrl("jdbc:calcite:model=" + modelJson.getAbsolutePath());

            ret = olapDataSources.putIfAbsent(project, ds);
            if (ret == null) {
                ret = ds;
            }
        }
        return ret;
    }
 
源代码10 项目: metanome-algorithms   文件: EnforceDemo.java
private Collection<Collection<ColumnMatchWithThreshold<?>>> getRules() {
	try {
		List<String> mds = Files.readLines(mdFile, CHARSET);
		return StreamUtils.seq(mds)
			.map(MDParser::parseMd)
			.toList();
	} catch (IOException e) {
		log.error("Error reading MDs", e);
		return Collections.emptyList();
	}
}
 
源代码11 项目: levelup-java-examples   文件: ReadTextFile.java
@Test
public void read_text_file_with_google_guava() {

	String filePath = this.getClass().getClassLoader()
			.getResource(FILE_PATH).getFile();

	List<String> lines = null;
	try {
		lines = Files.readLines(new File(filePath), Charsets.UTF_8);
	} catch (IOException e) {
		logger.error(e);
	}
	assertTrue(lines.size() == 28);
}
 
源代码12 项目: baleen   文件: CsvRelationEvalationConsumerTest.java
@Test
public void testCsv()
    throws AnalysisEngineProcessException, ResourceInitializationException, IOException {

  final File file = File.createTempFile("test", "relations");
  file.deleteOnExit();

  final String text = "John went to London.";
  jCas.setDocumentText(text);

  final Sentence s = new Sentence(jCas);
  s.setBegin(0);
  s.setEnd(text.length());
  s.addToIndexes();

  final Person p = new Person(jCas);
  p.setBegin(text.indexOf("John"));
  p.setEnd(p.getBegin() + "John".length());
  p.setValue("John");
  p.addToIndexes();

  final Location l = new Location(jCas);
  l.setBegin(text.indexOf("London"));
  l.setEnd(l.getBegin() + "London".length());
  l.setValue("London");
  l.addToIndexes();

  final Relation r = new Relation(jCas);
  r.setBegin(text.indexOf("went"));
  r.setEnd(r.getBegin() + "went".length());
  r.setValue("went");
  r.setRelationshipType("MOVEMENT");
  r.setRelationSubType("went");
  r.setSource(p);
  r.setTarget(l);
  r.addToIndexes();

  processJCas("filename", file.getAbsolutePath());

  final List<String> lines = Files.readLines(file, StandardCharsets.UTF_8);

  assertEquals(2, lines.size());

  // Header
  assertTrue(lines.get(0).contains("source"));
  // Relation
  assertTrue(lines.get(1).contains(",\"John went to London.\","));
  assertTrue(lines.get(1).contains(",\"John\","));
  assertTrue(lines.get(1).contains(",\"London\","));
  assertTrue(lines.get(1).contains(",\"MOVEMENT\","));
  assertTrue(lines.get(1).contains(",\"went\","));

  file.delete();
}
 
源代码13 项目: karamel   文件: IoUtils.java
public static List<String> readLinesFromPath(String url) throws IOException {
  return Files.readLines(new File(url), Charsets.UTF_8);
}
 
源代码14 项目: tutorials   文件: CsvUnitTest.java
private List<String> readFile(String filename) throws IOException {
    return Files.readLines(new File(filename), Charset.forName("utf-8"));
}
 
源代码15 项目: tasmo   文件: DebugHarnessTest.java
@Test(invocationCount = 1_000, singleThreaded = false, skipFailedInvocations = true, enabled = false)
    public void hackTest(TasmoMaterializerHarness t) throws Exception {
//        LogManager.getLogger("com.jivesoftware.os.tasmo").setLevel(Level.TRACE);
//        LogManager.getLogger("com.jivesoftware.os.tasmo.lib.concur.ConcurrencyAndExistanceCommitChange").setLevel(Level.TRACE);
//        LogManager.getLogger("com.jivesoftware.os.tasmo.reference.lib.ReferenceStore").setLevel(Level.TRACE);
//        LogManager.getLogger("com.jivesoftware.os.tasmo.view.reader.service.writer.WriteToViewValueStore").setLevel(Level.TRACE);

        ArrayNode rawViews = mapper.readValue(new File("/home/jonathan/jive/os/all_views.json"), ArrayNode.class);
        final JsonEventConventions eventConventions = new JsonEventConventions();
        Views views = TasmoModelFactory.modelToViews(rawViews);
        t.initModel(views);

        List<String> stringEvents = Files.readLines(new File("/home/jonathan/jive/os/events.txt"), Charset.defaultCharset());
        final Set<Id> instanceIds = new HashSet<>();
//        ExecutorService executorService = Executors.newFixedThreadPool(20);
        for (final String stringEvent : stringEvents) {
//            executorService.submit(new Runnable() {
//                public void run() {
            try {
                ObjectNode eventObjectNode = mapper.readValue(stringEvent, ObjectNode.class);
                //System.out.println("eventObjectNode:"+eventObjectNode);
                ObjectId instanceId = eventConventions.getInstanceObjectId(eventObjectNode);
                t.write(new Event(eventObjectNode, instanceId));
                if (instanceId.isClassName("UserFollowActivity")) {
                    instanceIds.add(instanceId.getId());
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
//                }
//            });
        }
        //Thread.sleep(5000);
        System.out.println("Checking " + instanceIds.size() + " views");
        boolean failed = false;
        for (Id commentInstanceId : instanceIds) {
            ObjectId viewObjectId = new ObjectId("UserFollowActivityView", commentInstanceId);
            ObjectNode view = t.readView(tenantId, actorId, viewObjectId, Id.NULL);
            System.err.println("View: " + commentInstanceId.toStringForm());
            System.err.println(mapper.writeValueAsString(view));
            if (view == null) {
                System.err.println("Failed to load view for " + viewObjectId);
            } else {
                //UserFollowActivityView.verbSubject.followedObject.instanceId
                if (!view.has("verbSubject")) {
                    JsonNode got = view.get("verbSubject");
                    if (!got.has("followedObject")) {
                        got = got.get("followedObject");
                        if (!got.has("instanceId")) {
                            System.out.println("ERROR");
                        } else {
                            failed = true;
                        }
                    } else {
                        failed = true;
                    }
                } else {
                    failed = true;
                }
            }
        }
        if (failed) {
            fail();
        }
    }
 
源代码16 项目: NBANDROID-V2   文件: ResourceClassGenerator.java
public static Map<ResourceType, Map<String, Object>> buildFullResourceMap(ResourceNamespace namespace, String fqcn, File projectR, ResourceClassGeneratorConfig config) {
    final Map<Integer, Integer> originalToGenerated = new HashMap<>();
    final Map<ResourceType, Map<String, Object>> resources = Maps.newHashMap();
    try {
        List<String> readLines = Files.readLines(projectR, StandardCharsets.UTF_8);
        for (String line : readLines) {
            StringTokenizer tok = new StringTokenizer(line, " ", false);
            if (tok.countTokens() > 3) {
                switch (tok.nextToken()) {
                    case "int":
                        handleFullLine(namespace, tok, resources, originalToGenerated, config);
                        break;
                    case "int[]":
                        handleFullLineArray(tok, line, resources);
                        break;
                }
            }
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    //refresh array ids to new IDs
    for (Map.Entry<ResourceType, Map<String, Object>> entry : resources.entrySet()) {
        ResourceType type = entry.getKey();
        Map<String, Object> values = entry.getValue();
        for (Map.Entry<String, Object> entry1 : values.entrySet()) {
            String name = entry1.getKey();
            Object value = entry1.getValue();
            if (value instanceof List) {
                List<Integer> in = (List<Integer>) value;
                List<Integer> out = new ArrayList<>();
                for (Integer val : in) {
                    Integer newVal = originalToGenerated.get(val);
                    if (newVal == null) {
                        out.add(val);
                    } else {
                        out.add(newVal);
                    }
                }
                values.replace(name, out);
            }
        }
    }
    return resources;
}
 
源代码17 项目: simhash-java   文件: Main.java
private static List<String> readDocs(String[] args) throws IOException {
	return Files.readLines(new File(args[0]), Charsets.UTF_8);
}
 
源代码18 项目: j360-dubbo-app-all   文件: FileUtil.java
/**
 * 读取文件的每行内容到List<String>
 */
public static List<String> toLines(final File file) throws IOException {
	return Files.readLines(file, Charsets.UTF_8);
}
 
源代码19 项目: tint   文件: TextProEvaluation.java
public static void main(String[] args) {
    try {
        final CommandLine cmd = CommandLine
                .parser()
                .withName("./evaluate-lemma")
                .withHeader("Calculate lemma evaluation for TextPro")
                .withOption("t", "guessed", "Input file", "FILE",
                        CommandLine.Type.FILE_EXISTING, true, false, true)
                .withOption("g", "gold-standard", "Input gold standard file", "FILE",
                        CommandLine.Type.FILE, true, false, true)
                .withLogger(LoggerFactory.getLogger("eu.fbk")).parse(args);

        File guessed = cmd.getOptionValue("guessed", File.class);
        File gold = cmd.getOptionValue("gold-standard", File.class);

        List<String> guesses = Files.readLines(guessed, Charsets.UTF_8);
        List<String> trueLabels = Files.readLines(gold, Charsets.UTF_8);

        int total = 0;
        int correct = 0;

        for (int i = 0; i < trueLabels.size(); i++) {
            String goldLabel = trueLabels.get(i);

            if (goldLabel.length() == 0) {
                continue;
            }

            String guess = guesses.get(i + 4); // TextPro output file has 4 starting lines
            String[] parts;

            parts = goldLabel.split("\t");
            goldLabel = parts[1];
            String pos = parts[2];

            boolean doIt = false;
            if (pos.startsWith("V")) {
                doIt = true;
            } else if (pos.startsWith("S")) {
                doIt = true;
            } else if (pos.startsWith("A")) {
                doIt = true;
            } else if (pos.startsWith("B")) {
                doIt = true;
            }

            if (goldLabel.equals("_")) {
                doIt = false;
            }

            if (!doIt) {
                continue;
            }
            total++;

            parts = guess.split("\t");
            guess = parts[2];
            guess = guess.replaceAll("\\s+.*", "");

            if (guess.equalsIgnoreCase(goldLabel)) {
                correct++;
            } else {
                System.out.printf("%s -> %s\n", guess, goldLabel);
            }

        }

        System.out.println(correct);
        System.out.println(total);
        System.out.println(correct * 1.0 / total);
    } catch (Exception e) {
        CommandLine.fail(e);
    }
}
 
源代码20 项目: tint   文件: TintEvaluation.java
public static void main(String[] args) {
    try {
        final CommandLine cmd = CommandLine
                .parser()
                .withName("./evaluate-lemma")
                .withHeader("Calculate lemma evaluation for Tint")
                .withOption("t", "guessed", "Input file", "FILE",
                        CommandLine.Type.FILE_EXISTING, true, false, true)
                .withOption("g", "gold-standard", "Input gold standard file", "FILE",
                        CommandLine.Type.FILE, true, false, true)
                .withLogger(LoggerFactory.getLogger("eu.fbk")).parse(args);

        File guessed = cmd.getOptionValue("guessed", File.class);
        File gold = cmd.getOptionValue("gold-standard", File.class);

        List<String> guesses = Files.readLines(guessed, Charsets.UTF_8);
        List<String> trueLabels = Files.readLines(gold, Charsets.UTF_8);

        int total = 0;
        int correct = 0;

        for (int i = 0; i < guesses.size(); i++) {
            String guess = guesses.get(i);
            String goldLabel = trueLabels.get(i);

            if (goldLabel.length() == 0) {
                continue;
            }

            String[] parts;

            parts = goldLabel.split("\t");
            goldLabel = parts[1];
            String pos = parts[2];

            boolean doIt = false;
            if (pos.startsWith("V")) {
                doIt = true;
            } else if (pos.startsWith("S")) {
                doIt = true;
            } else if (pos.startsWith("A")) {
                doIt = true;
            } else if (pos.startsWith("B")) {
                doIt = true;
            }

            if (goldLabel.equals("_")) {
                doIt = false;
            }

            if (!doIt) {
                continue;
            }
            total++;

            parts = guess.split("\t");
            guess = parts[2];

            if (guess.equalsIgnoreCase(goldLabel)) {
                correct++;
            }
            else {
                System.out.printf("%s -> %s\n", guess, goldLabel);
            }

        }

        System.out.println(correct);
        System.out.println(total);
        System.out.println(correct * 1.0 / total);
    } catch (Exception e) {
        CommandLine.fail(e);
    }
}