public final class

Dumper

extends java.lang.Object

 java.lang.Object

↳androidx.media3.test.utils.Dumper

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-test-utils', version: '1.0.0-alpha03'

  • groupId: androidx.media3
  • artifactId: media3-test-utils
  • version: 1.0.0-alpha03

Artifact androidx.media3:media3-test-utils:1.0.0-alpha03 it located at Google repository (https://maven.google.com/)

Overview

Helper utility to dump field values.

Summary

Constructors
publicDumper()

Methods
public Dumperadd(Dumper.Dumpable object)

public Dumperadd(java.lang.String field, byte[] value[])

public Dumperadd(java.lang.String field, java.lang.Object value)

public DumperaddTime(java.lang.String field, long time)

public DumperendBlock()

public DumperstartBlock(java.lang.String name)

public java.lang.StringtoString()

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructors

public Dumper()

Methods

public Dumper add(java.lang.String field, java.lang.Object value)

public Dumper add(Dumper.Dumpable object)

public Dumper add(java.lang.String field, byte[] value[])

public Dumper addTime(java.lang.String field, long time)

public Dumper startBlock(java.lang.String name)

public Dumper endBlock()

public java.lang.String toString()

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.test.utils;

import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.util.UnstableApi;
import java.util.Arrays;
import java.util.Locale;

/** Helper utility to dump field values. */
@UnstableApi
public final class Dumper {

  /** Provides custom dump method. */
  public interface Dumpable {
    /**
     * Dumps the fields of the object using the {@code dumper}.
     *
     * @param dumper The {@link Dumper} to be used to dump fields.
     */
    void dump(Dumper dumper);
  }

  private static final int INDENT_SIZE_IN_SPACES = 2;

  private final StringBuilder sb;
  private int indent;

  public Dumper() {
    sb = new StringBuilder();
  }

  public Dumper add(String field, @Nullable Object value) {
    return addString(field + " = " + value + '\n');
  }

  public Dumper add(Dumpable object) {
    object.dump(this);
    return this;
  }

  public Dumper add(String field, @Nullable byte[] value) {
    String string =
        String.format(
            Locale.US,
            "%s = length %d, hash %X\n",
            field,
            value == null ? 0 : value.length,
            Arrays.hashCode(value));
    return addString(string);
  }

  public Dumper addTime(String field, long time) {
    return add(field, time == C.TIME_UNSET ? "UNSET TIME" : time);
  }

  public Dumper startBlock(String name) {
    addString(name + ":\n");
    indent += INDENT_SIZE_IN_SPACES;
    return this;
  }

  public Dumper endBlock() {
    indent -= INDENT_SIZE_IN_SPACES;
    return this;
  }

  @Override
  public String toString() {
    return sb.toString();
  }

  private Dumper addString(String string) {
    for (int i = 0; i < indent; i++) {
      sb.append(' ');
    }
    sb.append(string);
    return this;
  }
}