@Test public void read_withFailureReading_closesStream() throws IOException { doThrow(new InvalidProtocolBufferException("")).when(parser).parseFrom(fileInputStream); protoStorageClient.read(parser).subscribe(); verify(fileInputStream).close(); }
public <T extends AbstractMessageLite> Maybe<T> read(Parser<T> parser) { return Maybe.fromCallable( () -> { synchronized (this) { try (FileInputStream inputStream = application.openFileInput(fileName)) { return parser.parseFrom(inputStream); } catch (InvalidProtocolBufferException | FileNotFoundException e) { Logging.logi("Recoverable exception while reading cache: " + e.getMessage()); return null; } } }); }
ProtoStorageClient { public <T extends AbstractMessageLite> Maybe<T> read(Parser<T> parser) { return Maybe.fromCallable( () -> { synchronized (this) { try (FileInputStream inputStream = application.openFileInput(fileName)) { return parser.parseFrom(inputStream); } catch (InvalidProtocolBufferException | FileNotFoundException e) { Logging.logi("Recoverable exception while reading cache: " + e.getMessage()); return null; } } }); } }
ProtoStorageClient { public <T extends AbstractMessageLite> Maybe<T> read(Parser<T> parser) { return Maybe.fromCallable( () -> { synchronized (this) { try (FileInputStream inputStream = application.openFileInput(fileName)) { return parser.parseFrom(inputStream); } catch (InvalidProtocolBufferException | FileNotFoundException e) { Logging.logi("Recoverable exception while reading cache: " + e.getMessage()); return null; } } }); } ProtoStorageClient(Application application, String fileName); }
ProtoStorageClient { public <T extends AbstractMessageLite> Maybe<T> read(Parser<T> parser) { return Maybe.fromCallable( () -> { synchronized (this) { try (FileInputStream inputStream = application.openFileInput(fileName)) { return parser.parseFrom(inputStream); } catch (InvalidProtocolBufferException | FileNotFoundException e) { Logging.logi("Recoverable exception while reading cache: " + e.getMessage()); return null; } } }); } ProtoStorageClient(Application application, String fileName); Completable write(AbstractMessageLite messageLite); Maybe<T> read(Parser<T> parser); }
ProtoStorageClient { public <T extends AbstractMessageLite> Maybe<T> read(Parser<T> parser) { return Maybe.fromCallable( () -> { synchronized (this) { try (FileInputStream inputStream = application.openFileInput(fileName)) { return parser.parseFrom(inputStream); } catch (InvalidProtocolBufferException | FileNotFoundException e) { Logging.logi("Recoverable exception while reading cache: " + e.getMessage()); return null; } } }); } ProtoStorageClient(Application application, String fileName); Completable write(AbstractMessageLite messageLite); Maybe<T> read(Parser<T> parser);  }