From 56b4d43eb015d97179a96cfdca410dccb196b445 Mon Sep 17 00:00:00 2001 From: Dan Yang Date: Wed, 29 Apr 2020 16:08:01 -0700 Subject: [PATCH] Database Plugin - Increase blob max length and attempt to render UTF-8 Summary: 512 is a pretty small blob length. Increasing it to 5120 and changing it to attempt to stringify UTF-8 if not ascii. Reviewed By: jknoxville Differential Revision: D21253132 fbshipit-source-id: 1cc9226b86a9b9ddfd73e29c8b0c04ac54b5b4b2 --- .../flipper/plugins/databases/ObjectMapper.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/facebook/flipper/plugins/databases/ObjectMapper.java b/android/src/main/java/com/facebook/flipper/plugins/databases/ObjectMapper.java index 72aa17f51..e92fb907b 100644 --- a/android/src/main/java/com/facebook/flipper/plugins/databases/ObjectMapper.java +++ b/android/src/main/java/com/facebook/flipper/plugins/databases/ObjectMapper.java @@ -24,11 +24,12 @@ import java.io.UnsupportedEncodingException; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; public class ObjectMapper { - private static final int MAX_BLOB_LENGTH = 512; - private static final String UNKNOWN_BLOB_LABEL = "{blob}"; + private static final int MAX_BLOB_LENGTH = 5120; + private static final String UNKNOWN_BLOB_LABEL_FORMAT = "{%d-byte %s blob}"; public static FlipperArray databaseListToFlipperArray( Collection databaseDescriptorHolderList) { @@ -229,9 +230,17 @@ public class ObjectMapper { } catch (UnsupportedEncodingException e) { // Fall through... } + } else { + // try UTF-8 + try { + return new String(blob, "UTF-8"); + } catch (UnsupportedEncodingException e) { + // Fall through... + } } + return String.format(Locale.US, UNKNOWN_BLOB_LABEL_FORMAT, blob.length, "binary"); } - return UNKNOWN_BLOB_LABEL; + return String.format(Locale.US, UNKNOWN_BLOB_LABEL_FORMAT, blob.length, "large"); } private static boolean fastIsAscii(byte[] blob) {