/** * Returns a view of the given {@code path} as a {@link CharSink} 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 sink 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#CREATE CREATE}, {@link * StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} and {@link StandardOpenOption#WRITE * WRITE} options. */ public static CharSink asCharSink(Path path, Charset charset, OpenOption... options) { return asByteSink(path, options).asCharSink(charset); }
/** * Returns a view of the given {@code path} as a {@link CharSink} 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 sink 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#CREATE CREATE}, {@link * StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} and {@link StandardOpenOption#WRITE * WRITE} options. */ public static CharSink asCharSink(Path path, Charset charset, OpenOption... options) { return asByteSink(path, options).asCharSink(charset); }
@Override public ByteSink createSink() throws IOException { Path file = createFile(); if (initialBytes != null) { java.nio.file.Files.write(file, initialBytes); return MoreFiles.asByteSink(file, StandardOpenOption.APPEND); } return MoreFiles.asByteSink(file); }
/** * Returns a view of the given {@code path} as a {@link CharSink} 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 sink 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#CREATE CREATE}, {@link * StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} and {@link StandardOpenOption#WRITE * WRITE} options. */ public static CharSink asCharSink(Path path, Charset charset, OpenOption... options) { return asByteSink(path, options).asCharSink(charset); }
/** * Returns a view of the given {@code path} as a {@link CharSink} 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 sink 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#CREATE CREATE}, {@link * StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} and {@link StandardOpenOption#WRITE * WRITE} options. */ public static CharSink asCharSink(Path path, Charset charset, OpenOption... options) { return asByteSink(path, options).asCharSink(charset); }
/** * Returns a view of the given {@code path} as a {@link CharSink} 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 sink 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#CREATE CREATE}, {@link * StandardOpenOption#TRUNCATE_EXISTING TRUNCATE_EXISTING} and {@link StandardOpenOption#WRITE * WRITE} options. */ public static CharSink asCharSink(Path path, Charset charset, OpenOption... options) { return asByteSink(path, options).asCharSink(charset); }
@Override public ByteSink createSink() throws IOException { Path file = createFile(); if (initialBytes != null) { java.nio.file.Files.write(file, initialBytes); return MoreFiles.asByteSink(file, StandardOpenOption.APPEND); } return MoreFiles.asByteSink(file); }