title: Twitter4J: How do I return the tweets printed by sample/filter methods?
body: <p><strong>What I am doing?</strong><br>
  I am trying to build an application with a User Interface. The user will enter the search term and then using a websocket connection, I would start returning the filtered tweets to UI.</p>
  
  <p><strong>What I did?</strong><br>
  I have a <code>TwitterFilter</code> class that looks like  </p>
  
  <pre><code>public TwitterFilter(String searchTerm) {
          final ConfigurationBuilder configurationBuilder = getConfigurationBuilder();
  
          twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance();
          final StatusListener statusListener = getStatusListener();
  
          filterQuery = new FilterQuery();
          filterQuery.track(new String[] { searchTerm });
          filterQuery.language(new String[] { "en" });
          twitterStream.addListener(statusListener);
  
      }
  
      public void getFilteredTweets() {
          twitterStream.filter(filterQuery);
      }
  
      private static StatusListener getStatusListener() {
          return new StatusListener() {
              @Override
              public void onStatus(final Status status) {
                  System.out.println(status.getText());
              }
  
              @Override
              public void onDeletionNotice(final StatusDeletionNotice statusDeletionNotice) {
  
              }
  
              @Override
              public void onTrackLimitationNotice(final int i) {
  
              }
  
              @Override
              public void onScrubGeo(final long userId, final long upToStatusId) {
              }
  
              @Override
              public void onStallWarning(final StallWarning stallWarning) {
  
              }
  
              @Override
              public void onException(final Exception e) {
                  e.printStackTrace();
              }
          };
      }
  
      private static ConfigurationBuilder getConfigurationBuilder() {
          final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
          configurationBuilder.setDebugEnabled(true);
          configurationBuilder.setOAuthConsumerKey(CONSUMER_KEY);
          configurationBuilder.setOAuthConsumerSecret(CONSUMER_SECRET);
          configurationBuilder.setOAuthAccessToken(ACCESS_TOKEN);
          configurationBuilder.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);
          return configurationBuilder;
      }
  </code></pre>
  
  <p>and a class with websocket code, that needs to return tweets filtered by Twitter, looks as  </p>
  
  <pre><code>@ServerEndpoint("/tweets")
  public class TweetStreamServer {
      @OnMessage
      public void tweets(final String message, final Session client) throws IOException, InterruptedException {
          final TwitterFilter twitterFilter = new TwitterFilter("india");
          for (final Session peer: client.getOpenSessions()) {
              peer.getBasicRemote().sendText(twitterFilter.getFilteredTweets()); // compilation error
          }
      }
  }
  </code></pre>
  
  <p><strong>Problem?</strong><br>
  Since neither <code>filter()</code> or <code>sample()</code> methods return anything(<code>void</code>), how do I return the tweets? (<a href="http://twitter4j.org/javadoc/index.html?twitter4j/FilterQuery.html" rel="nofollow">documentation</a>)?</p>