private void assertFilesAreEqualIgnoringWhitespaces(File expected, File actual) throws Exception { String assertionMessage = "Expected content in " + expected + ", Actual content in " + actual; List<String> expectedLines = Files.readLines(expected, Charset.forName("UTF-8")); List<String> actualLines = Files.readLines(actual, Charset.forName("UTF-8")); assertEquals(assertionMessage, expectedLines.size(), actualLines.size()); for (int i = 0, end = expectedLines.size(); i < end; i++) { String expectedLine = expectedLines.get(i); String actualLine = actualLines.get(i); assertEquals(assertionMessage, expectedLine.trim(), actualLine.trim()); } }
@Test(groups = "Integration") public void testCopyResourceCreatingParentDir() throws Exception { File tempDataDirSub = new File(tempDataDir, "subdir"); File tempDest = new File(tempDataDirSub, "tempDest.txt"); String tempLocalContent = "abc"; File tempLocal = new File(tempDataDir, "tempLocal.txt"); Files.write(tempLocalContent, tempLocal, Charsets.UTF_8); localhost.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath()); MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)); app.start(ImmutableList.of(localhost)); // First confirm would get exception in createeParentDir==false try { entity .getDriver() .copyResource(tempLocal.toURI().toString(), tempDest.getAbsolutePath(), false); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); fail("Should have failed to create " + tempDest); } catch (SshException e) { // success } finally { Os.deleteRecursively(tempDataDirSub); } // Copy to absolute path try { entity .getDriver() .copyResource(tempLocal.toURI().toString(), tempDest.getAbsolutePath(), true); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); } finally { Os.deleteRecursively(tempDataDirSub); } // Copy to absolute path String runDir = entity.getDriver().getRunDir(); String tempDataDirRelativeToRunDir = "subdir"; String tempDestRelativeToRunDir = Os.mergePaths(tempDataDirRelativeToRunDir, "tempDest.txt"); File tempDestInRunDir = new File(Os.mergePaths(runDir, tempDestRelativeToRunDir)); try { entity.getDriver().copyResource(tempLocal.toURI().toString(), tempDestRelativeToRunDir, true); assertEquals( Files.readLines(tempDestInRunDir, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); } finally { Os.deleteRecursively(new File(runDir, tempDataDirRelativeToRunDir)); } }
public void parse() throws Exception { Files.readLines( Paths.get(path).toFile(), Charset.defaultCharset(), new LineProcessor<String>() { @Override public boolean processLine(String line) throws IOException { HistogramResult result = JSON.parseObject(line, HistogramResult.class); String histogramString = result.getHistogram(); System.out.println(histogramString); ByteBuffer buffer = ByteBuffer.wrap(DatatypeConverter.parseBase64Binary(histogramString)); try { Histogram histogram = Histogram.decodeFromCompressedByteBuffer(buffer, 0); histogram.setStartTimeStamp(result.getStartTime()); histogram.setEndTimeStamp(result.getEndTime()); // TODO } catch (DataFormatException e) { e.printStackTrace(); } return true; } @Override public String getResult() { return null; } }); }
/** * Check if the xml file starts with a prolog "<?xml version="1.0" ?>" if so, check if there * is any characters prefixing it. */ private void checkForCharactersBeforeProlog(FileSystem fileSystem) { try { int lineNb = 1; Pattern firstTagPattern = Pattern.compile("<[a-zA-Z?]+"); boolean hasBOM = false; for (String line : Files.readLines(inputFile.file(), fileSystem.encoding())) { if (lineNb == 1 && line.startsWith(BOM_CHAR)) { hasBOM = true; characterDeltaForHighlight = -1; } Matcher m = firstTagPattern.matcher(line); if (m.find()) { int column = line.indexOf(m.group()); if (XML_PROLOG_START_TAG.equals(m.group()) && !isFileBeginning(lineNb, column, hasBOM)) { hasCharsBeforeProlog = true; } break; } lineNb++; } if (hasCharsBeforeProlog) { processCharBeforePrologInFile(fileSystem, lineNb); } } catch (IOException e) { LOG.warn("Unable to analyse file {}", inputFile.absolutePath(), e); } }
public static void main(String[] args) { List<String> lines = null; try { lines = Files.readLines(new File("D:\\version.txt"), Charset.forName("UTF-8")); } catch (IOException e) { e.printStackTrace(); } Map<String, String> versionMap = Maps.newHashMap(); for (String line : lines) { if (StringUtils.isBlank(line)) continue; Iterable<String> entryFields = Splitter.on(':').trimResults().limit(2).split(line); if (entryFields == null) continue; Iterator<String> i = entryFields.iterator(); if (i.hasNext()) { String key = null; String value = null; key = i.next(); if (i.hasNext()) { value = i.next(); } versionMap.put(key, value); } } System.out.println(versionMap.get("Name")); System.out.println(versionMap.get("Version")); }
public static void clean(File inputFile, File outputFile) throws IOException { List<String> inputLines = Files.readLines(inputFile, Charsets.UTF_8); List<String> outputLines = Lists.newArrayList(); clean(inputLines, outputLines); outputFile.delete(); boolean ok = outputFile.createNewFile(); Preconditions.checkState(ok); OutputStreamWriter char_output = new OutputStreamWriter( new FileOutputStream(outputFile, false), Charset.forName("UTF-8").newEncoder()); BufferedWriter os = new BufferedWriter(char_output); for (String line : outputLines) { os.write(line); log.debug(line); os.write("\n"); } os.close(); }
public static void main(String[] args) throws IOException, InterruptedException { if (args[0].startsWith("@")) { build(Files.readLines(new File(args[0].substring(1)), StandardCharsets.UTF_8)); } else { build(Arrays.asList(args)); } }
@Test public void read_file_array_list_guava() throws IOException { List<String> teams = Files.readLines(worldSeriesWinners.toFile(), Charsets.UTF_8); assertEquals(10, teams.size()); }
public void build() throws IOException { moduleNameToMakeFileMap = Maps.newHashMap(); makeFileToModuleNamesMap = Maps.newHashMap(); logger.info("Building index from " + indexFile.getCanonicalPath()); Files.readLines( indexFile, Charset.forName("UTF-8"), new LineProcessor<Object>() { int count = 0; @Override public boolean processLine(String line) throws IOException { count++; String[] arr = line.split(":"); if (arr.length < 2) { logger.log(Level.WARNING, "Ignoring index line " + count + ". Bad format: " + line); } else { String makeFile = arr[0]; String moduleName = arr[1]; moduleNameToMakeFileMap.put(moduleName, makeFile); append(makeFile, moduleName); } return true; } @Override public Object getResult() { return null; } }); }
public static void main(String[] args) throws IOException { Closer closer = Closer.create(); // copy a file File origin = new File("join_temp"); File copy = new File("target_temp"); try { BufferedReader reader = new BufferedReader(new FileReader("join_temp")); BufferedWriter writer = new BufferedWriter(new FileWriter("target_temp")); closer.register(reader); closer.register(writer); String line; while ((line = reader.readLine()) != null) { writer.write(line); } } catch (IOException e) { throw closer.rethrow(e); } finally { closer.close(); } Files.copy(origin, copy); File moved = new File("moved"); // moving renaming Files.move(copy, moved); // working files as string List<String> lines = Files.readLines(origin, Charsets.UTF_8); HashCode hashCode = Files.hash(origin, Hashing.md5()); System.out.println(hashCode); // file write and append String hamlet = "To be, or not to be it is a question\n"; File write_and_append = new File("write_and_append"); Files.write(hamlet, write_and_append, Charsets.UTF_8); Files.append(hamlet, write_and_append, Charsets.UTF_8); // write_and_append.deleteOnExit(); Files.write("OverWrite the file", write_and_append, Charsets.UTF_8); // ByteSource ByteSink ByteSource fileBytes = Files.asByteSource(write_and_append); byte[] readBytes = fileBytes.read(); // equals to pre line -> Files.toByteArray(write_and_append) == readBytes ByteSink fileByteSink = Files.asByteSink(write_and_append); fileByteSink.write(Files.toByteArray(write_and_append)); BaseEncoding base64 = BaseEncoding.base64(); System.out.println(base64.encode("123456".getBytes())); }
@Test(groups = "Integration") public void testCopyResource() throws Exception { File tempDest = new File(tempDataDir, "tempDest.txt"); String tempLocalContent = "abc"; File tempLocal = new File(tempDataDir, "tempLocal.txt"); Files.write(tempLocalContent, tempLocal, Charsets.UTF_8); localhost.setConfig(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath()); MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)); app.start(ImmutableList.of(localhost)); // Copy local file entity.getDriver().copyResource(tempLocal, tempDest.getAbsolutePath()); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); tempDest.delete(); // Copy local file using url entity.getDriver().copyResource(tempLocal.toURI().toString(), tempDest.getAbsolutePath()); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); tempDest.delete(); // Copy reader entity.getDriver().copyResource(new StringReader(tempLocalContent), tempDest.getAbsolutePath()); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); tempDest.delete(); // Copy stream entity .getDriver() .copyResource( ByteSource.wrap(tempLocalContent.getBytes()).openStream(), tempDest.getAbsolutePath()); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); tempDest.delete(); // Copy known-size stream entity .getDriver() .copyResource( new KnownSizeInputStream( Streams.newInputStreamWithContents(tempLocalContent), tempLocalContent.length()), tempDest.getAbsolutePath()); assertEquals(Files.readLines(tempDest, Charsets.UTF_8), ImmutableList.of(tempLocalContent)); tempDest.delete(); }
private static String[] parseParamFileIfUsed(@Nonnull String[] args) { if (args.length != 1 || !args[0].startsWith("@")) { return args; } File paramFile = new File(args[0].substring(1)); try { return Files.readLines(paramFile, StandardCharsets.UTF_8).toArray(new String[0]); } catch (IOException e) { throw new RuntimeException("Error parsing param file: " + args[0], e); } }
@Test public void testWriteStreamToTempFile() throws Exception { File tempFileLocal = ResourceUtils.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(); } }
private AccessToken getSavedAccessToken(String hostname) { File file = getAccessTokenFile(hostname); if (file.exists() && file.canRead()) { try { String tokenString = Joiner.on("").join(Files.readLines(file, Charsets.UTF_8)); return new AccessToken(tokenString, -1L, null); } catch (IOException ignored) { // Fall through } } return null; }
/** * Returns a map from name to resource types for all resources known to this library. This is * used to make sure that when the {@link #isPrivate(ResourceType, String)} query method is * called, it can tell the difference between a resource implicitly private by not being * declared as public and a resource unknown to this library (e.g. defined by a different * library or the user's own project resources.) * * @return a map from name to resource type for all resources in this library */ @Nullable private Multimap<String, ResourceType> computeAllMap() { // getSymbolFile() is not defined in AndroidLibrary, only in the subclass LibraryBundle File symbolFile = new File(mLibrary.getPublicResources().getParentFile(), FN_RESOURCE_TEXT); if (!symbolFile.exists()) { return null; } try { List<String> lines = Files.readLines(symbolFile, Charsets.UTF_8); Multimap<String, ResourceType> result = ArrayListMultimap.create(lines.size(), 2); ResourceType previousType = null; String previousTypeString = ""; int lineIndex = 1; final int count = lines.size(); for (; lineIndex <= count; lineIndex++) { String line = lines.get(lineIndex - 1); if (line.startsWith("int ")) { // not int[] definitions for styleables // format is "int <type> <class> <name> <value>" int typeStart = 4; int typeEnd = line.indexOf(' ', typeStart); // Items are sorted by type, so we can avoid looping over types in // ResourceType.getEnum() for each line by sharing type in each section String typeString = line.substring(typeStart, typeEnd); ResourceType type; if (typeString.equals(previousTypeString)) { type = previousType; } else { type = ResourceType.getEnum(typeString); previousTypeString = typeString; previousType = type; } if (type == null) { // some newly introduced type continue; } int nameStart = typeEnd + 1; int nameEnd = line.indexOf(' ', nameStart); String name = line.substring(nameStart, nameEnd); result.put(name, type); } } return result; } catch (IOException ignore) { } return null; }
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { if (file == null || !file.exists()) { return; } final Pattern patternCompiled = Pattern.compile(pattern); try { final List<String> lines = Files.readLines( file, Charset.defaultCharset(), new LineProcessor<List<String>>() { private List<String> matchedLines = new LinkedList<>(); @Override public boolean processLine(final String line) throws IOException { if (patternCompiled.matcher(line).matches()) { matchedLines.add(line); if (maxMatchedLines != 0 && maxMatchedLines <= matchedLines.size()) { return false; } } return true; } @Override public List<String> getResult() { return matchedLines; } }); if (lines.size() > 0) { throw new EnforcerRuleException( "Found lines matching pattern: '" + pattern + "'! Lines matched: " + Arrays.toString(lines.toArray()) + " in file: " + file.getAbsolutePath()); } } catch (IOException e) { throw new EnforcerRuleException( "I/O Error occurred during processing of file: " + file.getAbsolutePath(), e); } }
@Test public void testClasspathSetupMulti() throws Exception { System.clearProperty(HiveConf.ConfVars.HADOOPBIN.toString()); List<String> inputURLs = Lists.newArrayList(); inputURLs.add("/usr/lib/hbase/lib/hbase-protocol-0.96.1.2.0.11.0-1-hadoop2.jar"); inputURLs.add( "/opt/cloudera/parcels/CDH-5.0.0-0.cdh5b2.p0.27/lib/hbase/hbase-protocol-0.95.0.jar"); inputURLs.add( "/home/cloudera/.m2/repository/org/apache/hbase/hbase-protocol/0.95.1-hadoop1/" + "hbase-protocol-0.95.1-hadoop1.jar"); inputURLs.add("/usr/lib/hbase/lib/hbase-hadoop2-compat-0.96.1.2.0.11.0-1-hadoop2.jar"); inputURLs.add("/usr/lib/hbase/lib/hbase-thrift-0.96.1.2.0.11.0-1-hadoop2.jar"); inputURLs.add("/usr/lib/hadoop/hadoop-common-2.2.0.2.0.11.0-1-tests.jar"); List<String> auxJarsURLs = Lists.newArrayList(); auxJarsURLs.add( "/hadoop/hadoop/nm-local-dir/usercache/cdap/appcache/org.ow2.asm.asm-all-4.0.jar"); auxJarsURLs.add( "/hadoop/hadoop/nm-local-dir/usercache/cdap/appcache/co.cask.cdap.common-2.4.0-SNAPSHOT.jar"); HiveConf hiveConf = new HiveConf(); LocalMapreduceClasspathSetter classpathSetter = new LocalMapreduceClasspathSetter( hiveConf, TEMP_FOLDER.newFolder().getAbsolutePath(), auxJarsURLs); for (String url : inputURLs) { classpathSetter.accept(url); } Assert.assertEquals( ImmutableList.of( "/usr/lib/hbase/lib/hbase-protocol-0.96.1.2.0.11.0-1-hadoop2.jar", "/opt/cloudera/parcels/CDH-5.0.0-0.cdh5b2.p0.27/lib/hbase/" + "hbase-protocol-0.95.0.jar", "/home/cloudera/.m2/repository/org/apache/hbase/hbase-protocol/" + "0.95.1-hadoop1/hbase-protocol-0.95.1-hadoop1.jar"), ImmutableList.copyOf(classpathSetter.getHbaseProtocolJarPaths())); classpathSetter.setupClasspathScript(); String newHadoopBin = new HiveConf().get(HiveConf.ConfVars.HADOOPBIN.toString()); Assert.assertEquals( generatedHadoopBinMulti, Joiner.on('\n').join(Files.readLines(new File(newHadoopBin), Charsets.UTF_8))); Assert.assertTrue(new File(newHadoopBin).canExecute()); System.clearProperty(HiveConf.ConfVars.HADOOPBIN.toString()); }
private XPathSetPredicate getXPathSetPredicate(final String xpathQuery, final String filePath) { try { return new XPathSetPredicate( xpathQuery, Sets.newHashSet(Files.readLines(new File(filePath), UTF_8))); } catch (XPathExpressionException e) { printHelp(messageInvalidXPathExpression(xpathQuery, SELECT, e)); return null; } catch (IOException e) { printHelp( messageInvalidArguments( "Failed to read white-list of patterns from file: " + filePath + "." + originalError(e))); return null; } }
@Override protected Optional<Mapping> _call() { Preconditions.checkNotNull(entry); final File osmMapFolder = command(ResolveOSMMappingLogFolder.class).call(); File file = new File(osmMapFolder, entry.getPostMappingId().toString()); if (!file.exists()) { return Optional.absent(); } try { List<String> lines = Files.readLines(file, Charsets.UTF_8); String s = Joiner.on("\n").join(lines); Mapping mapping = Mapping.fromString(s); return Optional.of(mapping); } catch (IOException e) { throw Throwables.propagate(e); } }
private boolean isProblemClass(File javaFile) { if (nonProblemClassesToFilter.contains(javaFile.getName())) return false; final String javaClassName = FilenameUtils.getBaseName(javaFile.getAbsolutePath()); try { Collection<String> lines = Files.readLines(javaFile, Charset.forName("UTF8")); for (String line : lines) { if (line.matches("^\\s*public\\s+final\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) return true; if (line.matches("^\\s*final\\s+public\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) return true; if (line.matches("^\\s*public\\s+class\\s+" + javaClassName + "\\s+extends\\s+.*")) return true; } return false; } catch (IOException e) { return false; } }
private static Map<String, String> readConfigFileLines(final String configFile) { if (StringTools.isNullOrEmpty(configFile) || !FileTools.fileExistsAndCanRead(configFile)) return ImmutableMap.of(); try { LogTools.info("Reading config values from file {0}", configFile); return StringTools.convertStringsToMap( Files.readLines(new File(configFile), Charset.defaultCharset()) .stream() .filter(line -> !line.trim().startsWith("#")) // remove comments .collect(Collectors.toList()), CharMatcher.is('='), false); } catch (IOException e) { throw Throwables.propagate(e); } }
@Override public void visitFile(AstNode astNode) { List<String> lines; try { lines = Files.readLines(getContext().getFile(), charset); } catch (IOException e) { throw new SonarException(e); } for (int i = 0; i < lines.size(); i++) { if (lines.get(i).contains("\t")) { getContext() .createLineViolation( this, "Replace all tab characters in this file by sequences of white-spaces.", i + 1); break; } } }
private void runScriptFile(final String testScript) { try { log.info("Running test script: {}", testScript); StringBuilder scriptBuilder = new StringBuilder(); for (String line : Files.readLines(new File(testScript), Charsets.UTF_8)) { scriptBuilder.append(line).append("\r\n"); } Object result = runScript(scriptBuilder.toString()); log.info("Script completed successfully with result: {}", result); BeanInjector.getBean(BundleContext.class).getBundle(0).stop(); Thread.sleep(5000); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
public Ppm(File file) throws IOException { List<String> lines = Files.readLines(file, Charset.defaultCharset()); Iterator<String> it = lines.iterator(); if (!"P6".equals(it.next())) { throw new IllegalArgumentException("Expected P6"); } String[] wl = it.next().split(" "); this.width = Integer.parseInt(wl[0]); this.height = Integer.parseInt(wl[1]); this.image = new int[width][height][3]; int maxColor = Integer.parseInt(it.next()); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { String[] colors = it.next().split(" "); int i = 0; image[x][y][i] = Integer.parseInt(colors[i++]); image[x][y][i] = Integer.parseInt(colors[i++]); image[x][y][i] = Integer.parseInt(colors[i++]); } } }
private void processFlagFile(PrintStream err) throws CmdLineException, IOException { File flagFileInput = new File(flags.flagFile); List<String> argsInFile = tokenizeKeepingQuotedStrings(Files.readLines(flagFileInput, Charset.defaultCharset())); flags.flagFile = ""; List<String> processedFileArgs = processArgs(argsInFile.toArray(new String[] {})); CmdLineParser parserFileArgs = new CmdLineParser(flags); // Command-line warning levels should override flag file settings, // which means they should go last. List<GuardLevel> previous = Lists.newArrayList(Flags.guardLevels); Flags.guardLevels.clear(); parserFileArgs.parseArgument(processedFileArgs.toArray(new String[] {})); Flags.guardLevels.addAll(previous); // Currently we are not supporting this (prevent direct/indirect loops) if (!flags.flagFile.equals("")) { err.println("ERROR - Arguments in the file cannot contain " + "--flagfile option."); isConfigValid = false; } }
public DebugExec() { try { final File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js"); if (file.exists()) { init(); final String script = StringMan.join( Files.readLines( new File( new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8), System.getProperty("line.separator")); scope.put("THIS", this); scope.put("PlotPlayer", ConsolePlayer.getConsole()); engine.eval(script, scope); } } catch (final Exception e) { } }
@Test public void testPersistentStoreBack() throws Exception { File file = new File(System.getProperty("java.io.tmpdir")); adocEditor.setPersistentStoreBack("test", file); FXPlatform.invokeLater(() -> adocEditor.setText("bla blubb")); Thread.sleep(LastTextChange.WAIT_TIME * 2); activityController.waitForTasks(); List<String> strings = Files.readLines(new File(file, "test"), Charsets.UTF_8); assertEquals(1, strings.size()); adocEditor.removePersistentStoreBack(); FXPlatform.invokeLater(() -> adocEditor.setText("")); Thread.sleep(LastTextChange.WAIT_TIME * 2); activityController.waitForTasks(); adocEditor.setPersistentStoreBack("test", file); FXPlatform.invokeLater(() -> adocEditor.onRefresh(null)); activityController.waitForTasks(); assertEquals("bla blubb\n", adocEditor.getText()); }
public void test(File testFile) throws IOException { DataSet testSet = Files.readLines(testFile, Charsets.UTF_8, new DataSetLoader()); int hit = 0, total = 0; Stopwatch sw = Stopwatch.createStarted(); Random r = new Random(5); for (SentenceData sentence : testSet.sentences) { for (Z3WordData word : sentence.words) { Collections.shuffle(word.allParses, r); } Ambiguous[] seq = getAmbiguousSequence(sentence); int[] bestSeq = bestSequence(seq); int j = 0; for (int parseIndex : bestSeq) { Z3WordData wordData = sentence.words.get(j); if (wordData.allParses.get(parseIndex).equals(wordData.correctParse)) { hit++; } else { System.out.println( "miss:" + wordData.word + " Correct:" + wordData.correctParse + " : " + wordData.allParses.get(parseIndex)); } total++; j++; } } System.out.println("Elapsed: " + sw.elapsed(TimeUnit.MILLISECONDS) + "ms."); System.out.println("Total: " + total + " hit: " + hit); System.out.println(String.format("Accuracy:%.3f%%", (double) hit / total * 100)); if (sw.elapsed(TimeUnit.MILLISECONDS) > 0) { System.out.println( "Approximate performance: " + (1000L * total / sw.elapsed(TimeUnit.MILLISECONDS)) + " per second."); } }
private void addJsonSchemaDefinition(ObjectNode definitions, DocletTag tag) { File definitionsDirectory = new File(srcDirectory + "/src/main/resources/definitions"); if (tag != null) { tag.getParameters() .stream() .forEach( param -> { try { File config = new File(definitionsDirectory.getAbsolutePath() + "/" + param + ".json"); String lines = Files.readLines(config, Charsets.UTF_8) .stream() .reduce((t, u) -> t + u) .get(); definitions.putPOJO(param, lines); } catch (IOException e) { e.printStackTrace(); } }); } }
public static void main(String[] args) throws IOException { System.out.println("Hello, world.."); String basePath = "conf"; if (args.length > 0) { basePath = args[0]; } File file = new File(basePath + File.separator + "cmd.conf"); try { List<String> lines = Files.readLines(file, Charset.forName("UTF-8")); Properties prop = new Properties(); prop.list(System.out); for (String line : lines) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } }