backup_data:第X行的SKIP_PADDING FAILED [英] backup_data: SKIP_PADDING FAILED at line X

查看:119
本文介绍了backup_data:第X行的SKIP_PADDING FAILED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SharedPreferences的Google Backup API,如下所述:

I am using the Google Backup API for SharedPreferences as described here:

http://developer.android.com/guide/topics/data/backup.html#RequestingRestore

使用bmgr时,如下所述: http://developer.android.com/tools/help/bmgr.html

When using bmgr, as described here: http://developer.android.com/tools/help/bmgr.html

我确实获得了onRestore和onBackup方法的日志消息,但是在onRestore中,我得到了这一行:

I do get the log messages for onRestore an onBackup methods, but in onRestore I get this line:

06-06 11:24:16.546: D/backup_data(24615): SKIP_PADDING FAILED at line 332

唯一的参考在这里: https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp

The only reference for it is here: https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp

并且没有读取任何输入.

And no input is read.

我的助手类:

public class NoteBackupAgent extends BackupAgentHelper {

    public static final Object[] DATA_LOCK = new Object[0];
    private static final String PREFS_BACKUP_KEY = Const.ENTRY_PREFS;

    @Override
    public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
            ParcelFileDescriptor newState) throws IOException {

        Log.d(toString(), "########### onBackup() " + oldState.getStatSize());

        synchronized (DATA_LOCK) {
            super.onBackup(oldState, data, newState);
        }
    }

    @Override
    public void onCreate() {
        SharedPreferencesBackupHelper preferencesHelper = new SharedPreferencesBackupHelper(this,
                getPackageName() + "_preferences");
        Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_LONG).show();
        addHelper(PREFS_BACKUP_KEY, preferencesHelper);

    }

    @Override
    public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
            throws IOException {

        synchronized (DATA_LOCK) {
            //super.onRestore(data, appVersionCode, newState);

            // There should be only one entity, but the safest
            // way to consume it is using a while loop
            StringBuilder total = new StringBuilder();

            while (data.readNextHeader()) {
                String key = data.getKey();
                int dataSize = data.getDataSize();

                // If the key is ours (for saving top score). Note this key was used when
                // we wrote the backup entity header
                if (PREFS_BACKUP_KEY.equals(key)) {
                    // Create an input stream for the BackupDataInput
                    byte[] dataBuf = new byte[dataSize];
                    data.readEntityData(dataBuf, 0, dataSize);
                    ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
                    DataInputStream in = new DataInputStream(baStream);

                    BufferedReader r = new BufferedReader(new InputStreamReader(in));

                    String line;
                    while ((line = r.readLine()) != null) {
                        total.append(line);
                    }
                    Log.d(toString(), "########## data " + total);
                } else {
                    data.skipEntityData();
                }
            }

            Log.d(toString(), "########## onRestore()" + total.toString());
        }
    }

}

推荐答案

在我们的案例中,该解决方案阻止对共享首选项中存储的值强制实施Base64编码. 如您所愿@Demonick, https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp 是导致错误的原因,BackupDataReader :: skip_padding()使用Base32编码填充.

In our case the solution was preventing enforcing Base64 encodings on the values stored in our shared preferences. As you mentoined @Demonick, https://github.com/comex/frash/blob/master/utils/utils/BackupData.cpp is the cause of the error, BackupDataReader::skip_padding() is using Base32 encoding for paddings.

结论是: 禁止使用Base64.encodeToString(input,Base64.NO_PADDING)编写共享首选项.

Conclusion is: Prevent using Base64.encodeToString(input, Base64.NO_PADDING) for writing shared preferences.

这篇关于backup_data:第X行的SKIP_PADDING FAILED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆