/** * Reads the first line from a file. The line does not include line-termination characters, but * does include other leading and trailing whitespace. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @return the first line, or null if the file is empty * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readFirstLine()}. This method is * scheduled to be removed in January 2019. */ @Deprecated public static String readFirstLine(File file, Charset charset) throws IOException { return asCharSource(file, charset).readFirstLine(); }
/** * Reads the first line from a file. The line does not include line-termination characters, but * does include other leading and trailing whitespace. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @return the first line, or null if the file is empty * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readFirstLine()}. This method is * scheduled to be removed in January 2019. */ @Deprecated public static String readFirstLine(File file, Charset charset) throws IOException { return asCharSource(file, charset).readFirstLine(); }
private static String getActiveGoogleCloudConfig(File configDir) { String activeGoogleCloudConfig = null; try { activeGoogleCloudConfig = Files.asCharSource(new File(configDir, "active_config"), Charset.defaultCharset()) .readFirstLine(); } catch (IOException ex) { // ignore } // if reading active_config failed or the file is empty we try default return firstNonNull(activeGoogleCloudConfig, "default"); }
/** * Reads the first line from a file. The line does not include line-termination characters, but * does include other leading and trailing whitespace. * * @param file the file to read from * @param charset the charset used to decode the input stream; see {@link StandardCharsets} for * helpful predefined constants * @return the first line, or null if the file is empty * @throws IOException if an I/O error occurs * @deprecated Prefer {@code asCharSource(file, charset).readFirstLine()}. This method is * scheduled to be removed in January 2019. */ @Deprecated public static String readFirstLine(File file, Charset charset) throws IOException { return asCharSource(file, charset).readFirstLine(); }
public void testReadFirstLine() throws IOException { if (expectedLines.isEmpty()) { assertNull(source.readFirstLine()); } else { assertEquals(expectedLines.get(0), source.readFirstLine()); } }
private boolean shouldShutdown(final String message) { try { return shutdownKey.equals(wrap(message).readFirstLine()); } catch (IOException e) { throw new MocoException(e); } } }
try { if (!committedReadOffsetFile.createNewFile()) { final String line = Files.asCharSource(committedReadOffsetFile, StandardCharsets.UTF_8).readFirstLine();
private static String readPasswordFromFile(Path passwordFile) { try { return Files.asCharSource(passwordFile.toFile(), UTF_8).readFirstLine(); } catch (IOException e) { throw new UncheckedIOException( String.format("Unable to read password from file '%s'.", passwordFile), e); } } }
public static String[] readAndSplitFirstLine(File file) throws IOException { return Files.asCharSource(file, StandardCharsets.UTF_8).readFirstLine().trim().split("\\s+"); }
private String readRef(final File refFile) { // make sure no other thread changes the ref as we read it try { synchronized (refFile.getCanonicalPath().intern()) { return Files.asCharSource(refFile, CHARSET).readFirstLine(); } } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void testOfUrl() throws Exception { String fullPathToFile = "file:///" + System.getProperty("user.dir") + "/" + fileName; URL url = new URL(fullPathToFile); CharSource charSource = CharSources.ofUrl(url); assertEquals(charSource.readFirstLine(), "H\u0000e\u0000l\u0000l\u0000o\u0000"); }
@Test public void testOfUrlWithCharset() throws Exception { String fullPathToFile = "file:///" + System.getProperty("user.dir") + "/" + fileName; URL url = new URL(fullPathToFile); CharSource charSource = CharSources.ofUrl(url, Charsets.UTF_16LE); assertEquals(charSource.readFirstLine(), "Hello"); }
public void testOfFile() throws Exception { CharSource charSource = CharSources.ofFile(new File(fileName)); assertEquals(charSource.readFirstLine(), "H\u0000e\u0000l\u0000l\u0000o\u0000"); assertEquals(charSource.length(), 10); }
@Test public void testOfContentByteArray() throws Exception { byte[] inputText = "H\u0000e\u0000l\u0000l\u0000o\u0000".getBytes(Charsets.UTF_8); CharSource charSource = CharSources.ofContent(inputText); assertEquals(charSource.readFirstLine(), "H\u0000e\u0000l\u0000l\u0000o\u0000"); assertEquals(charSource.length(), 10); }
@Test public void testOfContentByteArrayWithCharset() throws Exception { byte[] inputText = "H\u0000e\u0000l\u0000l\u0000o\u0000".getBytes(Charsets.UTF_8); CharSource charSource = CharSources.ofContent(inputText, Charsets.UTF_16LE); assertEquals(charSource.readFirstLine(), "Hello"); assertEquals(charSource.length(), 5); } }
public void testOfFileWithCharset() throws Exception { CharSource charSource = CharSources.ofFile(new File(fileName), Charsets.UTF_16LE); assertEquals(charSource.readFirstLine(), "Hello"); assertEquals(charSource.length(), 5); }
@Test public void testOfContentString() throws Exception { CharSource charSource = CharSources.ofContent("H\u0000e\u0000l\u0000l\u0000o\u0000"); assertEquals(charSource.readFirstLine(), "H\u0000e\u0000l\u0000l\u0000o\u0000"); assertEquals(charSource.length(), 10); }
public void testOfPath() throws Exception { CharSource charSource = CharSources.ofPath(Paths.get(fileName)); assertEquals(charSource.readFirstLine(), "H\u0000e\u0000l\u0000l\u0000o\u0000"); assertEquals(charSource.length(), 10); }
public void testOfFileName() throws Exception { CharSource charSource = CharSources.ofFileName(fileName); assertEquals(charSource.readFirstLine(), "H\u0000e\u0000l\u0000l\u0000o\u0000"); assertEquals(charSource.length(), 10); }
public void testOfFileNameWithCharset() throws Exception { CharSource charSource = CharSources.ofFileName(fileName, Charsets.UTF_16LE); assertEquals(charSource.readFirstLine(), "Hello"); assertEquals(charSource.length(), 5); }