work/workmanager/src/main/java/androidx/work/Data.java
@TypeConverter
    public static @NonNull Data fromByteArray(@NonNull byte[] bytes) throws IllegalStateException {
        if (bytes.length > MAX_DATA_BYTES) {
            throw new IllegalStateException(
                    "Data cannot occupy more than " + MAX_DATA_BYTES + "KB when serialized");
        }

        Map<String, Object> map = new HashMap<>();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
        ObjectInputStream objectInputStream = null;
        try {
            objectInputStream = new ObjectInputStream(inputStream);
            for (int i = objectInputStream.readInt(); i > 0; i--) {
                map.put(objectInputStream.readUTF(), objectInputStream.readObject());
            }
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (objectInputStream != null) {
                try {
                    objectInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return new Data(map);
    }
/**
     * Converts a byte array to {@link Data}.
     *
     * @param bytes The byte array representation to convert
     * @return An {@link Data} object built from the input
     * @throws IllegalStateException if bytes is bigger than {@link #MAX_DATA_BYTES}
     */
Converts a byte array to  Data.
@param bytes The byte array representation to convert
@return An  Data object built from the input
@throws IllegalStateException if bytes is bigger than  #MAX_DATA_BYTES
Converts a byte array to Data . @param bytes The byte array representation to convert @return An Data object built from the input @throws IllegalStateException if bytes is bigger than #MAX_DATA_BYTES
@TypeConverter
    public static @NonNull Data fromByteArray(@NonNull byte[] bytes) throws IllegalStateException {
        if (bytes.length > MAX_DATA_BYTES) {
            throw new IllegalStateException(
                    "Data cannot occupy more than " + MAX_DATA_BYTES + "KB when serialized");
        }
        Map<String, Object> map = new HashMap<>();
        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
        ObjectInputStream objectInputStream = null;
        try {
            objectInputStream = new ObjectInputStream(inputStream);
            for (int i = objectInputStream.readInt(); i > 0; i--) {
                map.put(objectInputStream.readUTF(), objectInputStream.readObject());
            }
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (objectInputStream != null) {
                try {
                    objectInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return new Data(map);
    }
@ TypeConverter public static @ NonNull Data fromByteArray ( @ NonNull byte [ ] bytes ) throws IllegalStateException { if ( bytes . length > MAX_DATA_BYTES ) { throw new IllegalStateException ( "Data cannot occupy more than " + MAX_DATA_BYTES + "KB when serialized" ) ; } Map < String , Object > map = new HashMap < > ( ) ; ByteArrayInputStream inputStream = new ByteArrayInputStream ( bytes ) ; ObjectInputStream objectInputStream = null ; try { objectInputStream = new ObjectInputStream ( inputStream ) ; for ( int i = objectInputStream . readInt ( ) ; i > 0 ; i -- ) { map . put ( objectInputStream . readUTF ( ) , objectInputStream . readObject ( ) ) ; } } catch ( IOException | ClassNotFoundException e ) { e . printStackTrace ( ) ; } finally { if ( objectInputStream != null ) { try { objectInputStream . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } try { inputStream . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return new Data ( map ) ; }
Converts a byte array to {@link Data}.
Converts a byte array to { @link Data } .