List of usage examples for java.nio.file Files readAllLines
public static List<String> readAllLines(Path path, Charset cs) throws IOException
From source file:org.apache.htrace.impl.TestDroppedSpans.java
/** * Test that we can write to the dropped spans log. *//* ww w .j av a2 s. co m*/ @Test(timeout = 60000) public void testWriteToDroppedSpansLog() throws Exception { final String logPath = new File(tempDir.toFile(), "testWriteToDroppedSpansLog").getAbsolutePath(); HTraceConfiguration conf = HTraceConfiguration.fromMap(new HashMap<String, String>() { { put(Conf.ADDRESS_KEY, "127.0.0.1:8080"); put(TracerId.TRACER_ID_KEY, "testWriteToDroppedSpansLog"); put(Conf.DROPPED_SPANS_LOG_PATH_KEY, logPath); put(Conf.DROPPED_SPANS_LOG_MAX_SIZE_KEY, "128"); } }); HTracedSpanReceiver rcvr = new HTracedSpanReceiver(conf); try { final String LINE1 = "This is a test of the dropped spans log."; rcvr.appendToDroppedSpansLog(LINE1 + "\n"); final String LINE2 = "These lines should appear in the log."; rcvr.appendToDroppedSpansLog(LINE2 + "\n"); try { rcvr.appendToDroppedSpansLog("This line won't be written because we're " + "out of space."); Assert.fail("expected append to fail because of lack of space"); } catch (IOException e) { // ignore } List<String> lines = Files.readAllLines(Paths.get(logPath), StandardCharsets.UTF_8); Assert.assertEquals(2, lines.size()); Assert.assertEquals(LINE1, lines.get(0).substring(25)); Assert.assertEquals(LINE2, lines.get(1).substring(25)); } finally { rcvr.close(); } }
From source file:com.kakao.hbase.manager.command.ExportKeysTest.java
@Test public void testRunOptimize() throws Exception { String outputFile = "exportkeys_test.keys"; try {/*from w ww . j a v a 2 s . com*/ String splitPoint = "splitpoint"; splitTable(splitPoint.getBytes()); String[] argsParam = { "zookeeper", tableName, outputFile, "--optimize=1g" }; Args args = new ManagerArgs(argsParam); assertEquals("zookeeper", args.getZookeeperQuorum()); ExportKeys command = new ExportKeys(admin, args); waitForSplitting(2); command.run(); List<Triple<String, String, String>> results = new ArrayList<>(); for (String keys : Files.readAllLines(Paths.get(outputFile), Constant.CHARSET)) { String[] split = keys.split(ExportKeys.DELIMITER); results.add(new ImmutableTriple<>(split[0], split[1], split[2])); } assertEquals(0, results.size()); } finally { Files.delete(Paths.get(outputFile)); } }
From source file:gr.cslab.Metric_test.java
static public boolean loadHostFile() { try {//w ww . j ava 2s .c om List<String> lines = Files.readAllLines(Paths.get(hostsFile), Charset.forName("UTF-8")); for (String line : lines) hosts.add(line.trim()); } catch (IOException ex) { return false; } return true; }
From source file:org.esupportail.publisher.config.FileUploadConfiguration.java
@Bean(name = "protectedFileUploadHelper") public FileUploadHelper protectedFileUploadHelper() throws IOException, URISyntaxException { FileUploadHelper fuh = new FileUploadHelper(); final String path = getDefinedUploadPath(ENV_UPLOAD_PROTECTED_PATH); Assert.notNull(path, "You should define a protected file path"); fuh.setUploadDirectoryPath(path);//from w w w.j a va 2s. c o m fuh.setResourceLocation("file:///" + path); fuh.setUrlResourceMapping(ViewController.FILE_VIEW.replaceFirst("/", "")); fuh.setUseDefaultPath(false); fuh.setFileMaxSize(env.getProperty(ENV_UPLOAD_FILESIZE, long.class, defaultFileMaxSize)); fuh.setUnremovablePaths( Arrays.asList(env.getProperty(ENV_UNREMOVABLE_PATH, String[].class, new String[] {}))); final String mimeTypesFilePath = env.getProperty(ENV_UPLOAD_FILE_AUTHORIZED_MIME_TYPE, defaultFileMimeTypes); try { List<String> list = Files.readAllLines(Paths.get(new ClassPathResource(mimeTypesFilePath).getURI()), Charsets.UTF_8); fuh.setAuthorizedMimeType(list); } catch (IOException e) { log.error("No file describing authorized MimeTypes is readable !", e); throw e; } log.debug("FileUploadConfiguration : " + fuh.toString()); return fuh; }
From source file:org.rapidpm.microservice.optionals.service.ServiceWrapper.java
private static String getRestPortFromFile() throws IOException { List<String> lines = Files.readAllLines(MICROSERVICE_REST_FILE, Charset.defaultCharset()); if (lines.size() != 1) { throw new NumberFormatException("File does not contain a number. It is empty"); }/* w w w .j a v a2 s .com*/ return lines.get(0); }
From source file:grakn.core.console.ConsoleSession.java
private static String readFile(Path filePath) throws IOException { List<String> lines = Files.readAllLines(filePath, StandardCharsets.UTF_8); return String.join("\n", lines); }
From source file:org.nuxeo.keynote.ZippedKeynoteToPDFConverter.java
/** * Just checking if the file starts with %PDF. * If it is the case, it does not make sure the pdf is * well formated, complete, etc. etc.// www. j a va2s . co m * * @since 5.9.5 * @param inFile * @return boolean */ protected boolean looksLikePdf(File inFile) { boolean startsWithCorrectTag = false; try { byte[] buffer = new byte[4]; InputStream is = new FileInputStream(inFile); if (is.read(buffer) != buffer.length) { startsWithCorrectTag = false; } else if (buffer[0] != 0x25 // % || buffer[1] != 0x50 // P || buffer[2] != 0x44 // D || buffer[3] != 0x46)// F { startsWithCorrectTag = false; // So we have an error => let's log this error java.nio.file.Path path = Paths.get(inFile.getPath()); log.error("nodejs server error:\n" + Files.readAllLines(path, StandardCharsets.UTF_8)); } else { startsWithCorrectTag = true; } is.close(); } catch (Exception e) { //FileNotFoundException, IOException log.error("Cannot read received pdf", e); startsWithCorrectTag = false; } return startsWithCorrectTag; }
From source file:rapture.sheet.file.FileSheetStore.java
/** * Load directly, do not try to read from cache. * @param sheetName/*from w ww . j a v a 2 s. c o m*/ * @return */ private FileSheetStatus loadSheet(String sheetName, long epoch) { File sheetFile = FileRepoUtils.makeGenericFile(parentDir, sheetName); if (!sheetFile.exists() || !sheetFile.isFile()) return nullSheetStatus; try { List<String> lines = Files.readAllLines(sheetFile.toPath(), StandardCharsets.UTF_8); FileSheetStatus status = new FileSheetStatus(); for (String line : lines) { String splitChar = line.substring(0, 1); String[] fields = line.substring(1).split(splitChar); RaptureSheetCell cell = new RaptureSheetCell(); long tmpEpoch = Long.parseLong(fields[2]); if (tmpEpoch >= epoch) { cell.setRow(Integer.parseInt(fields[0])); cell.setColumn(Integer.parseInt(fields[1])); cell.setEpoch(tmpEpoch); cell.setData(fields[3]); status.addCell(cell); } } sheetStatus.put(sheetName, status); return status; } catch (IOException | NumberFormatException e) { log.info("Cannot load sheet " + sheetName, e); log.debug(ExceptionToString.format(e)); } return nullSheetStatus; }
From source file:org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.TestTrafficController.java
private void verifyTrafficControlOperation(PrivilegedOperation op, PrivilegedOperation.OperationType expectedOpType, List<String> expectedTcCmds) throws IOException { //Verify that the optype matches Assert.assertEquals(expectedOpType, op.getOperationType()); List<String> args = op.getArguments(); //Verify that arg count is always 1 (tc command file) for a tc operation Assert.assertEquals(1, args.size()); File tcCmdsFile = new File(args.get(0)); //Verify that command file exists Assert.assertTrue(tcCmdsFile.exists()); List<String> tcCmds = Files.readAllLines(tcCmdsFile.toPath(), Charset.forName("UTF-8")); //Verify that the number of commands is the same as expected and verify //that each command is the same, in sequence Assert.assertEquals(expectedTcCmds.size(), tcCmds.size()); for (int i = 0; i < tcCmds.size(); ++i) { Assert.assertEquals(expectedTcCmds.get(i), tcCmds.get(i)); }/*from w w w . ja v a2 s. c o m*/ }
From source file:edu.usu.sdl.openstorefront.usecase.AttributeImport.java
private AttributeTypeView loadDI2EArch() { AttributeTypeView attributeTypeView = new AttributeTypeView(); CSVParser parser = new CSVParser(); Path path = Paths.get(FileSystemManager.getDir(FileSystemManager.IMPORT_DIR) + "/di2esv4.csv"); int lineNumber = 0; try {/* w ww. j a v a2 s . c o m*/ List<String> lines = Files.readAllLines(path, Charset.defaultCharset()); //read type try (CSVReader reader = new CSVReader(new InputStreamReader( new FileInputStream("\\var\\openstorefront\\import\\svcv-4_export.csv")));) { String data[] = parser.parseLine(lines.get(1)); attributeTypeView.setAttributeType(data[0].trim()); attributeTypeView.setDescription(data[1].trim()); attributeTypeView.setArchitectureFlg(Convert.toBoolean(data[2].trim())); attributeTypeView.setVisibleFlg(Convert.toBoolean(data[3].trim())); attributeTypeView.setImportantFlg(Convert.toBoolean(data[4].trim())); attributeTypeView.setRequiredFlg(Convert.toBoolean(data[5].trim())); attributeTypeView.setAllowMultipleFlg(Convert.toBoolean(data[6].trim())); List<String[]> allLines = reader.readAll(); for (int i = 1; i < allLines.size(); i++) { lineNumber = i; String lineData[] = allLines.get(i); if (lineData.length > 0) { AttributeCodeView attributeCodeView = new AttributeCodeView(); if (StringUtils.isNotBlank(lineData[1].trim())) { attributeCodeView.setCode(lineData[1].toUpperCase().trim()); attributeCodeView.setLabel(lineData[1].toUpperCase().trim() + " " + lineData[2].trim()); StringBuilder desc = new StringBuilder(); desc.append("<b>Definition:</b>").append(lineData[3].replace("\n", "<br>")) .append("<br>"); desc.append("<b>Description:</b>").append(lineData[4].replace("\n", "<br>")); attributeCodeView.setDescription(desc.toString()); attributeTypeView.getCodes().add(attributeCodeView); } } } } catch (IOException ex) { log.log(Level.SEVERE, "Failed on line: " + lineNumber, ex); } } catch (IOException ex) { log.log(Level.SEVERE, null, ex); } return attributeTypeView; }