private List<TopicPartition> listPartitionInfos(
            Admin client,
            TopicPartitionFilter topicPartitionFilter,
            boolean excludeInternalTopics
    ) throws ExecutionException, InterruptedException {
        ListTopicsOptions listTopicsOptions = new ListTopicsOptions().listInternal(!excludeInternalTopics);
        Set<String> topics = client.listTopics(listTopicsOptions).names().get();
        Set<String> filteredTopics = topics.stream().filter(topicPartitionFilter::isTopicAllowed).collect(Collectors.toSet());

        return client.describeTopics(filteredTopics).allTopicNames().get().entrySet().stream().flatMap(
                topic -> topic.getValue().partitions().stream().map(
                        tp -> new TopicPartition(topic.getKey(), tp.partition())
                ).filter(topicPartitionFilter::isTopicPartitionAllowed)
        ).collect(Collectors.toList());
    }
Return the partition infos. Filter them with topicPartitionFilter.
tools/src/main/java/org/apache/kafka/tools/GetOffsetShell.java