Search in sources :

Example 1 with GzipUtil.compressString

use of com.microsoft.identity.common.internal.util.GzipUtil.compressString in project microsoft-authentication-library-common-for-android by AzureAD.

the class MsalBrokerResultAdapter method bundleFromAccounts.

@NonNull
public Bundle bundleFromAccounts(@NonNull final List<ICacheRecord> cacheRecords, @Nullable final String negotiatedProtocolVersion) {
    final Bundle resultBundle = new Bundle();
    final String jsonString = JsonExtensions.getJsonStringFromICacheRecordList(cacheRecords);
    if (BrokerProtocolVersionUtil.canCompressBrokerPayloads(negotiatedProtocolVersion)) {
        try {
            byte[] bytes = GzipUtil.compressString(jsonString);
            Logger.info(TAG, "Get accounts, raw payload size :" + jsonString.getBytes().length + " compressed size " + bytes.length);
            resultBundle.putByteArray(BROKER_ACCOUNTS_COMPRESSED, bytes);
        } catch (IOException e) {
            Logger.error(TAG, " Failed to compress account list to bytes, sending as jsonString", e);
            resultBundle.putString(BROKER_ACCOUNTS, jsonString);
        }
    } else {
        Logger.info(TAG, "Broker protocol version: " + negotiatedProtocolVersion + " lower than compression changes, sending as string");
        resultBundle.putString(BROKER_ACCOUNTS, jsonString);
    }
    return resultBundle;
}
Also used : Bundle(android.os.Bundle) GzipUtil.compressString(com.microsoft.identity.common.internal.util.GzipUtil.compressString) IOException(java.io.IOException) NonNull(androidx.annotation.NonNull)

Aggregations

Bundle (android.os.Bundle)1 NonNull (androidx.annotation.NonNull)1 GzipUtil.compressString (com.microsoft.identity.common.internal.util.GzipUtil.compressString)1 IOException (java.io.IOException)1