work/workmanager/src/main/java/androidx/work/Data.java
@TypeConverter
    public static @NonNull byte[] toByteArray(@NonNull Data data) throws IllegalStateException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = null;
        try {
            objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeInt(data.size());
            for (Map.Entry<String, Object> entry : data.mValues.entrySet()) {
                objectOutputStream.writeUTF(entry.getKey());
                objectOutputStream.writeObject(entry.getValue());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (objectOutputStream != null) {
                try {
                    objectOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        if (outputStream.size() > MAX_DATA_BYTES) {
            throw new IllegalStateException(
                    "Data cannot occupy more than " + MAX_DATA_BYTES + "KB when serialized");
        }
        return outputStream.toByteArray();
    }
/**
     * Converts {@link Data} to a byte array for persistent storage.
     *
     * @param data The {@link Data} object to convert
     * @return The byte array representation of the input
     * @throws IllegalStateException if the serialized payload is bigger than
     *         {@link #MAX_DATA_BYTES}
     */
Converts  Data to a byte array for persistent storage.
@param data The  Data object to convert
@return The byte array representation of the input
@throws IllegalStateException if the serialized payload is bigger than
#MAX_DATA_BYTES
Converts Data to a byte array for persistent storage . @param data The Data object to convert @return The byte array representation of the input @throws IllegalStateException if the serialized payload is bigger than #MAX_DATA_BYTES
@TypeConverter
    public static @NonNull byte[] toByteArray(@NonNull Data data) throws IllegalStateException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = null;
        try {
            objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeInt(data.size());
            for (Map.Entry<String, Object> entry : data.mValues.entrySet()) {
                objectOutputStream.writeUTF(entry.getKey());
                objectOutputStream.writeObject(entry.getValue());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (objectOutputStream != null) {
                try {
                    objectOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (outputStream.size() > MAX_DATA_BYTES) {
            throw new IllegalStateException(
                    "Data cannot occupy more than " + MAX_DATA_BYTES + "KB when serialized");
        }
        return outputStream.toByteArray();
    }
@ TypeConverter public static @ NonNull byte [ ] toByteArray ( @ NonNull Data data ) throws IllegalStateException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; ObjectOutputStream objectOutputStream = null ; try { objectOutputStream = new ObjectOutputStream ( outputStream ) ; objectOutputStream . writeInt ( data . size ( ) ) ; for ( Map . Entry < String , Object > entry : data . mValues . entrySet ( ) ) { objectOutputStream . writeUTF ( entry . getKey ( ) ) ; objectOutputStream . writeObject ( entry . getValue ( ) ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { if ( objectOutputStream != null ) { try { objectOutputStream . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } try { outputStream . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } if ( outputStream . size ( ) > MAX_DATA_BYTES ) { throw new IllegalStateException ( "Data cannot occupy more than " + MAX_DATA_BYTES + "KB when serialized" ) ; } return outputStream . toByteArray ( ) ; }
Converts {@link Data} to a byte array for persistent storage.
Converts { @link Data } to a byte array for persistent storage .