@Override public CharSource asCharSource(Charset charset) { if (options.length == 0) { // If no OpenOptions were passed, delegate to Files.lines, which could have performance // advantages. (If OpenOptions were passed we can't, because Files.lines doesn't have an // overload taking OpenOptions, meaning we can't guarantee the same behavior w.r.t. things // like following/not following symlinks. return new AsCharSource(charset) { @SuppressWarnings("FilesLinesLeak") // the user needs to close it in this case @Override public Stream<String> lines() throws IOException { return Files.lines(path, charset); } }; } return super.asCharSource(charset); }
@Override public CharSource asCharSource(Charset charset) { if (charset.equals(this.charset)) { return CharSource.this; } return super.asCharSource(charset); }
@Override public CharSource asCharSource(Charset charset) { if (options.length == 0) { // If no OpenOptions were passed, delegate to Files.lines, which could have performance // advantages. (If OpenOptions were passed we can't, because Files.lines doesn't have an // overload taking OpenOptions, meaning we can't guarantee the same behavior w.r.t. things // like following/not following symlinks. return new AsCharSource(charset) { @SuppressWarnings("FilesLinesLeak") // the user needs to close it in this case @Override public Stream<String> lines() throws IOException { return Files.lines(path, charset); } }; } return super.asCharSource(charset); }
ByteSource source = ... String text = source.asCharSource(Charsets.UTF_8).read();
@Override public CharSource asCharSource(Charset charset) { if (options.length == 0) { // If no OpenOptions were passed, delegate to Files.lines, which could have performance // advantages. (If OpenOptions were passed we can't, because Files.lines doesn't have an // overload taking OpenOptions, meaning we can't guarantee the same behavior w.r.t. things // like following/not following symlinks. return new AsCharSource(charset) { @SuppressWarnings("FilesLinesLeak") // the user needs to close it in this case @Override public Stream<String> lines() throws IOException { return Files.lines(path, charset); } }; } return super.asCharSource(charset); }
@Override public CharSource asCharSource(Charset charset) { if (charset.equals(this.charset)) { return CharSource.this; } return super.asCharSource(charset); }
/** * Returns a new {@link CharSource} for reading character data from the given file using the given * character set. * * @since 14.0 */ public static CharSource asCharSource(File file, Charset charset) { return asByteSource(file).asCharSource(charset); }
/** * Returns a {@link CharSource} that reads from the given URL using the given character set. * * @since 14.0 */ public static CharSource asCharSource(URL url, Charset charset) { return asByteSource(url).asCharSource(charset); }
/** * Returns a view of the given {@code path} as a {@link CharSource} using the given {@code * charset}. * * <p>Any {@linkplain OpenOption open options} provided are used when opening streams to the file * and may affect the behavior of the returned source and the streams it provides. See {@link * StandardOpenOption} for the standard options that may be provided. Providing no options is * equivalent to providing the {@link StandardOpenOption#READ READ} option. */ public static CharSource asCharSource(Path path, Charset charset, OpenOption... options) { return asByteSource(path, options).asCharSource(charset); }
@Override public CharSource asCharSource(Charset charset) { if (charset.equals(this.charset)) { return CharSource.this; } return super.asCharSource(charset); }
/** * Returns a new {@link CharSource} for reading character data from the given file using the given * character set. * * @since 14.0 */ public static CharSource asCharSource(File file, Charset charset) { return asByteSource(file).asCharSource(charset); }
/** * Returns a {@link CharSource} that reads from the given URL using the given character set. * * @since 14.0 */ public static CharSource asCharSource(URL url, Charset charset) { return asByteSource(url).asCharSource(charset); }
/** * Returns a view of the given {@code path} as a {@link CharSource} using the given {@code * charset}. * * <p>Any {@linkplain OpenOption open options} provided are used when opening streams to the file * and may affect the behavior of the returned source and the streams it provides. See {@link * StandardOpenOption} for the standard options that may be provided. Providing no options is * equivalent to providing the {@link StandardOpenOption#READ READ} option. */ public static CharSource asCharSource(Path path, Charset charset, OpenOption... options) { return asByteSource(path, options).asCharSource(charset); }
/** * Returns a new {@link CharSource} for reading character data from the given file using the given * character set. * * @since 14.0 */ public static CharSource asCharSource(File file, Charset charset) { return asByteSource(file).asCharSource(charset); }
/** * Returns a {@link CharSource} that reads from the given URL using the given character set. * * @since 14.0 */ public static CharSource asCharSource(URL url, Charset charset) { return asByteSource(url).asCharSource(charset); }
/** * Returns a view of the given {@code path} as a {@link CharSource} using the given {@code * charset}. * * <p>Any {@linkplain OpenOption open options} provided are used when opening streams to the file * and may affect the behavior of the returned source and the streams it provides. See {@link * StandardOpenOption} for the standard options that may be provided. Providing no options is * equivalent to providing the {@link StandardOpenOption#READ READ} option. */ public static CharSource asCharSource(Path path, Charset charset, OpenOption... options) { return asByteSource(path, options).asCharSource(charset); }
@Override public CharSource createSource(String string) throws IOException { return factory.createSource(string.getBytes(Charsets.UTF_8)).asCharSource(Charsets.UTF_8); }
public ExampleRecordCursor(List<ExampleColumnHandle> columnHandles, ByteSource byteSource) { this.columnHandles = columnHandles; fieldToColumnIndex = new int[columnHandles.size()]; for (int i = 0; i < columnHandles.size(); i++) { ExampleColumnHandle columnHandle = columnHandles.get(i); fieldToColumnIndex[i] = columnHandle.getOrdinalPosition(); } try (CountingInputStream input = new CountingInputStream(byteSource.openStream())) { lines = byteSource.asCharSource(UTF_8).readLines().iterator(); totalBytes = input.getCount(); } catch (IOException e) { throw new UncheckedIOException(e); } }
public static IncrementalIndex makeRealtimeIndex(final String resourceFilename, boolean rollup) { final URL resource = TestIndex.class.getClassLoader().getResource(resourceFilename); if (resource == null) { throw new IllegalArgumentException("cannot find resource " + resourceFilename); } log.info("Realtime loading index file[%s]", resource); CharSource stream = Resources.asByteSource(resource).asCharSource(StandardCharsets.UTF_8); return makeRealtimeIndex(stream, rollup); }
public void testRoundTripSources() throws Exception { File asciiFile = getTestFile("ascii.txt"); ByteSource byteSource = Files.asByteSource(asciiFile); assertSame(byteSource, byteSource.asCharSource(Charsets.UTF_8).asByteSource(Charsets.UTF_8)); }