Refine search
private String read() throws IOException { final List<String> lines = Files.readAllLines(Paths.get(filename), StandardCharsets.UTF_8); return lines.size() > 0 ? lines.get(0) : ""; }
public static void main(String... args) throws IOException { Path path = Paths.get(URI.create("gs://bucket/lolcat.csv")); List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8); } }
private List<String> readHostsFromFile(String filename) throws IOException { List<String> hosts = Files.readAllLines(Paths.get(filename), Charset.defaultCharset()); return hostNameToInstanceNames(hosts); }
private static String loadScript(final String filePath) { try { return Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8).stream() .collect(Collectors.joining(System.lineSeparator())); } catch (IOException e) { throw new KsqlException("Failed to read file: " + filePath, e); } } }
/** * @return List of servers from the exclude file in format 'hostname:port'. */ private List<String> readExcludes(String excludeFile) throws IOException { List<String> excludeServers = new ArrayList<>(); if (excludeFile == null) { return excludeServers; } else { try { Files.readAllLines(Paths.get(excludeFile)).stream().map(String::trim) .filter(((Predicate<String>) String::isEmpty).negate()).map(String::toLowerCase) .forEach(excludeServers::add); } catch (IOException e) { LOG.warn("Exception while reading excludes file, continuing anyways", e); } return excludeServers; } }
@GetMapping("/read") @ApiOperation("读取文本文件内容") @SneakyThrows @Authorize(action = "read", description = "读取文件") public ResponseMessage<String> read(@RequestParam String file) { File fileInfo = new File(file); if (!fileInfo.exists()) { return ResponseMessage.error(404,"文件不存在"); } if (fileInfo.length() > 2 * 1024 * 1024 * 1024L) { return ResponseMessage.error(500, "文件过大,无法读取"); } List<String> list = Files.readAllLines(Paths.get(file)); StringJoiner joiner = new StringJoiner("\n"); list.forEach(joiner::add); return ResponseMessage.ok(joiner.toString()); }
/** * Reads a list of nodes from given file name ignoring comments and empty lines. * Can be used to read conf/workers or conf/masters. * @param fileName name of a file that contains the list of the nodes * @return list of the node names, null when file fails to read */ public static List<String> readNodeList(String fileName) { String confDir = ServerConfiguration.get(PropertyKey.CONF_DIR); List<String> lines; try { lines = Files.readAllLines(Paths.get(confDir, fileName), StandardCharsets.UTF_8); } catch (IOException e) { System.err.format("Failed to read file %s/%s.%n", confDir, fileName); return null; } List<String> nodes = new ArrayList<>(); for (String line : lines) { String node = line.trim(); if (node.startsWith("#") || node.length() == 0) { continue; } nodes.add(node); } return nodes; }
private static void expandPrimitiveSpecialisedClass(final String packageName, final String className) throws IOException { final Path inputPath = Paths.get(SOURCE_DIRECTORY, packageName, className + SUFFIX); final Path outputDirectory = Paths.get(GENERATED_DIRECTORY, packageName); Files.createDirectories(outputDirectory); final List<String> contents = Files.readAllLines(inputPath, UTF_8); for (final Substitution substitution : SUBSTITUTIONS) { final String substitutedFileName = substitution.substitute(className); final List<String> substitutedContents = contents .stream() .map(substitution::checkedSubstitute) .collect(toList()); final Path outputPath = Paths.get(GENERATED_DIRECTORY, packageName, substitutedFileName + SUFFIX); Files.write(outputPath, substitutedContents, UTF_8); } }
private void readAndPrintFile(String fileName) { try { Files.readAllLines(Paths.get(fileName)).forEach(line -> log(" " + line, Project.MSG_INFO)); } catch (IOException ex) { LOGGER.error(ex.getMessage(), ex); } }
/** * Includes OS cache and free swap. * * @return the total free memory size of the OS. 0 if there is an error or the OS doesn't support * this memory check. */ long getOsTotalFreeMemorySize() { if (!Files.isRegularFile(Paths.get(MEM_INFO_FILE))) { // Mac doesn't support /proc/meminfo for example. return 0; } final List<String> lines; // The file /proc/meminfo is assumed to contain only ASCII characters. // The assumption is that the file is not too big. So it is simpler to read the whole file // into memory. try { lines = Files.readAllLines(Paths.get(MEM_INFO_FILE), StandardCharsets.UTF_8); } catch (final IOException e) { final String errMsg = "Failed to open mem info file: " + MEM_INFO_FILE; logger.error(errMsg, e); return 0; } return getOsTotalFreeMemorySizeFromStrings(lines); }
@Override public String query(String key) { StringBuilder sb = new StringBuilder(); Path path = Paths.get(appConfiguration.getMsgLoggerPath() + appConfiguration.getUserName() + "/"); try { Stream<Path> list = Files.list(path); List<Path> collect = list.collect(Collectors.toList()); for (Path file : collect) { List<String> strings = Files.readAllLines(file); for (String msg : strings) { if (msg.trim().contains(key)) { sb.append(msg).append("\n"); } } } } catch (IOException e) { LOGGER.info("IOException", e); } return sb.toString().replace(key, "\033[31;4m" + key + "\033[0m"); } }
private List<String> getScriptLines(Resource scriptResource) throws IOException { URI uri = scriptResource.getURI(); initFileSystem(uri); return Files.readAllLines(Paths.get(uri), StandardCharsets.UTF_8); }
@DataProvider(name = "1000points") public Object[][] points1000() throws IOException { Path filePath = Paths.get(this.getClass().getClassLoader().getResource("1000_points.txt").getPath()); List<String> points = Files.readAllLines(filePath); return new Object[][] { { "1000points", "POLYGON ((0.7642699 0.000490129, 0.92900103 0.005068898, 0.97419316 0.019917727, 0.99918157 0.063635945, 0.9997078 0.10172784, 0.9973114 0.41161585, 0.9909166 0.94222105, 0.9679412 0.9754768, 0.95201814 0.9936909, 0.44082636 0.9999601, 0.18622541 0.998157, 0.07163471 0.98902994, 0.066090584 0.9885783, 0.024429202 0.9685611, 0.0044354796 0.8878008, 0.0025004745 0.81172496, 0.0015820265 0.39900982, 0.001614511 0.00065791607, 0.7642699 0.000490129))", points.toArray(new String[0]), }, }; }
private static String getBucketPolicyFromFile(String policy_file) { StringBuilder file_text = new StringBuilder(); try { List<String> lines = Files.readAllLines( Paths.get(policy_file), Charset.forName("UTF-8")); for (String line : lines) { file_text.append(line); } } catch (IOException e) { System.out.format("Problem reading file: \"%s\"", policy_file); System.out.println(e.getMessage()); } // Verify the policy by trying to load it into a Policy object. Policy bucket_policy = null; try { bucket_policy = Policy.fromJson(file_text.toString()); } catch (IllegalArgumentException e) { System.out.format("Invalid policy text in file: \"%s\"", policy_file); System.out.println(e.getMessage()); } return bucket_policy.toJson(); }
private List<String> getLinesFromCurrentDataFile() throws IOException { Path dataFile = Paths.get(TEST_OUT_DIR, fileNameFormat.getCurrentFileName()); List<String> lines = Files.readAllLines(dataFile, Charset.defaultCharset()); return lines; }
@Test public void testLargeGeometryToBingTiles() throws Exception { Path filePath = Paths.get(this.getClass().getClassLoader().getResource("large_polygon.txt").getPath()); List<String> lines = Files.readAllLines(filePath); for (String line : lines) { String[] parts = line.split("\\|"); String wkt = parts[0]; int zoomLevel = Integer.parseInt(parts[1]); long tileCount = Long.parseLong(parts[2]); assertFunction("cardinality(geometry_to_bing_tiles(ST_GeometryFromText('" + wkt + "'), " + zoomLevel + "))", BIGINT, tileCount); } }
public static void main(String[] args) throws Exception { Options options = buildOptions(); CommandLineParser parser = new DefaultParser(); CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption(OPTION_SQL_FILE_LONG)) { printUsageAndExit(options, OPTION_SQL_FILE_LONG + " is required"); } String filePath = commandLine.getOptionValue(OPTION_SQL_FILE_LONG); List<String> stmts = Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8); StormSql sql = StormSql.construct(); @SuppressWarnings("unchecked") Map<String, Object> conf = Utils.readStormConfig(); if (commandLine.hasOption(OPTION_SQL_EXPLAIN_LONG)) { sql.explain(stmts); } else if (commandLine.hasOption(OPTION_SQL_TOPOLOGY_NAME_LONG)) { String topoName = commandLine.getOptionValue(OPTION_SQL_TOPOLOGY_NAME_LONG); SubmitOptions submitOptions = new SubmitOptions(TopologyInitialStatus.ACTIVE); sql.submit(topoName, stmts, conf, submitOptions, null, null); } else { printUsageAndExit(options, "Either " + OPTION_SQL_TOPOLOGY_NAME_LONG + " or " + OPTION_SQL_EXPLAIN_LONG + " must be presented"); } }
List<String> files = Arrays.asList(filename, filename.replace(".", File.separator) + ".java"); List<Path> source = Lists.newArrayList(Paths.get(filename)); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override return new Source(source.get(0), Files.readAllLines(source.get(0), StandardCharsets.UTF_8)); }).orElse(new Source(Paths.get(filename), Collections.emptyList()));
static void assertFileContents(final int runNumber) throws IOException { final Path path = Paths.get(FOLDER + "/audit.tmp"); final List<String> lines = Files.readAllLines(path, Charset.defaultCharset()); int i = 1; final int size = lines.size(); for (final String string : lines) { if (string.startsWith(",,")) { final Path folder = Paths.get(FOLDER); final File[] files = folder.toFile().listFiles(); Arrays.sort(files); System.out.println("Run " + runNumber + ": " + Arrays.toString(files)); Assert.fail( String.format("Run %,d, line %,d of %,d: \"%s\" in %s", runNumber, i++, size, string, lines)); } } }
@Setup public void setup() throws IOException { Path filePath = Paths.get(this.getClass().getClassLoader().getResource("large_polygon.txt").getPath()); List<String> lines = Files.readAllLines(filePath); String line = lines.get(0); String[] parts = line.split("\\|"); String wkt = parts[0]; geometry = GeoFunctions.stGeometryFromText(Slices.utf8Slice(wkt)); envelope = GeoFunctions.stEnvelope(geometry); zoomLevel = Integer.parseInt(parts[1]); } }