class AppMetadataBackupWriter {

    public void backupWidget(
            PackageInfo packageInfo, File metadataFile, File filesDir, byte[] widgetData)
            throws IOException {
        Preconditions.checkArgument(widgetData.length > 0, "Can't backup widget with no data.");

        String packageName = packageInfo.packageName;
        FileOutputStream fileOutputStream = new FileOutputStream(metadataFile);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
        DataOutputStream dataOutputStream = new DataOutputStream(bufferedOutputStream);

        byte[] metadata = getMetadataBytes(packageName);
        bufferedOutputStream.write(metadata); // bypassing DataOutputStream
        writeWidgetData(dataOutputStream, widgetData);
        bufferedOutputStream.flush();
        dataOutputStream.close();

        // As with the manifest file, guarantee consistency of the archive metadata for the widget
        // block by using a fixed last modified time on the metadata file.
        metadataFile.setLastModified(0);

        FullBackup.backupToTar(
                packageName,
                /* domain */ null,
                /* linkDomain */ null,
                filesDir.getAbsolutePath(),
                metadataFile.getAbsolutePath(),
                mOutput);
    }

    public  AppMetadataBackupWriter(FullBackupDataOutput output, PackageManager packageManager);

}