I don’t think it’s possible with TextIO but you can create your own 
FileIO.Sink<String> and use it together with FileIO

Something like:

p.apply(FileIO.<String>write().to(“/path/to/output").via(new MySink()));
public static class MySink implements FileIO.Sink<String> {

  private transient @Nullable PrintWriter writer;

  @Override
  public void open(WritableByteChannel channel) throws IOException {
    writer = new PrintWriter(
        new BufferedWriter(new 
OutputStreamWriter(Channels.newOutputStream(channel), UTF_8)));
  }

  @Override
  public void write(String element) throws IOException {
    writer.print(element);
  }

  @Override
  public void flush() throws IOException {
    writer.flush();
  }
}


> On 19 Feb 2021, at 07:25, Pradyumna Achar <[email protected]> wrote:
> 
> Hi everyone,
> 
> TextIO adds an extra newline to every element. Is there a way to avoid it? 
> If I write a 10-byte file, I get 11 bytes in the destination (with that extra 
> newline)
> 
> https://github.com/apache/beam/blob/f09f2afa25299cf0af67476e10f0deb330b7b810/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextIO.java#L1300
>  
> <https://github.com/apache/beam/blob/f09f2afa25299cf0af67476e10f0deb330b7b810/sdks/java/core/src/main/java/org/apache/beam/sdk/io/TextIO.java#L1300>
> 
> Thank you
> Regards
> Pradyumna

Reply via email to