private Map<TopicPartition, LogOffsetResult> getLogOffsets(Collection<TopicPartition> topicPartitions, OffsetSpec offsetSpec) {
            try {
                Map<TopicPartition, OffsetSpec> startOffsets = topicPartitions.stream()
                    .collect(Collectors.toMap(Function.identity(), tp -> offsetSpec));

                Map<TopicPartition, ListOffsetsResultInfo> offsets = adminClient.listOffsets(
                    startOffsets,
                    withTimeoutMs(new ListOffsetsOptions())
                ).all().get();

                return topicPartitions.stream().collect(Collectors.toMap(
                    Function.identity(),
                    tp -> offsets.containsKey(tp)
                        ? new LogOffset(offsets.get(tp).offset())
                        : new Unknown()
                ));
            } catch (InterruptedException | ExecutionException e) {
                throw new RuntimeException(e);
            }
        }
Returns states of the specified consumer groups and partition assignment states
tools/src/main/java/org/apache/kafka/tools/consumer/group/ConsumerGroupCommand.java