public final class Data

A persistable set of key/value pairs which are used as inputs and outputs for ListenableWorkers. Keys are Strings, and values can be Strings, primitive types, or their array variants.

This is a lightweight container, and should not be considered your data store. As such, there is an enforced .MAX_DATA_BYTES limit on the serialized (byte array) size of the payloads. This class will throw IllegalStateExceptions if you try to serialize or deserialize past this limit.

Summary

Constants

static final int

The maximum number of bytes for Data when it is serialized (converted to a byte array).

Public fields

static final @NonNull Data

An empty Data object with no elements.

Constants

MAX_DATA_BYTES

public static final int MAX_DATA_BYTES

The maximum number of bytes for Data when it is serialized (converted to a byte array). Please see the class-level Javadoc for more information.

Public fields

EMPTY

public static final @NonNull Data EMPTY

An empty Data object with no elements.

Public constructors

Public methods

getBoolean

public final boolean getBoolean(@NonNull String key, boolean defaultValue)

Gets the boolean value for the given key.

Parameters
@NonNull String key

The key for the argument

boolean defaultValue

The default value to return if the key is not found

Returns
boolean

The value specified by the key if it exists; the default value otherwise

getBooleanArray

public final boolean[] getBooleanArray(@NonNull String key)

Gets the boolean array value for the given key.

Returns
boolean[]

The value specified by the key if it exists; null otherwise

getByte

public final byte getByte(@NonNull String key, byte defaultValue)

Gets the byte value for the given key.

Parameters
@NonNull String key

The key for the argument

byte defaultValue

The default value to return if the key is not found

Returns
byte

The value specified by the key if it exists; the default value otherwise

getByteArray

public final byte[] getByteArray(@NonNull String key)

Gets the byte array value for the given key.

Returns
byte[]

The value specified by the key if it exists; null otherwise

getDouble

public final double getDouble(@NonNull String key, double defaultValue)

Gets the double value for the given key.

Parameters
@NonNull String key

The key for the argument

double defaultValue

The default value to return if the key is not found

Returns
double

The value specified by the key if it exists; the default value otherwise

getDoubleArray

public final double[] getDoubleArray(@NonNull String key)

Gets the double array value for the given key.

Returns
double[]

The value specified by the key if it exists; null otherwise

getFloat

public final float getFloat(@NonNull String key, float defaultValue)

Gets the float value for the given key.

Parameters
@NonNull String key

The key for the argument

float defaultValue

The default value to return if the key is not found

Returns
float

The value specified by the key if it exists; the default value otherwise

getFloatArray

public final float[] getFloatArray(@NonNull String key)

Gets the float array value for the given key.

Returns
float[]

The value specified by the key if it exists; null otherwise

getInt

public final int getInt(@NonNull String key, int defaultValue)

Gets the integer value for the given key.

Parameters
@NonNull String key

The key for the argument

int defaultValue

The default value to return if the key is not found

Returns
int

The value specified by the key if it exists; the default value otherwise

getIntArray

public final int[] getIntArray(@NonNull String key)

Gets the integer array value for the given key.

Returns
int[]

The value specified by the key if it exists; null otherwise

getLong

public final long getLong(@NonNull String key, long defaultValue)

Gets the long value for the given key.

Parameters
@NonNull String key

The key for the argument

long defaultValue

The default value to return if the key is not found

Returns
long

The value specified by the key if it exists; the default value otherwise

getLongArray

public final long[] getLongArray(@NonNull String key)

Gets the long array value for the given key.

Returns
long[]

The value specified by the key if it exists; null otherwise

getString

public final String getString(@NonNull String key)

Gets the String value for the given key.

Returns
String

The value specified by the key if it exists; null otherwise

getStringArray

public final String[] getStringArray(@NonNull String key)

Gets the String array value for the given key.

Returns
String[]

The value specified by the key if it exists; null otherwise

toByteArray

public final @NonNull byte[] toByteArray()

Converts this Data to a byte array suitable for sending to other processes in your application. There are no versioning guarantees with this byte array, so you should not use this for IPCs between applications or persistence.

Returns
@NonNull byte[]

The byte array representation of the input

Extension functions

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-01-30 UTC.