private String getPid() { final File libDir = PACKAGE_JAR.getParentFile(); final File installDir = libDir.getParentFile(); final File pidFile = new File(installDir, this.pidFilename); try { return Files.readFirstLine(pidFile, StandardCharsets.UTF_8).trim(); } catch (final IOException e) { log.error("Unable to obtain PID", e); return "unknown"; } }
@Nullable protected String readMetadata(@Nonnull Metadata metadata) throws MojoExecutionException { final File metadataFile = ensureMetadataFile(metadata); if (!metadataFile.exists()) { return null; } try { return Files.readFirstLine(metadataFile, Charsets.UTF_8); } catch (IOException e) { final String message = MessageFormat.format("Could not read {0} file at {1}", metadata.getFileName(), metadataFile); throw new MojoExecutionException(message, e); } }
public void testLineReading() throws IOException { File temp = createTempFile(); assertNull(Files.readFirstLine(temp, Charsets.UTF_8)); assertTrue(Files.readLines(temp, Charsets.UTF_8).isEmpty()); PrintWriter w = new PrintWriter(Files.newWriter(temp, Charsets.UTF_8)); w.println("hello"); w.println(""); w.println(" world "); w.println(""); w.close(); assertEquals("hello", Files.readFirstLine(temp, Charsets.UTF_8)); assertEquals( ImmutableList.of("hello", "", " world ", ""), Files.readLines(temp, Charsets.UTF_8)); assertTrue(temp.delete()); }
@Test public void testCopy() throws Exception { Path dir = FileUtil.createTempDir(); assertThat(dir).exists(); String srcFileName = "src"; File srcFile = dir.resolve(srcFileName).toFile(); FileUtil.touch(srcFile); assertThat(srcFile).exists(); FileUtil.write("test", srcFile); String destFileName = "dest"; File destFile = new File(dir.toFile(), "parent1/parent2/" + destFileName); FileUtil.makesureParentDirExists(destFile); FileUtil.copy(srcFile, destFile); assertThat(Files.readFirstLine(destFile, Charsets.UTF_8)).isEqualTo("test"); }
System.exit(1); String p12Content = Files.readFirstLine(new File("key.p12"), Charset.defaultCharset()); if (p12Content.startsWith("Please")) { System.err.println(p12Content);
protected void verifyResultRowCount(String queryFolder) throws Exception { printInfo("---------- verify result count in folder: " + queryFolder); List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql"); for (File sqlFile : sqlFiles) { String queryName = StringUtils.split(sqlFile.getName(), '.')[0]; String sql = getTextFromFile(sqlFile); File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected"); int expectRowCount = Integer.parseInt(Files.readFirstLine(expectResultFile, Charset.defaultCharset())); // execute Kylin printInfo("Query Result from Kylin - " + queryName + " (" + queryFolder + ")"); IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection); ITable kylinTable = executeQuery(kylinConn, queryName, sql, false); // compare the result Assert.assertEquals(expectRowCount, kylinTable.getRowCount()); // Assertion.assertEquals(expectRowCount, kylinTable.getRowCount()); } }
private String readRef(File refFile) { try { synchronized (refFile.getCanonicalPath().intern()) { return Files.readFirstLine(refFile, CHARSET); } } catch (IOException e) { throw Throwables.propagate(e); } }
private static String getActiveGoogleCloudConfig(File configDir) { String activeGoogleCloudConfig = null; try { activeGoogleCloudConfig = Files.readFirstLine(new File(configDir, "active_config"), Charset.defaultCharset()); } catch (IOException ex) { // ignore } // if reading active_config failed or the file is empty we try default return firstNonNull(activeGoogleCloudConfig, "default"); }
private static String activeGoogleCloudConfig(File configDir) { String activeGoogleCloudConfig = null; try { activeGoogleCloudConfig = Files.readFirstLine(new File(configDir, "active_config"), Charset.defaultCharset()); } catch (IOException ex) { // ignore } // if reading active_config failed or the file is empty we try default return firstNonNull(activeGoogleCloudConfig, "default"); }
private String readRef(final File refFile) { try { // make sure no other thread changes the ref as we read it synchronized (refFile.getCanonicalPath().intern()) { return Files.readFirstLine(refFile, CHARSET); } } catch (IOException e) { throw Throwables.propagate(e); } }
/** Reads the number of features in the model from the first line of alphabetFile */ private static int getNumFeatures(String alphabetFile) throws IOException { final String firstLine = Files.readFirstLine(new File(alphabetFile), Charsets.UTF_8); final int numFeatures = Integer.parseInt(firstLine.trim()) + 1; logger.info("Number of features: " + numFeatures); return numFeatures; }
private Class<?> readSuiteContext() { try { String className = Files.readFirstLine(lastRunFeatureFile, Charsets.UTF_8); ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (className != null && !"".equals(className.trim())) { return cl.loadClass(className); } } catch (Exception e) { return null; } return null; }
private Class<?> readSuiteContext() { try { String className = Files.readFirstLine(lastRunFeatureFile, Charsets.UTF_8); ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (className != null && !"".equals(className.trim())) { return cl.loadClass(className); } } catch (Exception e) { return null; } return null; }
private void skipCurrentCommit() { File rebaseFolder = getRebaseFolder(); File nextFile = new File(rebaseFolder, "next"); try { String idx = Files.readFirstLine(nextFile, Charsets.UTF_8); File commitFile = new File(rebaseFolder, idx); commitFile.delete(); int newIdx = Integer.parseInt(idx) + 1; Files.write(Integer.toString(newIdx), nextFile, Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Cannot read/write rebase commits index file"); } }
private static boolean isPrivateKeyFile(File file) { if (!file.isFile() || (!LintUtils.endsWith(file.getPath(), "pem") && !LintUtils.endsWith(file.getPath(), "key"))) { return false; } try { String firstLine = Files.readFirstLine(file, Charsets.US_ASCII); return firstLine != null && firstLine.startsWith("---") && firstLine.contains("PRIVATE KEY"); } catch (IOException ex) { // Don't care } return false; }
int readVersionHint() throws IOException { return Integer.parseInt(Files.readFirstLine(versionHintFile, Charsets.UTF_8)); }
@Test(groups = "Integration") public void testCopyFileTo() throws Exception { File dest = Os.newTempFile(getClass(), ".dest.tmp"); File src = Os.newTempFile(getClass(), ".src.tmp"); try { Files.write("abc", src, Charsets.UTF_8); host.copyTo(src, dest); assertEquals("abc", Files.readFirstLine(dest, Charsets.UTF_8)); } finally { src.delete(); dest.delete(); } }
@Test(groups = "Integration") public void testCopyStreamTo() throws Exception { String contents = "abc"; File dest = new File(Os.tmp(), "sshMachineLocationTest_dest.tmp"); try { host.copyTo(Streams.newInputStreamWithContents(contents), dest.getAbsolutePath()); assertEquals("abc", Files.readFirstLine(dest, Charsets.UTF_8)); } finally { dest.delete(); } }
@Override public void run() { String targetStatus = monitNode.getAttribute(MonitNode.MONIT_TARGET_PROCESS_STATUS); LOG.debug("MonitNode target status: {}", targetStatus); assertEquals(targetStatus, "Running"); try { initialPid[0] = Files.readFirstLine(new File(mySqlNode.getAttribute(SoftwareProcess.PID_FILE)), Charset.defaultCharset()); LOG.debug("Initial PID: {}", initialPid[0]); } catch (IOException e) { Asserts.fail("Could not read PID file: " + e); } } });
public void testLineReading() throws IOException { File temp = createTempFile(); assertNull(Files.readFirstLine(temp, Charsets.UTF_8)); assertTrue(Files.readLines(temp, Charsets.UTF_8).isEmpty()); PrintWriter w = new PrintWriter(Files.newWriter(temp, Charsets.UTF_8)); w.println("hello"); w.println(""); w.println(" world "); w.println(""); w.close(); assertEquals("hello", Files.readFirstLine(temp, Charsets.UTF_8)); assertEquals(ImmutableList.of("hello", "", " world ", ""), Files.readLines(temp, Charsets.UTF_8)); assertTrue(temp.delete()); }