@Test public void read_emptyFile_returnsNull() throws Exception { ConfigContainer container = storageClient.read(); assertThat(container).isNull(); }
@Nullable public synchronized ConfigContainer read() throws IOException { FileInputStream fileInputStream = null; try { fileInputStream = context.openFileInput(fileName); byte[] bytes = new byte[fileInputStream.available()]; fileInputStream.read(bytes, 0, bytes.length); String containerJsonString = new String(bytes, JSON_STRING_ENCODING); JSONObject containerJson = new JSONObject(containerJsonString); return ConfigContainer.copyOf(containerJson); } catch (JSONException | FileNotFoundException e) { return null; } finally { if (fileInputStream != null) fileInputStream.close(); } }
ConfigStorageClient { @Nullable public synchronized ConfigContainer read() throws IOException { FileInputStream fileInputStream = null; try { fileInputStream = context.openFileInput(fileName); byte[] bytes = new byte[fileInputStream.available()]; fileInputStream.read(bytes, 0, bytes.length); String containerJsonString = new String(bytes, JSON_STRING_ENCODING); JSONObject containerJson = new JSONObject(containerJsonString); return ConfigContainer.copyOf(containerJson); } catch (JSONException | FileNotFoundException e) { return null; } finally { if (fileInputStream != null) fileInputStream.close(); } } }
ConfigStorageClient { @Nullable public synchronized ConfigContainer read() throws IOException { FileInputStream fileInputStream = null; try { fileInputStream = context.openFileInput(fileName); byte[] bytes = new byte[fileInputStream.available()]; fileInputStream.read(bytes, 0, bytes.length); String containerJsonString = new String(bytes, JSON_STRING_ENCODING); JSONObject containerJson = new JSONObject(containerJsonString); return ConfigContainer.copyOf(containerJson); } catch (JSONException | FileNotFoundException e) { return null; } finally { if (fileInputStream != null) fileInputStream.close(); } } private  ConfigStorageClient(Context context, String fileName); }
ConfigStorageClient { @Nullable public synchronized ConfigContainer read() throws IOException { FileInputStream fileInputStream = null; try { fileInputStream = context.openFileInput(fileName); byte[] bytes = new byte[fileInputStream.available()]; fileInputStream.read(bytes, 0, bytes.length); String containerJsonString = new String(bytes, JSON_STRING_ENCODING); JSONObject containerJson = new JSONObject(containerJsonString); return ConfigContainer.copyOf(containerJson); } catch (JSONException | FileNotFoundException e) { return null; } finally { if (fileInputStream != null) fileInputStream.close(); } } private  ConfigStorageClient(Context context, String fileName); synchronized Void write(ConfigContainer container); @Nullable synchronized ConfigContainer read(); synchronized Void clear(); static synchronized ConfigStorageClient getInstance(Context context, String fileName); @VisibleForTesting static synchronized void clearInstancesForTest(); }
ConfigStorageClient { @Nullable public synchronized ConfigContainer read() throws IOException { FileInputStream fileInputStream = null; try { fileInputStream = context.openFileInput(fileName); byte[] bytes = new byte[fileInputStream.available()]; fileInputStream.read(bytes, 0, bytes.length); String containerJsonString = new String(bytes, JSON_STRING_ENCODING); JSONObject containerJson = new JSONObject(containerJsonString); return ConfigContainer.copyOf(containerJson); } catch (JSONException | FileNotFoundException e) { return null; } finally { if (fileInputStream != null) fileInputStream.close(); } } private  ConfigStorageClient(Context context, String fileName); synchronized Void write(ConfigContainer container); @Nullable synchronized ConfigContainer read(); synchronized Void clear(); static synchronized ConfigStorageClient getInstance(Context context, String fileName); @VisibleForTesting static synchronized void clearInstancesForTest();  }