@@ -233,6 +233,24 @@ public int entrySize(String name) {
233233 * @return true for success, false for failure
234234 */
235235 public boolean writeObject (String name , Object o ) {
236+ return writeObject (name , o , true );
237+ }
238+
239+ /**
240+ * <p>Writes the given object to storage assuming it is an externalizable type
241+ * or one of the supported types.</p>
242+ *
243+ * <p>
244+ * The sample below demonstrates the usage and registration of the {@link com.codename1.io.Externalizable} interface:
245+ * </p>
246+ * <script src="https://gist.github.com/codenameone/858d8634e3cf1a82a1eb.js"></script>
247+ *
248+ * @param name store name
249+ * @param o object to store
250+ * @param includeLogging During app initialization, the logging on error might impact the apps stability
251+ * @return true for success, false for failure
252+ */
253+ public boolean writeObject (String name , Object o , boolean includeLogging ) {
236254 name = fixFileName (name );
237255 cache .put (name , o );
238256 DataOutputStream d = null ;
@@ -242,9 +260,11 @@ public boolean writeObject(String name, Object o) {
242260 d .close ();
243261 return true ;
244262 } catch (Exception err ) {
245- Log .e (err );
246- if (Log .isCrashBound ()) {
247- Log .sendLog ();
263+ if (includeLogging ) {
264+ Log .e (err );
265+ if (Log .isCrashBound ()) {
266+ Log .sendLog ();
267+ }
248268 }
249269 Util .getImplementation ().deleteStorageFile (name );
250270 Util .getImplementation ().cleanup (d );
@@ -263,6 +283,21 @@ public boolean writeObject(String name, Object o) {
263283 * @return object stored under that name
264284 */
265285 public Object readObject (String name ) {
286+ return readObject (name , true );
287+ }
288+
289+ /**
290+ * <p>Reads the object from the storage, returns null if the object isn't there</p>
291+ * <p>
292+ * The sample below demonstrates the usage and registration of the {@link com.codename1.io.Externalizable} interface:
293+ * </p>
294+ * <script src="https://gist.github.com/codenameone/858d8634e3cf1a82a1eb.js"></script>
295+ *
296+ * @param name name of the store
297+ * @param includeLogging During app initialization, the logging on error might impact the apps stability
298+ * @return object stored under that name
299+ */
300+ public Object readObject (String name , boolean includeLogging ) {
266301 name = fixFileName (name );
267302 Object o = cache .get (name );
268303 if (o != null ) {
@@ -279,10 +314,12 @@ public Object readObject(String name) {
279314 cache .put (name , o );
280315 return o ;
281316 } catch (Throwable err ) {
282- Log .p ("Error while reading: " + name );
283- Log .e (err );
284- if (Log .isCrashBound ()) {
285- Log .sendLog ();
317+ if (includeLogging ) {
318+ Log .p ("Error while reading: " + name );
319+ Log .e (err );
320+ if (Log .isCrashBound ()) {
321+ Log .sendLog ();
322+ }
286323 }
287324 Util .getImplementation ().cleanup (d );
288325 return null ;
0 commit comments