title: Writing an an unbounded collection to GCS
body: <p>I have seen many questions on the same topic. But, I am still having problem with writing to GCS. I am reading the topic from pubsub and trying to push this to GCS. I have referred to <a href="https://stackoverflow.com/questions/40402150/write-each-row-received-over-pubsub-to-its-own-file-on-cloud-storage?noredirect=1&amp;lq=1">this link</a>. But, couldn't find the IOChannelUtils in the latest beam packages. </p>
  
  <pre><code>PCollection&lt;String&gt; details = pipeline
              .apply(PubsubIO.readStrings().fromTopic("/topics/&lt;project&gt;/sampleTopic"));
  
  PCollection&lt;KV&lt;String, String&gt;&gt; keyedStream = details.apply(WithKeys.of(new SerializableFunction&lt;String, String&gt;() {
          public String apply(String s) {
              return "constant";
          }
      }));
  
      PCollection&lt;KV&lt;String, Iterable&lt;String&gt;&gt;&gt; keyedWindows = keyedStream.apply(Window.&lt;KV&lt;String, String&gt;&gt;into(FixedWindows.of(ONE_MIN)).withAllowedLateness(ONE_DAY)
              .triggering(AfterWatermark.pastEndOfWindow().withEarlyFirings(AfterPane.elementCountAtLeast(10))
                      .withLateFirings(AfterFirst.of(AfterPane.elementCountAtLeast(10),
                              AfterProcessingTime.pastFirstElementInPane().plusDelayOf(TEN_SECONDS))))
              .discardingFiredPanes()).apply(GroupByKey.create());
  
      PCollection&lt;Iterable&lt;String&gt;&gt; windows = keyedWindows.apply(Values.create());
  </code></pre>
  
  <p>This I have taken from many other similar topics in stack overflow. Now, I understand that, TextIO do support unbounded PCollection write option with withWindowedWrites and withNumShards. </p>
  
  <p>ref : <a href="https://stackoverflow.com/questions/36509116/writing-to-google-cloud-storage-from-pubsub-using-cloud-dataflow-using-dofn">Writing to Google Cloud Storage from PubSub using Cloud Dataflow using DoFn</a></p>
  
  <p>But, I did not understand, how I should do this.</p>
  
  <p>I am trying to write to GCS as follows. </p>
  
  <pre><code>FilenamePolicy policy = DefaultFilenamePolicy.constructUsingStandardParameters(
              StaticValueProvider.of(outputDirectory), DefaultFilenamePolicy.DEFAULT_SHARD_TEMPLATE, "");
  
      details.apply(TextIO.write().to("gs://&lt;bucket&gt;/topicfile").withWindowedWrites()
              .withFilenamePolicy(policy).withNumShards(4));
  </code></pre>
  
  <p>I do not have sufficient points to add comments to those topics in Stack Overflow, hence I am raising it as a different question.</p>