target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void displayReportData_setsReportTextViewVisibilityToVisible_andSetsText() throws Exception { testSubject.displayReportData(DUMMY_REPORT_DATA); verify(displayReportTextView).setVisibility(View.VISIBLE); verify(displayReportTextView).setText(DUMMY_REPORT_DATA); }
|
@Override public void displayReportData(CharSequence report) { displayReportTextView.setVisibility(View.VISIBLE); displayReportTextView.setText(report); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportData(CharSequence report) { displayReportTextView.setVisibility(View.VISIBLE); displayReportTextView.setText(report); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportData(CharSequence report) { displayReportTextView.setVisibility(View.VISIBLE); displayReportTextView.setText(report); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportData(CharSequence report) { displayReportTextView.setVisibility(View.VISIBLE); displayReportTextView.setText(report); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportData(CharSequence report) { displayReportTextView.setVisibility(View.VISIBLE); displayReportTextView.setText(report); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void displayReportError_displaysToastWithCorrectErrorMessage() throws Exception { String expected = RuntimeEnvironment.application.getString(R.string.lobby_report_error_text); testSubject.displayReportError(); assertThat(ShadowToast.getTextOfLatestToast(), is(expected)); }
|
@Override public void displayReportError() { Toast.makeText(this, R.string.lobby_report_error_text, Toast.LENGTH_LONG).show(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportError() { Toast.makeText(this, R.string.lobby_report_error_text, Toast.LENGTH_LONG).show(); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportError() { Toast.makeText(this, R.string.lobby_report_error_text, Toast.LENGTH_LONG).show(); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportError() { Toast.makeText(this, R.string.lobby_report_error_text, Toast.LENGTH_LONG).show(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayReportError() { Toast.makeText(this, R.string.lobby_report_error_text, Toast.LENGTH_LONG).show(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void hideReportData_setsReportTextViewVisibilityToGone() throws Exception { testSubject.hideReportData(); verify(displayReportTextView).setVisibility(View.GONE); }
|
@Override public void hideReportData() { displayReportTextView.setVisibility(View.GONE); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideReportData() { displayReportTextView.setVisibility(View.GONE); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideReportData() { displayReportTextView.setVisibility(View.GONE); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideReportData() { displayReportTextView.setVisibility(View.GONE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideReportData() { displayReportTextView.setVisibility(View.GONE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void displayLoadingIndicator_setsLoadingIndicatorVisibilityToVisible() throws Exception { testSubject.displayLoadingIndicator(); verify(loadingIndicator).setVisibility(View.VISIBLE); }
|
@Override public void displayLoadingIndicator() { loadingIndicator.setVisibility(View.VISIBLE); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayLoadingIndicator() { loadingIndicator.setVisibility(View.VISIBLE); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayLoadingIndicator() { loadingIndicator.setVisibility(View.VISIBLE); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayLoadingIndicator() { loadingIndicator.setVisibility(View.VISIBLE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void displayLoadingIndicator() { loadingIndicator.setVisibility(View.VISIBLE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void hideLoadingIndicator_setsLoadingIndicatorVisibilityToGone() throws Exception { testSubject.hideLoadingIndicator(); verify(loadingIndicator).setVisibility(View.GONE); }
|
@Override public void hideLoadingIndicator() { loadingIndicator.setVisibility(View.GONE); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideLoadingIndicator() { loadingIndicator.setVisibility(View.GONE); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideLoadingIndicator() { loadingIndicator.setVisibility(View.GONE); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideLoadingIndicator() { loadingIndicator.setVisibility(View.GONE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override public void hideLoadingIndicator() { loadingIndicator.setVisibility(View.GONE); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void generateReport_getsReportAsyncFromRepository() throws Exception { testSubject.generateReport(); verify(lobbyRepository).getReportAsync(); }
|
Single<String> generateReport() { return repository.getReportAsync(); }
|
LobbyReportUseCase { Single<String> generateReport() { return repository.getReportAsync(); } }
|
LobbyReportUseCase { Single<String> generateReport() { return repository.getReportAsync(); } @Inject LobbyReportUseCase(LobbyRepository repository); }
|
LobbyReportUseCase { Single<String> generateReport() { return repository.getReportAsync(); } @Inject LobbyReportUseCase(LobbyRepository repository); }
|
LobbyReportUseCase { Single<String> generateReport() { return repository.getReportAsync(); } @Inject LobbyReportUseCase(LobbyRepository repository); }
|
@Test public void getLocalReport_getsReportFromRepository() throws Exception { testSubject.getLocalReport(); verify(lobbyRepository).getReport(); }
|
String getLocalReport() { return repository.getReport(); }
|
LobbyReportUseCase { String getLocalReport() { return repository.getReport(); } }
|
LobbyReportUseCase { String getLocalReport() { return repository.getReport(); } @Inject LobbyReportUseCase(LobbyRepository repository); }
|
LobbyReportUseCase { String getLocalReport() { return repository.getReport(); } @Inject LobbyReportUseCase(LobbyRepository repository); }
|
LobbyReportUseCase { String getLocalReport() { return repository.getReport(); } @Inject LobbyReportUseCase(LobbyRepository repository); }
|
@Test public void generateReport_whenReportDataAvailable_displaysReportDataInView() throws Exception { when(lobbyReportUseCase.generateReport()).thenReturn(Single.just(DUMMY_REPORT_DATA)); testSubject.generateReport(); testScheduler.advanceTimeBy(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS); testScheduler.triggerActions(); verify(view).hideReportData(); verify(view).displayLoadingIndicator(); verify(view).hideLoadingIndicator(); verify(view).displayReportData(DUMMY_REPORT_DATA); verifyNoMoreInteractions(view); }
|
void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
@Test public void generateReport_whenReportDataError_displaysReportErrorInView() throws Exception { Throwable throwable = mock(Throwable.class); when(lobbyReportUseCase.generateReport()).thenReturn(Single.error(throwable)); testSubject.generateReport(); testScheduler.advanceTimeBy(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS); testScheduler.triggerActions(); verify(view).hideReportData(); verify(view).displayLoadingIndicator(); verify(view).hideLoadingIndicator(); verify(view).displayReportError(); verifyNoMoreInteractions(view); }
|
void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void generateReport() { addDisposable(lobbyReportUseCase.generateReport() .doOnSubscribe(s -> publishRequestState(RequestState.LOADING)) .subscribeOn(schedulersFacade.io()) .observeOn(schedulersFacade.ui()) .delay(REPORT_DELAY_MILLIS, TimeUnit.MILLISECONDS, schedulersFacade.ui()) .doOnSuccess(s -> publishRequestState(RequestState.COMPLETE)) .doOnError(t -> publishRequestState(RequestState.ERROR)) .subscribe(this::onReportDataAvailable, this::onReportDataError)); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
@Test public void onReportDataAvailable_displaysReportDataInView() throws Exception { testSubject.onReportDataAvailable(DUMMY_REPORT_DATA); verify(view).displayReportData(DUMMY_REPORT_DATA); }
|
void onReportDataAvailable(String report) { Timber.d("report data: %s", report); view.displayReportData(report); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataAvailable(String report) { Timber.d("report data: %s", report); view.displayReportData(report); } }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataAvailable(String report) { Timber.d("report data: %s", report); view.displayReportData(report); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataAvailable(String report) { Timber.d("report data: %s", report); view.displayReportData(report); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataAvailable(String report) { Timber.d("report data: %s", report); view.displayReportData(report); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
@Test public void onReportDataError_displaysReportErrorInView() throws Exception { testSubject.onReportDataError(null); verify(view).displayReportError(); }
|
void onReportDataError(Throwable throwable) { Timber.e(throwable, "report error"); view.displayReportError(); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataError(Throwable throwable) { Timber.e(throwable, "report error"); view.displayReportError(); } }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataError(Throwable throwable) { Timber.e(throwable, "report error"); view.displayReportError(); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataError(Throwable throwable) { Timber.e(throwable, "report error"); view.displayReportError(); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
LobbyPresenter extends BasePresenter<LobbyView> { void onReportDataError(Throwable throwable) { Timber.e(throwable, "report error"); view.displayReportError(); } @Inject LobbyPresenter(LobbyReportUseCase lobbyReportUseCase, SchedulersFacade schedulersFacade); }
|
@Test public void getReportAsync_onSuccess_returnsReportData() throws Exception { when(testSubject.getReportAsync()) .thenReturn(Single.just(LobbyRepositoryImpl.FAKE_REPORT_DATA)); TestObserver<String> testObserver = testSubject.getReportAsync().test(); testObserver.assertResult(LobbyRepositoryImpl.FAKE_REPORT_DATA); testObserver.assertComplete(); }
|
@Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } @Override Single<String> getReportAsync(); @Override String getReport(); }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } @Override Single<String> getReportAsync(); @Override String getReport(); }
|
@Test public void getReportAsync_onError_returnsError() throws Exception { when(testSubject.getReportAsync()) .thenReturn(Single.error(new RuntimeException())); TestObserver<String> testObserver = testSubject.getReportAsync().test(); testObserver.assertError(RuntimeException.class); }
|
@Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } @Override Single<String> getReportAsync(); @Override String getReport(); }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public Single<String> getReportAsync() { return Single.just(FAKE_REPORT_DATA); } @Override Single<String> getReportAsync(); @Override String getReport(); }
|
@Test public void getReport_returnsReportData() throws Exception { String result = testSubject.getReport(); assertThat(result, is(LobbyRepositoryImpl.FAKE_REPORT_DATA)); }
|
@Override public String getReport() { return FAKE_REPORT_DATA; }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public String getReport() { return FAKE_REPORT_DATA; } }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public String getReport() { return FAKE_REPORT_DATA; } }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public String getReport() { return FAKE_REPORT_DATA; } @Override Single<String> getReportAsync(); @Override String getReport(); }
|
LobbyRepositoryImpl implements LobbyRepository { @Override public String getReport() { return FAKE_REPORT_DATA; } @Override Single<String> getReportAsync(); @Override String getReport(); }
|
@Test public void onDestroy_callsOnViewDestroyedOnPresenter() throws Exception { testSubject.onDestroy(); verify(presenter).onViewDestroyed(); }
|
@Override protected void onDestroy() { presenter.onViewDestroyed(); super.onDestroy(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override protected void onDestroy() { presenter.onViewDestroyed(); super.onDestroy(); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override protected void onDestroy() { presenter.onViewDestroyed(); super.onDestroy(); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override protected void onDestroy() { presenter.onViewDestroyed(); super.onDestroy(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @Override protected void onDestroy() { presenter.onViewDestroyed(); super.onDestroy(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void onGenerateReportButtonClicked_callsGenerateReportOnPresenter() throws Exception { testSubject.onGenerateReportButtonClicked(); verify(presenter).generateReport(); }
|
@OnClick(R.id.generate_report) public void onGenerateReportButtonClicked() { presenter.generateReport(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @OnClick(R.id.generate_report) public void onGenerateReportButtonClicked() { presenter.generateReport(); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @OnClick(R.id.generate_report) public void onGenerateReportButtonClicked() { presenter.generateReport(); } }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @OnClick(R.id.generate_report) public void onGenerateReportButtonClicked() { presenter.generateReport(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
LobbyActivity extends AppCompatActivity implements LobbyView { @OnClick(R.id.generate_report) public void onGenerateReportButtonClicked() { presenter.generateReport(); } @OnClick(R.id.generate_report) void onGenerateReportButtonClicked(); @Override void displayReportData(CharSequence report); @Override void hideReportData(); @Override void displayReportError(); @Override void displayLoadingIndicator(); @Override void hideLoadingIndicator(); }
|
@Test public void topicValidatorTest() { try { Validators.checkTopic("Hello"); Validators.checkTopic("%RETRY%Hello"); Validators.checkTopic("_%RETRY%Hello"); Validators.checkTopic("-%RETRY%Hello"); Validators.checkTopic("223-%RETRY%Hello"); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(false); } }
|
public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { throw new MQClientException("the specified topic is blank", null); } if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( "the specified topic[%s] contains illegal characters, allowing only %s", topic, VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified topic is longer than topic max length 255.", null); } if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( String.format("the topic[%s] is conflict with default topic.", topic), null); } }
|
Validators { public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { throw new MQClientException("the specified topic is blank", null); } if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( "the specified topic[%s] contains illegal characters, allowing only %s", topic, VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified topic is longer than topic max length 255.", null); } if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( String.format("the topic[%s] is conflict with default topic.", topic), null); } } }
|
Validators { public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { throw new MQClientException("the specified topic is blank", null); } if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( "the specified topic[%s] contains illegal characters, allowing only %s", topic, VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified topic is longer than topic max length 255.", null); } if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( String.format("the topic[%s] is conflict with default topic.", topic), null); } } }
|
Validators { public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { throw new MQClientException("the specified topic is blank", null); } if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( "the specified topic[%s] contains illegal characters, allowing only %s", topic, VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified topic is longer than topic max length 255.", null); } if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( String.format("the topic[%s] is conflict with default topic.", topic), null); } } static String getGroupWithRegularExpression(String origin, String patternStr); static void checkGroup(String group); static boolean regularExpressionMatcher(String origin, Pattern pattern); static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer); static void checkTopic(String topic); }
|
Validators { public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { throw new MQClientException("the specified topic is blank", null); } if (!regularExpressionMatcher(topic, PATTERN)) { throw new MQClientException(String.format( "the specified topic[%s] contains illegal characters, allowing only %s", topic, VALID_PATTERN_STR), null); } if (topic.length() > CHARACTER_MAX_LENGTH) { throw new MQClientException("the specified topic is longer than topic max length 255.", null); } if (topic.equals(MixAll.DEFAULT_TOPIC)) { throw new MQClientException( String.format("the topic[%s] is conflict with default topic.", topic), null); } } static String getGroupWithRegularExpression(String origin, String patternStr); static void checkGroup(String group); static boolean regularExpressionMatcher(String origin, Pattern pattern); static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer); static void checkTopic(String topic); static final String VALID_PATTERN_STR; static final Pattern PATTERN; static final int CHARACTER_MAX_LENGTH; }
|
@Test public void test_flushConsumerOffset() throws Exception { BrokerController brokerController = new BrokerController( new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), new MessageStoreConfig()); boolean initResult = brokerController.initialize(); System.out.println("initialize " + initResult); brokerController.start(); ConsumerOffsetManager consumerOffsetManager = new ConsumerOffsetManager(brokerController); Random random = new Random(); for (int i = 0; i < 100; i++) { String group = "DIANPU_GROUP_" + i; for (int id = 0; id < 16; id++) { consumerOffsetManager.commitOffset(null, group, "TOPIC_A", id, random.nextLong() % 1024 * 1024 * 1024); consumerOffsetManager.commitOffset(null, group, "TOPIC_B", id, random.nextLong() % 1024 * 1024 * 1024); consumerOffsetManager.commitOffset(null, group, "TOPIC_C", id, random.nextLong() % 1024 * 1024 * 1024); } } consumerOffsetManager.persist(); brokerController.shutdown(); }
|
public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { String key = topic + TOPIC_GROUP_SEPARATOR + group; this.commitOffset(clientHost, key, queueId, offset); }
|
ConsumerOffsetManager extends ConfigManager { public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { String key = topic + TOPIC_GROUP_SEPARATOR + group; this.commitOffset(clientHost, key, queueId, offset); } }
|
ConsumerOffsetManager extends ConfigManager { public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { String key = topic + TOPIC_GROUP_SEPARATOR + group; this.commitOffset(clientHost, key, queueId, offset); } ConsumerOffsetManager(); ConsumerOffsetManager(BrokerController brokerController); }
|
ConsumerOffsetManager extends ConfigManager { public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { String key = topic + TOPIC_GROUP_SEPARATOR + group; this.commitOffset(clientHost, key, queueId, offset); } ConsumerOffsetManager(); ConsumerOffsetManager(BrokerController brokerController); void scanUnsubscribedTopic(); Set<String> whichTopicByConsumer(final String group); Set<String> whichGroupByTopic(final String topic); void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset); long queryOffset(final String group, final String topic, final int queueId); String encode(); @Override String configFilePath(); @Override void decode(String jsonString); String encode(final boolean prettyFormat); ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> getOffsetTable(); void setOffsetTable(ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> offsetTable); Map<Integer, Long> queryMinOffsetInAllGroup(final String topic, final String filterGroups); Map<Integer, Long> queryOffset(final String group, final String topic); void cloneOffset(final String srcGroup, final String destGroup, final String topic); }
|
ConsumerOffsetManager extends ConfigManager { public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { String key = topic + TOPIC_GROUP_SEPARATOR + group; this.commitOffset(clientHost, key, queueId, offset); } ConsumerOffsetManager(); ConsumerOffsetManager(BrokerController brokerController); void scanUnsubscribedTopic(); Set<String> whichTopicByConsumer(final String group); Set<String> whichGroupByTopic(final String topic); void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset); long queryOffset(final String group, final String topic, final int queueId); String encode(); @Override String configFilePath(); @Override void decode(String jsonString); String encode(final boolean prettyFormat); ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> getOffsetTable(); void setOffsetTable(ConcurrentHashMap<String, ConcurrentHashMap<Integer, Long>> offsetTable); Map<Integer, Long> queryMinOffsetInAllGroup(final String topic, final String filterGroups); Map<Integer, Long> queryOffset(final String group, final String topic); void cloneOffset(final String srcGroup, final String destGroup, final String topic); }
|
@Test public void test_flushTopicConfig() throws Exception { BrokerController brokerController = new BrokerController( new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), new MessageStoreConfig()); boolean initResult = brokerController.initialize(); System.out.println("initialize " + initResult); brokerController.start(); TopicConfigManager topicConfigManager = new TopicConfigManager(brokerController); TopicConfig topicConfig = topicConfigManager.createTopicInSendMessageMethod("TestTopic_SEND", MixAll.DEFAULT_TOPIC, null, 4, 0); assertTrue(topicConfig != null); System.out.println(topicConfig); for (int i = 0; i < 10; i++) { String topic = "UNITTEST-" + i; topicConfig = topicConfigManager .createTopicInSendMessageMethod(topic, MixAll.DEFAULT_TOPIC, null, 4, 0); assertTrue(topicConfig != null); } topicConfigManager.persist(); brokerController.shutdown(); }
|
public TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic, final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { TopicConfig topicConfig = null; boolean createNew = false; try { if (this.lockTopicConfigTable.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) { try { topicConfig = this.topicConfigTable.get(topic); if (topicConfig != null) return topicConfig; TopicConfig defaultTopicConfig = this.topicConfigTable.get(defaultTopic); if (defaultTopicConfig != null) { if (defaultTopic.equals(MixAll.DEFAULT_TOPIC)) { if (!this.brokerController.getBrokerConfig().isAutoCreateTopicEnable()) { defaultTopicConfig.setPerm(PermName.PERM_READ | PermName.PERM_WRITE); } } if (PermName.isInherited(defaultTopicConfig.getPerm())) { topicConfig = new TopicConfig(topic); int queueNums = clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig .getWriteQueueNums() : clientDefaultTopicQueueNums; if (queueNums < 0) { queueNums = 0; } topicConfig.setReadQueueNums(queueNums); topicConfig.setWriteQueueNums(queueNums); int perm = defaultTopicConfig.getPerm(); perm &= ~PermName.PERM_INHERIT; topicConfig.setPerm(perm); topicConfig.setTopicSysFlag(topicSysFlag); topicConfig.setTopicFilterType(defaultTopicConfig.getTopicFilterType()); } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " + remoteAddress); } } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] not exist." + " producer: " + remoteAddress); } if (topicConfig != null) { log.info("create new topic by default topic[" + defaultTopic + "], " + topicConfig + " producer: " + remoteAddress); this.topicConfigTable.put(topic, topicConfig); this.dataVersion.nextVersion(); createNew = true; this.persist(); } } finally { this.lockTopicConfigTable.unlock(); } } } catch (InterruptedException e) { log.error("createTopicInSendMessageMethod exception", e); } if (createNew) { this.brokerController.registerBrokerAll(false, true); } return topicConfig; }
|
TopicConfigManager extends ConfigManager { public TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic, final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { TopicConfig topicConfig = null; boolean createNew = false; try { if (this.lockTopicConfigTable.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) { try { topicConfig = this.topicConfigTable.get(topic); if (topicConfig != null) return topicConfig; TopicConfig defaultTopicConfig = this.topicConfigTable.get(defaultTopic); if (defaultTopicConfig != null) { if (defaultTopic.equals(MixAll.DEFAULT_TOPIC)) { if (!this.brokerController.getBrokerConfig().isAutoCreateTopicEnable()) { defaultTopicConfig.setPerm(PermName.PERM_READ | PermName.PERM_WRITE); } } if (PermName.isInherited(defaultTopicConfig.getPerm())) { topicConfig = new TopicConfig(topic); int queueNums = clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig .getWriteQueueNums() : clientDefaultTopicQueueNums; if (queueNums < 0) { queueNums = 0; } topicConfig.setReadQueueNums(queueNums); topicConfig.setWriteQueueNums(queueNums); int perm = defaultTopicConfig.getPerm(); perm &= ~PermName.PERM_INHERIT; topicConfig.setPerm(perm); topicConfig.setTopicSysFlag(topicSysFlag); topicConfig.setTopicFilterType(defaultTopicConfig.getTopicFilterType()); } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " + remoteAddress); } } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] not exist." + " producer: " + remoteAddress); } if (topicConfig != null) { log.info("create new topic by default topic[" + defaultTopic + "], " + topicConfig + " producer: " + remoteAddress); this.topicConfigTable.put(topic, topicConfig); this.dataVersion.nextVersion(); createNew = true; this.persist(); } } finally { this.lockTopicConfigTable.unlock(); } } } catch (InterruptedException e) { log.error("createTopicInSendMessageMethod exception", e); } if (createNew) { this.brokerController.registerBrokerAll(false, true); } return topicConfig; } }
|
TopicConfigManager extends ConfigManager { public TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic, final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { TopicConfig topicConfig = null; boolean createNew = false; try { if (this.lockTopicConfigTable.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) { try { topicConfig = this.topicConfigTable.get(topic); if (topicConfig != null) return topicConfig; TopicConfig defaultTopicConfig = this.topicConfigTable.get(defaultTopic); if (defaultTopicConfig != null) { if (defaultTopic.equals(MixAll.DEFAULT_TOPIC)) { if (!this.brokerController.getBrokerConfig().isAutoCreateTopicEnable()) { defaultTopicConfig.setPerm(PermName.PERM_READ | PermName.PERM_WRITE); } } if (PermName.isInherited(defaultTopicConfig.getPerm())) { topicConfig = new TopicConfig(topic); int queueNums = clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig .getWriteQueueNums() : clientDefaultTopicQueueNums; if (queueNums < 0) { queueNums = 0; } topicConfig.setReadQueueNums(queueNums); topicConfig.setWriteQueueNums(queueNums); int perm = defaultTopicConfig.getPerm(); perm &= ~PermName.PERM_INHERIT; topicConfig.setPerm(perm); topicConfig.setTopicSysFlag(topicSysFlag); topicConfig.setTopicFilterType(defaultTopicConfig.getTopicFilterType()); } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " + remoteAddress); } } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] not exist." + " producer: " + remoteAddress); } if (topicConfig != null) { log.info("create new topic by default topic[" + defaultTopic + "], " + topicConfig + " producer: " + remoteAddress); this.topicConfigTable.put(topic, topicConfig); this.dataVersion.nextVersion(); createNew = true; this.persist(); } } finally { this.lockTopicConfigTable.unlock(); } } } catch (InterruptedException e) { log.error("createTopicInSendMessageMethod exception", e); } if (createNew) { this.brokerController.registerBrokerAll(false, true); } return topicConfig; } TopicConfigManager(); TopicConfigManager(BrokerController brokerController); }
|
TopicConfigManager extends ConfigManager { public TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic, final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { TopicConfig topicConfig = null; boolean createNew = false; try { if (this.lockTopicConfigTable.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) { try { topicConfig = this.topicConfigTable.get(topic); if (topicConfig != null) return topicConfig; TopicConfig defaultTopicConfig = this.topicConfigTable.get(defaultTopic); if (defaultTopicConfig != null) { if (defaultTopic.equals(MixAll.DEFAULT_TOPIC)) { if (!this.brokerController.getBrokerConfig().isAutoCreateTopicEnable()) { defaultTopicConfig.setPerm(PermName.PERM_READ | PermName.PERM_WRITE); } } if (PermName.isInherited(defaultTopicConfig.getPerm())) { topicConfig = new TopicConfig(topic); int queueNums = clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig .getWriteQueueNums() : clientDefaultTopicQueueNums; if (queueNums < 0) { queueNums = 0; } topicConfig.setReadQueueNums(queueNums); topicConfig.setWriteQueueNums(queueNums); int perm = defaultTopicConfig.getPerm(); perm &= ~PermName.PERM_INHERIT; topicConfig.setPerm(perm); topicConfig.setTopicSysFlag(topicSysFlag); topicConfig.setTopicFilterType(defaultTopicConfig.getTopicFilterType()); } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " + remoteAddress); } } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] not exist." + " producer: " + remoteAddress); } if (topicConfig != null) { log.info("create new topic by default topic[" + defaultTopic + "], " + topicConfig + " producer: " + remoteAddress); this.topicConfigTable.put(topic, topicConfig); this.dataVersion.nextVersion(); createNew = true; this.persist(); } } finally { this.lockTopicConfigTable.unlock(); } } } catch (InterruptedException e) { log.error("createTopicInSendMessageMethod exception", e); } if (createNew) { this.brokerController.registerBrokerAll(false, true); } return topicConfig; } TopicConfigManager(); TopicConfigManager(BrokerController brokerController); boolean isSystemTopic(final String topic); Set<String> getSystemTopic(); boolean isTopicCanSendMessage(final String topic); TopicConfig selectTopicConfig(final String topic); TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic,
final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag); TopicConfig createTopicInSendMessageBackMethod(//
final String topic, //
final int clientDefaultTopicQueueNums,//
final int perm,//
final int topicSysFlag); void updateTopicUnitFlag(final String topic, final boolean unit); void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub); void updateTopicConfig(final TopicConfig topicConfig); void updateOrderTopicConfig(final KVTable orderKVTableFromNs); boolean isOrderTopic(final String topic); void deleteTopicConfig(final String topic); TopicConfigSerializeWrapper buildTopicConfigSerializeWrapper(); @Override String encode(); @Override String configFilePath(); @Override void decode(String jsonString); String encode(final boolean prettyFormat); DataVersion getDataVersion(); ConcurrentHashMap<String, TopicConfig> getTopicConfigTable(); }
|
TopicConfigManager extends ConfigManager { public TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic, final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag) { TopicConfig topicConfig = null; boolean createNew = false; try { if (this.lockTopicConfigTable.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) { try { topicConfig = this.topicConfigTable.get(topic); if (topicConfig != null) return topicConfig; TopicConfig defaultTopicConfig = this.topicConfigTable.get(defaultTopic); if (defaultTopicConfig != null) { if (defaultTopic.equals(MixAll.DEFAULT_TOPIC)) { if (!this.brokerController.getBrokerConfig().isAutoCreateTopicEnable()) { defaultTopicConfig.setPerm(PermName.PERM_READ | PermName.PERM_WRITE); } } if (PermName.isInherited(defaultTopicConfig.getPerm())) { topicConfig = new TopicConfig(topic); int queueNums = clientDefaultTopicQueueNums > defaultTopicConfig.getWriteQueueNums() ? defaultTopicConfig .getWriteQueueNums() : clientDefaultTopicQueueNums; if (queueNums < 0) { queueNums = 0; } topicConfig.setReadQueueNums(queueNums); topicConfig.setWriteQueueNums(queueNums); int perm = defaultTopicConfig.getPerm(); perm &= ~PermName.PERM_INHERIT; topicConfig.setPerm(perm); topicConfig.setTopicSysFlag(topicSysFlag); topicConfig.setTopicFilterType(defaultTopicConfig.getTopicFilterType()); } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] no perm, " + defaultTopicConfig.getPerm() + " producer: " + remoteAddress); } } else { log.warn("create new topic failed, because the default topic[" + defaultTopic + "] not exist." + " producer: " + remoteAddress); } if (topicConfig != null) { log.info("create new topic by default topic[" + defaultTopic + "], " + topicConfig + " producer: " + remoteAddress); this.topicConfigTable.put(topic, topicConfig); this.dataVersion.nextVersion(); createNew = true; this.persist(); } } finally { this.lockTopicConfigTable.unlock(); } } } catch (InterruptedException e) { log.error("createTopicInSendMessageMethod exception", e); } if (createNew) { this.brokerController.registerBrokerAll(false, true); } return topicConfig; } TopicConfigManager(); TopicConfigManager(BrokerController brokerController); boolean isSystemTopic(final String topic); Set<String> getSystemTopic(); boolean isTopicCanSendMessage(final String topic); TopicConfig selectTopicConfig(final String topic); TopicConfig createTopicInSendMessageMethod(final String topic, final String defaultTopic,
final String remoteAddress, final int clientDefaultTopicQueueNums, final int topicSysFlag); TopicConfig createTopicInSendMessageBackMethod(//
final String topic, //
final int clientDefaultTopicQueueNums,//
final int perm,//
final int topicSysFlag); void updateTopicUnitFlag(final String topic, final boolean unit); void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub); void updateTopicConfig(final TopicConfig topicConfig); void updateOrderTopicConfig(final KVTable orderKVTableFromNs); boolean isOrderTopic(final String topic); void deleteTopicConfig(final String topic); TopicConfigSerializeWrapper buildTopicConfigSerializeWrapper(); @Override String encode(); @Override String configFilePath(); @Override void decode(String jsonString); String encode(final boolean prettyFormat); DataVersion getDataVersion(); ConcurrentHashMap<String, TopicConfig> getTopicConfigTable(); }
|
@Test public void testBuildSubscriptionData() throws Exception { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3"); System.out.println(subscriptionData); }
|
public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } static URL classFile(final String className); static String simpleClassName(final String className); static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic,
String subString); }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } static URL classFile(final String className); static String simpleClassName(final String className); static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic,
String subString); }
|
@Test public void testSubscriptionData() throws Exception { SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3"); subscriptionData.setFilterClassSource("java hello"); String json = RemotingSerializable.toJson(subscriptionData, true); System.out.println(json); }
|
public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } static URL classFile(final String className); static String simpleClassName(final String className); static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic,
String subString); }
|
FilterAPI { public static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic, String subString) throws Exception { SubscriptionData subscriptionData = new SubscriptionData(); subscriptionData.setTopic(topic); subscriptionData.setSubString(subString); if (null == subString || subString.equals(SubscriptionData.SUB_ALL) || subString.length() == 0) { subscriptionData.setSubString(SubscriptionData.SUB_ALL); } else { String[] tags = subString.split("\\|\\|"); if (tags != null && tags.length > 0) { for (String tag : tags) { if (tag.length() > 0) { String trimString = tag.trim(); if (trimString.length() > 0) { subscriptionData.getTagsSet().add(trimString); subscriptionData.getCodeSet().add(trimString.hashCode()); } } } } else { throw new Exception("subString split error"); } } return subscriptionData; } static URL classFile(final String className); static String simpleClassName(final String className); static SubscriptionData buildSubscriptionData(final String consumerGroup, String topic,
String subString); }
|
@Test public void test_currentStackTrace() { System.out.println(UtilAll.currentStackTrace()); }
|
public static String currentStackTrace() { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : stackTrace) { sb.append("\n\t"); sb.append(ste.toString()); } return sb.toString(); }
|
UtilAll { public static String currentStackTrace() { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : stackTrace) { sb.append("\n\t"); sb.append(ste.toString()); } return sb.toString(); } }
|
UtilAll { public static String currentStackTrace() { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : stackTrace) { sb.append("\n\t"); sb.append(ste.toString()); } return sb.toString(); } }
|
UtilAll { public static String currentStackTrace() { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : stackTrace) { sb.append("\n\t"); sb.append(ste.toString()); } return sb.toString(); } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); }
|
UtilAll { public static String currentStackTrace() { StringBuilder sb = new StringBuilder(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement ste : stackTrace) { sb.append("\n\t"); sb.append(ste.toString()); } return sb.toString(); } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); static final String yyyy_MM_dd_HH_mm_ss; static final String yyyy_MM_dd_HH_mm_ss_SSS; static final String yyyyMMddHHmmss; }
|
@Test public void test_timeMillisToHumanString() { System.out.println(UtilAll.timeMillisToHumanString()); }
|
public static String timeMillisToHumanString() { return timeMillisToHumanString(System.currentTimeMillis()); }
|
UtilAll { public static String timeMillisToHumanString() { return timeMillisToHumanString(System.currentTimeMillis()); } }
|
UtilAll { public static String timeMillisToHumanString() { return timeMillisToHumanString(System.currentTimeMillis()); } }
|
UtilAll { public static String timeMillisToHumanString() { return timeMillisToHumanString(System.currentTimeMillis()); } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); }
|
UtilAll { public static String timeMillisToHumanString() { return timeMillisToHumanString(System.currentTimeMillis()); } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); static final String yyyy_MM_dd_HH_mm_ss; static final String yyyy_MM_dd_HH_mm_ss_SSS; static final String yyyyMMddHHmmss; }
|
@Test public void test_getpid() { int pid = UtilAll.getPid(); System.out.println("PID = " + pid); assertTrue(pid > 0); }
|
public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } }
|
UtilAll { public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } } }
|
UtilAll { public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } } }
|
UtilAll { public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); }
|
UtilAll { public static int getPid() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String name = runtime.getName(); try { return Integer.parseInt(name.substring(0, name.indexOf('@'))); } catch (Exception e) { return -1; } } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); static final String yyyy_MM_dd_HH_mm_ss; static final String yyyy_MM_dd_HH_mm_ss_SSS; static final String yyyyMMddHHmmss; }
|
@Test public void test_isBlank() { { boolean result = UtilAll.isBlank("Hello "); assertTrue(!result); } { boolean result = UtilAll.isBlank(" Hello"); assertTrue(!result); } { boolean result = UtilAll.isBlank("He llo"); assertTrue(!result); } { boolean result = UtilAll.isBlank(" "); assertTrue(result); } { boolean result = UtilAll.isBlank("Hello"); assertTrue(!result); } }
|
public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; }
|
UtilAll { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } }
|
UtilAll { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } }
|
UtilAll { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); }
|
UtilAll { public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } static int getPid(); static String currentStackTrace(); static String offset2FileName(final long offset); static long computeEclipseTimeMilliseconds(final long beginTime); static boolean isItTimeToDo(final String when); static String timeMillisToHumanString(); static String timeMillisToHumanString(final long t); static long computNextMorningTimeMillis(); static long computNextMinutesTimeMillis(); static long computNextHourTimeMillis(); static long computNextHalfHourTimeMillis(); static String timeMillisToHumanString2(final long t); static String timeMillisToHumanString3(final long t); static double getDiskPartitionSpaceUsedPercent(final String path); static final int crc32(byte[] array); static final int crc32(byte[] array, int offset, int length); static String bytes2string(byte[] src); static byte[] string2bytes(String hexString); static byte[] uncompress(final byte[] src); static byte[] compress(final byte[] src, final int level); static int asInt(String str, int defaultValue); static long asLong(String str, long defaultValue); static String formatDate(Date date, String pattern); static Date parseDate(String date, String pattern); static String responseCode2String(final int code); static String frontStringAtLeast(final String str, final int size); static boolean isBlank(String str); static String jstack(); static String jstack(Map<Thread, StackTraceElement[]> map); static boolean isInternalIP(byte[] ip); static String ipToIPv4Str(byte[] ip); static byte[] getIP(); static final String yyyy_MM_dd_HH_mm_ss; static final String yyyy_MM_dd_HH_mm_ss_SSS; static final String yyyyMMddHHmmss; }
|
@Test public void test() throws Exception { List<String> localInetAddress = MixAll.getLocalInetAddress(); String local = InetAddress.getLocalHost().getHostAddress(); Assert.assertTrue(localInetAddress.contains("127.0.0.1")); Assert.assertTrue(localInetAddress.contains(local)); }
|
public static List<String> getLocalInetAddress() { List<String> inetAddressList = new ArrayList<String>(); try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); Enumeration<InetAddress> addrs = networkInterface.getInetAddresses(); while (addrs.hasMoreElements()) { inetAddressList.add(addrs.nextElement().getHostAddress()); } } } catch (SocketException e) { throw new RuntimeException("get local inet address fail", e); } return inetAddressList; }
|
MixAll { public static List<String> getLocalInetAddress() { List<String> inetAddressList = new ArrayList<String>(); try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); Enumeration<InetAddress> addrs = networkInterface.getInetAddresses(); while (addrs.hasMoreElements()) { inetAddressList.add(addrs.nextElement().getHostAddress()); } } } catch (SocketException e) { throw new RuntimeException("get local inet address fail", e); } return inetAddressList; } }
|
MixAll { public static List<String> getLocalInetAddress() { List<String> inetAddressList = new ArrayList<String>(); try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); Enumeration<InetAddress> addrs = networkInterface.getInetAddresses(); while (addrs.hasMoreElements()) { inetAddressList.add(addrs.nextElement().getHostAddress()); } } } catch (SocketException e) { throw new RuntimeException("get local inet address fail", e); } return inetAddressList; } }
|
MixAll { public static List<String> getLocalInetAddress() { List<String> inetAddressList = new ArrayList<String>(); try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); Enumeration<InetAddress> addrs = networkInterface.getInetAddresses(); while (addrs.hasMoreElements()) { inetAddressList.add(addrs.nextElement().getHostAddress()); } } } catch (SocketException e) { throw new RuntimeException("get local inet address fail", e); } return inetAddressList; } static String getRetryTopic(final String consumerGroup); static boolean isSysConsumerGroup(final String consumerGroup); static boolean isSystemTopic(final String topic); static String getDLQTopic(final String consumerGroup); static String brokerVIPChannel(final boolean isChange, final String brokerAddr); static long getPID(); static long createBrokerId(final String ip, final int port); static final void string2File(final String str, final String fileName); static final void string2FileNotSafe(final String str, final String fileName); static final String file2String(final String fileName); static final String file2String(final File file); static final String file2String(final URL url); static String findClassPath(Class<?> c); static void printObjectProperties(final Logger log, final Object object); static void printObjectProperties(final Logger log, final Object object, final boolean onlyImportantField); static String properties2String(final Properties properties); static Properties string2Properties(final String str); static Properties object2Properties(final Object object); static void properties2Object(final Properties p, final Object object); static boolean isPropertiesEqual(final Properties p1, final Properties p2); static List<String> getLocalInetAddress(); static boolean isLocalAddr(String address); static boolean compareAndIncreaseOnly(final AtomicLong target, final long value); static String localhostName(); Set<String> list2Set(List<String> values); List<String> set2List(Set<String> values); }
|
MixAll { public static List<String> getLocalInetAddress() { List<String> inetAddressList = new ArrayList<String>(); try { Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface networkInterface = enumeration.nextElement(); Enumeration<InetAddress> addrs = networkInterface.getInetAddresses(); while (addrs.hasMoreElements()) { inetAddressList.add(addrs.nextElement().getHostAddress()); } } } catch (SocketException e) { throw new RuntimeException("get local inet address fail", e); } return inetAddressList; } static String getRetryTopic(final String consumerGroup); static boolean isSysConsumerGroup(final String consumerGroup); static boolean isSystemTopic(final String topic); static String getDLQTopic(final String consumerGroup); static String brokerVIPChannel(final boolean isChange, final String brokerAddr); static long getPID(); static long createBrokerId(final String ip, final int port); static final void string2File(final String str, final String fileName); static final void string2FileNotSafe(final String str, final String fileName); static final String file2String(final String fileName); static final String file2String(final File file); static final String file2String(final URL url); static String findClassPath(Class<?> c); static void printObjectProperties(final Logger log, final Object object); static void printObjectProperties(final Logger log, final Object object, final boolean onlyImportantField); static String properties2String(final Properties properties); static Properties string2Properties(final String str); static Properties object2Properties(final Object object); static void properties2Object(final Properties p, final Object object); static boolean isPropertiesEqual(final Properties p1, final Properties p2); static List<String> getLocalInetAddress(); static boolean isLocalAddr(String address); static boolean compareAndIncreaseOnly(final AtomicLong target, final long value); static String localhostName(); Set<String> list2Set(List<String> values); List<String> set2List(Set<String> values); static final String ROCKETMQ_HOME_ENV; static final String ROCKETMQ_HOME_PROPERTY; static final String NAMESRV_ADDR_ENV; static final String NAMESRV_ADDR_PROPERTY; static final String MESSAGE_COMPRESS_LEVEL; static final String WS_DOMAIN_NAME; static final String WS_DOMAIN_SUBGROUP; static final String WS_ADDR; static final String DEFAULT_TOPIC; static final String BENCHMARK_TOPIC; static final String DEFAULT_PRODUCER_GROUP; static final String DEFAULT_CONSUMER_GROUP; static final String TOOLS_CONSUMER_GROUP; static final String FILTERSRV_CONSUMER_GROUP; static final String MONITOR_CONSUMER_GROUP; static final String CLIENT_INNER_PRODUCER_GROUP; static final String SELF_TEST_PRODUCER_GROUP; static final String SELF_TEST_CONSUMER_GROUP; static final String SELF_TEST_TOPIC; static final String OFFSET_MOVED_EVENT; static final String ONS_HTTP_PROXY_GROUP; static final String CID_ONSAPI_PERMISSION_GROUP; static final String CID_ONSAPI_OWNER_GROUP; static final String CID_ONSAPI_PULL_GROUP; static final String CID_RMQ_SYS_PREFIX; static final List<String> LocalInetAddrs; static final String Localhost; static final String DEFAULT_CHARSET; static final long MASTER_ID; static final long CURRENT_JVM_PID; static final String RETRY_GROUP_TOPIC_PREFIX; static final String DLQ_GROUP_TOPIC_PREFIX; static final String SYSTEM_TOPIC_PREFIX; static final String UNIQUE_MSG_QUERY_FLAG; }
|
@Test public void parseModel_Pass_ParseMockedModelByClass() { JSONObject jsonObject = new JSONObject(); MockModelObject parsedResult = ModelUtils.deserializeModel(jsonObject, MockModelObject.class); assertNotNull(parsedResult); }
|
@NonNull static <T extends ModelObject> T deserializeModel(@NonNull JSONObject jsonObject, @NonNull Class<T> modelClass) { final ModelObject.Serializer<T> serializer = (ModelObject.Serializer<T>) ModelUtils.readModelSerializer(modelClass); return serializer.deserialize(jsonObject); }
|
ModelUtils { @NonNull static <T extends ModelObject> T deserializeModel(@NonNull JSONObject jsonObject, @NonNull Class<T> modelClass) { final ModelObject.Serializer<T> serializer = (ModelObject.Serializer<T>) ModelUtils.readModelSerializer(modelClass); return serializer.deserialize(jsonObject); } }
|
ModelUtils { @NonNull static <T extends ModelObject> T deserializeModel(@NonNull JSONObject jsonObject, @NonNull Class<T> modelClass) { final ModelObject.Serializer<T> serializer = (ModelObject.Serializer<T>) ModelUtils.readModelSerializer(modelClass); return serializer.deserialize(jsonObject); } private ModelUtils(); }
|
ModelUtils { @NonNull static <T extends ModelObject> T deserializeModel(@NonNull JSONObject jsonObject, @NonNull Class<T> modelClass) { final ModelObject.Serializer<T> serializer = (ModelObject.Serializer<T>) ModelUtils.readModelSerializer(modelClass); return serializer.deserialize(jsonObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @NonNull static <T extends ModelObject> T deserializeModel(@NonNull JSONObject jsonObject, @NonNull Class<T> modelClass) { final ModelObject.Serializer<T> serializer = (ModelObject.Serializer<T>) ModelUtils.readModelSerializer(modelClass); return serializer.deserialize(jsonObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@Test public void parseOptStringList_Pass_ParseEmptyArray() { JSONArray jsonArray = new JSONArray(); List<String> stringList = JsonUtils.parseOptStringList(jsonArray); Assert.assertNotNull(stringList); Assert.assertTrue(stringList.isEmpty()); }
|
@Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); @NonNull static String indent(@Nullable JSONObject jsonObject); static void writeToParcel(@NonNull Parcel parcel, @Nullable JSONObject jsonObject); @Nullable static JSONObject readFromParcel(@NonNull Parcel parcel); @Nullable static List<String> parseOptStringList(@Nullable JSONArray jsonArray); @Nullable static JSONArray serializeOptStringList(@Nullable List<String> stringList); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); @NonNull static String indent(@Nullable JSONObject jsonObject); static void writeToParcel(@NonNull Parcel parcel, @Nullable JSONObject jsonObject); @Nullable static JSONObject readFromParcel(@NonNull Parcel parcel); @Nullable static List<String> parseOptStringList(@Nullable JSONArray jsonArray); @Nullable static JSONArray serializeOptStringList(@Nullable List<String> stringList); static final int INDENTATION_SPACES; }
|
@SuppressWarnings("ConstantConditions") @Test public void parseOptStringList_Pass_ParseNull() { List<String> stringList = JsonUtils.parseOptStringList(null); Assert.assertNull(stringList); }
|
@Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); @NonNull static String indent(@Nullable JSONObject jsonObject); static void writeToParcel(@NonNull Parcel parcel, @Nullable JSONObject jsonObject); @Nullable static JSONObject readFromParcel(@NonNull Parcel parcel); @Nullable static List<String> parseOptStringList(@Nullable JSONArray jsonArray); @Nullable static JSONArray serializeOptStringList(@Nullable List<String> stringList); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); @NonNull static String indent(@Nullable JSONObject jsonObject); static void writeToParcel(@NonNull Parcel parcel, @Nullable JSONObject jsonObject); @Nullable static JSONObject readFromParcel(@NonNull Parcel parcel); @Nullable static List<String> parseOptStringList(@Nullable JSONArray jsonArray); @Nullable static JSONArray serializeOptStringList(@Nullable List<String> stringList); static final int INDENTATION_SPACES; }
|
@Test public void initBaseHttpUrl_Pass_HTTPS_ExpectSecureConnection() throws IOException { String url = "https: HttpURLConnection urlConnection = new BaseHttpUrlConnectionFactory() { @NonNull @Override HttpURLConnection handleInsecureConnection(@NonNull HttpURLConnection httpUrlConnection) { assertEquals(1, 2); return httpUrlConnection; } }.createHttpUrlConnection(url); assertEquals(urlConnection.getURL().toString(), url); }
|
@NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
@Test public void initBaseHttpUrl_Pass_HTTPS_ExpectInsecureConnection() throws IOException { final String url = "http: HttpURLConnection urlConnection = new BaseHttpUrlConnectionFactory() { @NonNull @Override HttpURLConnection handleInsecureConnection(@NonNull HttpURLConnection httpUrlConnection) { assertEquals(httpUrlConnection.getURL().toString(), url); return httpUrlConnection; } }.createHttpUrlConnection(url); }
|
@NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
BaseHttpUrlConnectionFactory { @NonNull HttpURLConnection createHttpUrlConnection(@NonNull String url) throws IOException { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); if (urlConnection instanceof HttpsURLConnection) { ((HttpsURLConnection) urlConnection).setSSLSocketFactory(TLS_SOCKET_FACTORY); return urlConnection; } else { return handleInsecureConnection(urlConnection); } } }
|
@Test public void parseOpt_Pass_ParseMockedModel() { JSONObject jsonObject = new JSONObject(); MockModelObject parsedResult = ModelUtils.deserializeOpt(jsonObject, MockModelObject.SERIALIZER); Assert.assertNotNull(parsedResult); }
|
@Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@SuppressWarnings("ConstantConditions") @Test public void parseOpt_Pass_ParseNull() { MockModelObject parsedResult = ModelUtils.deserializeOpt(null, MockModelObject.SERIALIZER); Assert.assertNull(parsedResult); }
|
@Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer) { return jsonObject == null ? null : serializer.deserialize(jsonObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@Test public void parseOptList_Pass_ParseMockedModel() { JSONArray jsonArray = new JSONArray(); List<MockModelObject> modelList = ModelUtils.deserializeOptList(jsonArray, MockModelObject.SERIALIZER); Assert.assertNotNull(modelList); }
|
@Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@SuppressWarnings("ConstantConditions") @Test public void parseOptList_Pass_ParseNull() { List<MockModelObject> modelList = ModelUtils.deserializeOptList(null, MockModelObject.SERIALIZER); Assert.assertNull(modelList); }
|
@Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer) { if (jsonArray == null) { return null; } final List<T> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final JSONObject itemJson = jsonArray.optJSONObject(i); if (itemJson != null) { final T item = serializer.deserialize(itemJson); list.add(item); } } return Collections.unmodifiableList(list); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@Test public void serializeOpt_Pass_SerializeMockedModel() { MockModelObject mockModelObject = new MockModelObject(); JSONObject jsonObject = ModelUtils.serializeOpt(mockModelObject, MockModelObject.SERIALIZER); Assert.assertNotNull(jsonObject); }
|
@Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@SuppressWarnings("ConstantConditions") @Test public void serializeOpt_Pass_SerializeNull() { JSONObject jsonObject = ModelUtils.serializeOpt(null, MockModelObject.SERIALIZER); Assert.assertNull(jsonObject); }
|
@Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer) { return modelObject == null ? null : serializer.serialize(modelObject); } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@Test public void serializeOptList_Pass_SerializeMockedModelList() { List<MockModelObject> modelObjectList = new ArrayList<>(); modelObjectList.add(new MockModelObject()); JSONArray jsonArray = ModelUtils.serializeOptList(modelObjectList, MockModelObject.SERIALIZER); Assert.assertNotNull(jsonArray); Assert.assertTrue(!jsonArray.isNull(0)); }
|
@Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@SuppressWarnings("ConstantConditions") @Test public void serializeOptList_Pass_SerializeNull() { JSONArray jsonArray = ModelUtils.serializeOptList(null, MockModelObject.SERIALIZER); Assert.assertNull(jsonArray); }
|
@Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } private ModelUtils(); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); }
|
ModelUtils { @Nullable public static <T extends ModelObject> JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer) { if (modelList == null || modelList.isEmpty()) { return null; } final JSONArray jsonArray = new JSONArray(); for (T model : modelList) { jsonArray.put(serializer.serialize(model)); } return jsonArray; } private ModelUtils(); @Nullable static T deserializeOpt(@Nullable JSONObject jsonObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static List<T> deserializeOptList(@Nullable JSONArray jsonArray, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONObject serializeOpt(@Nullable T modelObject, @NonNull ModelObject.Serializer<T> serializer); @Nullable static JSONArray serializeOptList(@Nullable List<T> modelList, @NonNull ModelObject.Serializer<T> serializer); static final String SERIALIZER_FIELD_NAME; }
|
@Test public void parseOptStringList_Pass_ParseStringArray() { JSONArray jsonArray = new JSONArray(); String testString = "Test"; jsonArray.put(testString); List<String> stringList = JsonUtils.parseOptStringList(jsonArray); Assert.assertNotNull(stringList); String first = stringList.get(0); Assert.assertEquals(testString, first); }
|
@Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); @NonNull static String indent(@Nullable JSONObject jsonObject); static void writeToParcel(@NonNull Parcel parcel, @Nullable JSONObject jsonObject); @Nullable static JSONObject readFromParcel(@NonNull Parcel parcel); @Nullable static List<String> parseOptStringList(@Nullable JSONArray jsonArray); @Nullable static JSONArray serializeOptStringList(@Nullable List<String> stringList); }
|
JsonUtils { @Nullable public static List<String> parseOptStringList(@Nullable JSONArray jsonArray) { if (jsonArray == null) { return null; } final List<String> list = new ArrayList<>(); for (int i = 0; i < jsonArray.length(); i++) { final String item = jsonArray.optString(i, null); if (item != null) { list.add(item); } } return Collections.unmodifiableList(list); } private JsonUtils(); @NonNull static String indent(@Nullable JSONObject jsonObject); static void writeToParcel(@NonNull Parcel parcel, @Nullable JSONObject jsonObject); @Nullable static JSONObject readFromParcel(@NonNull Parcel parcel); @Nullable static List<String> parseOptStringList(@Nullable JSONArray jsonArray); @Nullable static JSONArray serializeOptStringList(@Nullable List<String> stringList); static final int INDENTATION_SPACES; }
|
@Test public void testParseXml() throws FileNotFoundException, XMLStreamException { XMLInputFactory f = XMLInputFactory.newFactory(); File inputFile = new File(getClass().getResource("/SampleXml.xml").getFile()); XMLStreamReader sr = f.createXMLStreamReader(new FileInputStream(inputFile)); InputStream in = new FileInputStream(inputFile); List<String> arrays = XmlUtils.determineArrays(in); Assert.assertFalse(arrays.isEmpty()); Assert.assertEquals(2, arrays.size()); Assert.assertEquals("/root/channel", arrays.get(0)); Assert.assertEquals("/root/channel/formats/format", arrays.get(1)); sr.close(); }
|
public static List<String> determineArrays(InputStream in) throws XMLStreamException { Set<String> arrayKeys = new HashSet<>(); XMLStreamReader sr = null; try { XMLInputFactory f = XMLInputFactory.newFactory(); sr = f.createXMLStreamReader(in); getObjectElements(null, sr, new LongAdder(), arrayKeys); if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); arrayKeys.forEach(key -> sb.append(sb.length() > 0 ? "\n" : "").append(key)); LOGGER.trace("Found arrays:\n{}", sb.toString()); } } finally { if (null != sr) { sr.close(); } } return new ArrayList<>(arrayKeys); }
|
XmlUtils { public static List<String> determineArrays(InputStream in) throws XMLStreamException { Set<String> arrayKeys = new HashSet<>(); XMLStreamReader sr = null; try { XMLInputFactory f = XMLInputFactory.newFactory(); sr = f.createXMLStreamReader(in); getObjectElements(null, sr, new LongAdder(), arrayKeys); if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); arrayKeys.forEach(key -> sb.append(sb.length() > 0 ? "\n" : "").append(key)); LOGGER.trace("Found arrays:\n{}", sb.toString()); } } finally { if (null != sr) { sr.close(); } } return new ArrayList<>(arrayKeys); } }
|
XmlUtils { public static List<String> determineArrays(InputStream in) throws XMLStreamException { Set<String> arrayKeys = new HashSet<>(); XMLStreamReader sr = null; try { XMLInputFactory f = XMLInputFactory.newFactory(); sr = f.createXMLStreamReader(in); getObjectElements(null, sr, new LongAdder(), arrayKeys); if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); arrayKeys.forEach(key -> sb.append(sb.length() > 0 ? "\n" : "").append(key)); LOGGER.trace("Found arrays:\n{}", sb.toString()); } } finally { if (null != sr) { sr.close(); } } return new ArrayList<>(arrayKeys); } private XmlUtils(); }
|
XmlUtils { public static List<String> determineArrays(InputStream in) throws XMLStreamException { Set<String> arrayKeys = new HashSet<>(); XMLStreamReader sr = null; try { XMLInputFactory f = XMLInputFactory.newFactory(); sr = f.createXMLStreamReader(in); getObjectElements(null, sr, new LongAdder(), arrayKeys); if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); arrayKeys.forEach(key -> sb.append(sb.length() > 0 ? "\n" : "").append(key)); LOGGER.trace("Found arrays:\n{}", sb.toString()); } } finally { if (null != sr) { sr.close(); } } return new ArrayList<>(arrayKeys); } private XmlUtils(); static List<String> determineArrays(InputStream in); }
|
XmlUtils { public static List<String> determineArrays(InputStream in) throws XMLStreamException { Set<String> arrayKeys = new HashSet<>(); XMLStreamReader sr = null; try { XMLInputFactory f = XMLInputFactory.newFactory(); sr = f.createXMLStreamReader(in); getObjectElements(null, sr, new LongAdder(), arrayKeys); if (LOGGER.isDebugEnabled()) { StringBuilder sb = new StringBuilder(); arrayKeys.forEach(key -> sb.append(sb.length() > 0 ? "\n" : "").append(key)); LOGGER.trace("Found arrays:\n{}", sb.toString()); } } finally { if (null != sr) { sr.close(); } } return new ArrayList<>(arrayKeys); } private XmlUtils(); static List<String> determineArrays(InputStream in); }
|
@Test public void testFilteringXmlByPartialFileNamePatternFalse() { String pattern = "*Fle*.xml"; File file = new File("SomeFileWithXml.xml"); CustomPatternFileFilter filter = new CustomPatternFileFilter(pattern); Assert.assertFalse(filter.accept(file)); }
|
@Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
@Test public void testFilteringXmlByPartialFileNamePatternCaseInsensitive() { String pattern = "*File*.xml"; File file = new File("Some FileWithXml.XML"); CustomPatternFileFilter filter = new CustomPatternFileFilter(pattern); Assert.assertTrue(filter.accept(file)); }
|
@Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
@Test public void testFilteringJsonByPattern() { String pattern = "*.json"; File file = new File("SomeFileWithJson.json"); CustomPatternFileFilter filter = new CustomPatternFileFilter(pattern); Assert.assertTrue(filter.accept(file)); }
|
@Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
@Test public void testFilteringUnsupportedExtension() { String pattern = "*.txt"; File file = new File("SomeFileWithJson.txt"); CustomPatternFileFilter filter = new CustomPatternFileFilter(pattern); Assert.assertFalse(filter.accept(file)); }
|
@Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
@Test public void testConvertXmlToJson() throws IOException, XMLStreamException { File sourceFile = new File(this.getClass().getClassLoader().getResource("SampleXml.xml").getFile()); destinationFile = new File(getTempDirectory(), "ConvertedFile.json"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, new CustomFileReadListener(), isCanceled); assertTrue(destinationFile.exists()); assertTrue(destinationFile.length() > 0); System.out.println("destinationFile = " + destinationFile.getAbsolutePath()); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test public void testConvertXmlToJsonToNonExistingDirectory() throws IOException, XMLStreamException { File sourceFile = new File(this.getClass().getClassLoader().getResource("SampleXml.xml").getFile()); File nonExistingDirectory = new File(getTempDirectory(), "newDirectory"); filesToDelete.add(nonExistingDirectory); destinationFile = new File(nonExistingDirectory, "newDirectory/ConvertedFile.json"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, new CustomFileReadListener(), isCanceled); assertTrue(destinationFile.exists()); assertTrue(destinationFile.length() > 0); System.out.println("destinationFile = " + destinationFile.getAbsolutePath()); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test public void testConvertJsonToXml() throws IOException, XMLStreamException { File sourceFile = new File(this.getClass().getClassLoader().getResource("SampleJson.json").getFile()); destinationFile = new File(getTempDirectory(), "ConvertedFile.xml"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, new CustomFileReadListener(), isCanceled); assertTrue(destinationFile.exists()); assertTrue(destinationFile.length() > 0); System.out.println("destinationFile = " + destinationFile.getAbsolutePath()); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test(expected = XMLStreamException.class) public void testConvertCorruptedXmlToJson() throws IOException, XMLStreamException { File sourceFile = new File(this.getClass().getClassLoader().getResource("CorruptedXml.xml").getFile()); destinationFile = new File(getTempDirectory(), "ConvertedFile.json"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, new CustomFileReadListener(), isCanceled); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test(expected = UnsupportedFileType.class) public void testTryConvertUnsupportedFile() throws IOException, XMLStreamException { File sourceFile = new File(this.getClass().getClassLoader().getResource("Unsupported.txt").getFile()); destinationFile = new File(getTempDirectory(), "ConvertedFile.json"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, new CustomFileReadListener(), isCanceled); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test(expected = NullPointerException.class) public void testTryConvertWithNullListener() throws IOException, XMLStreamException { File sourceFile = new File(this.getClass().getClassLoader().getResource("SampleJson.json").getFile()); destinationFile = new File(getTempDirectory(), "ConvertedFile.xml"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, null, isCanceled); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test public void testApplicationVersion() { Assert.assertEquals(ApplicationUtils.UNNOWN_VERSION, ApplicationUtils.getVersion()); }
|
public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); static final String getVersion(); }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); static final String getVersion(); static final String UNNOWN_VERSION; }
|
@Test public void testConvertXmlToJsonFullProcess() throws IOException, XMLStreamException { File tempDirectory = new File(getTempDirectory(), "xml2jsonSerialize"); filesToDelete.add(tempDirectory); tempDirectory.mkdirs(); ComplexObject actualObject = new ComplexObject(); actualObject.setIntValue(555); actualObject.setText("Some Text in Complex Object"); SimpleObject so = new SimpleObject(); so.setBytePrimValue(Byte.valueOf("109")); so.setByteValue(Byte.valueOf("45")); so.setDoublePrimValue(457d); so.setDoubleValue(Double.parseDouble("256.12")); so.setFloatPrimValue(15.4f); so.setFloatValue(Float.parseFloat("852.45")); so.setIntegerValue(Integer.parseInt("400")); so.setIntValue(500); so.setLongPrimValue(32000000); so.setLongValue(Long.parseLong("4656053654")); so.setShortPrimValue((short)120); so.setShortValue(Short.parseShort("-99")); so.setSomeValue("Some text"); actualObject.getListOfObjects().add(so); so = new SimpleObject(); so.setBytePrimValue(Byte.valueOf("111")); so.setByteValue(Byte.valueOf("23")); so.setDoublePrimValue(3242d); so.setDoubleValue(Double.parseDouble("222.55")); so.setFloatPrimValue(2.2134f); so.setFloatValue(Float.parseFloat("876.44")); so.setIntegerValue(Integer.parseInt("456")); so.setIntValue(2223); so.setLongPrimValue(34534634); so.setLongValue(Long.parseLong("45856865")); so.setShortPrimValue((short)101); so.setShortValue(Short.parseShort("-44")); so.setSomeValue("Some text 2"); actualObject.getListOfObjects().add(so); File sourceFile = new File(tempDirectory, "SerializedObject.xml"); XmlMapper xmlMapper = new XmlMapper(); xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true); xmlMapper.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, true); xmlMapper.setDefaultUseWrapper(false); try (BufferedWriter writer = new BufferedWriter(new FileWriter(sourceFile))) { writer.write(xmlMapper.writeValueAsString(actualObject)); } destinationFile = new File(tempDirectory, "SerializedObject.json"); ConverterService service = new ConverterService(); AtomicBoolean isCanceled = new AtomicBoolean(false); service.convert(sourceFile, destinationFile, new CustomFileReadListener(), isCanceled); assertTrue(destinationFile.exists()); assertTrue(destinationFile.length() > 0); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); ComplexObject result = mapper.readValue(destinationFile, ComplexObject.class); assertNotNull(result); }
|
public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
ConverterService { public File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled) throws IOException, XMLStreamException { StopWatch sw = new StopWatch(); Objects.requireNonNull(listener, "Listener must be not null"); FileTypeEnum inputFileType = FileTypeEnum.parseByFileName(sourceFile.getName()); if (null == inputFileType) { throw new UnsupportedFileType(String.format(UNSUPPORTED_FILE_TYPE_TEMPLATE, sourceFile.getName())); } File parentFolder = outputFile.getParentFile(); if (!parentFolder.exists()) { parentFolder.mkdirs(); } try (InputStream input = getWrappedInputStream(sourceFile, listener, isCanceled); OutputStream output = getOutputStream(outputFile)) { sw.start(); JsonXMLConfig config = createConfig(inputFileType); XMLEventReader reader = createReader(config, inputFileType, input); XMLEventWriter writer = createWriter(config, sourceFile, output, isCanceled, listener); writer.add(reader); listener.finished(); writer.flush(); writer.close(); reader.close(); } catch (XMLStreamException ex) { throw new XMLStreamException(ex.getMessage()); } finally { LOGGER.info("Taken time: {}", sw); sw.stop(); } return outputFile; } File convert(File sourceFile, File outputFile, IFileReadListener listener, AtomicBoolean isCanceled); }
|
@Test(expected = IllegalStateException.class) public void testNotInitializedInstance() { HostServicesProvider.INSTANCE.getHostServices(); }
|
public HostServices getHostServices() { if (hostServices == null) { throw new IllegalStateException("Host services not initialized"); } return hostServices; }
|
HostServicesProvider { public HostServices getHostServices() { if (hostServices == null) { throw new IllegalStateException("Host services not initialized"); } return hostServices; } }
|
HostServicesProvider { public HostServices getHostServices() { if (hostServices == null) { throw new IllegalStateException("Host services not initialized"); } return hostServices; } }
|
HostServicesProvider { public HostServices getHostServices() { if (hostServices == null) { throw new IllegalStateException("Host services not initialized"); } return hostServices; } void init(HostServices hostServices); HostServices getHostServices(); }
|
HostServicesProvider { public HostServices getHostServices() { if (hostServices == null) { throw new IllegalStateException("Host services not initialized"); } return hostServices; } void init(HostServices hostServices); HostServices getHostServices(); static final HostServicesProvider INSTANCE; }
|
@Test(expected = FileNotFoundException.class) public void testLoadFromNonExistingFile() throws IOException { PropertiesLoader loader = new PropertiesLoader(new File("someProperties.txt")); loader.load(); }
|
public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); Properties load(); void saveProperties(Properties properties); }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); Properties load(); void saveProperties(Properties properties); }
|
@Test public void testLoad() throws IOException { PropertiesLoader loader = new PropertiesLoader(getPropertiesFile()); Properties props = loader.load(); Assert.assertEquals(4, props.size()); }
|
public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); Properties load(); void saveProperties(Properties properties); }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); Properties load(); void saveProperties(Properties properties); }
|
@Test(expected = FileNotFoundException.class) public void testLoadFileNotExists() throws IOException { File propsFile = new File(getDestinationDirectory(), "someFolder" + TEST_FILE); PropertiesLoader loader = new PropertiesLoader(propsFile); loader.load(); }
|
public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); Properties load(); void saveProperties(Properties properties); }
|
PropertiesLoader { public Properties load() throws IOException { Properties properties = new Properties(); LOGGER.debug("Loading properties from {}", propertiesFile.getAbsolutePath()); if (propertiesFile.exists()) { try (InputStream in = new FileInputStream(propertiesFile)) { properties.load(in); LOGGER.debug("Loaded {} properties", properties.size()); } } else { throw new FileNotFoundException("File '" + propertiesFile.getAbsolutePath() + "' is not exist"); } return properties; } PropertiesLoader(File propertiesFile); Properties load(); void saveProperties(Properties properties); }
|
@Test(expected = IllegalArgumentException.class) public void testApplicationPropertiesSetNullLoader() { File propsFile = new File(getDestinationDirectory(), TEST_FILE); ApplicationProperties props = new ApplicationProperties(new PropertiesLoader(propsFile)); Assert.assertNotNull(props); props.setPropertiesLoader(null); }
|
public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test public void testApplicationPropertiesSetNotNullLoader() { File propsFile = new File(getDestinationDirectory(), TEST_FILE); PropertiesLoader loader = new PropertiesLoader(propsFile); ApplicationProperties props = new ApplicationProperties(new PropertiesLoader(propsFile)); Assert.assertNotNull(props); props.setPropertiesLoader(loader); }
|
public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public void setPropertiesLoader(PropertiesLoader loader) { if (loader == null) { throw new IllegalArgumentException("Properties loader cannot be null"); } this.loader = loader; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test public void testGetPropertiesAndPathNotExists() { File propsFile = new File(getDestinationDirectory(), TEST_FILE); ApplicationProperties props = new ApplicationProperties(new PropertiesLoader(propsFile)); Assert.assertNotNull(props); String path = props.getLastOpenedPath(); Assert.assertNull(path); path = props.getLastOpenedPath(); Assert.assertNull(path); }
|
public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test public void testGetPropertiesAndPathIsEmpty() throws IOException { File propsFile = new File(getDestinationDirectory(), TEST_FILE); PropertiesLoader loader = new PropertiesLoader(propsFile); ApplicationProperties appProps = new ApplicationProperties(loader); Properties props = loader.load(); props.put(Config.LAST_DIRECTORY, ""); loader.saveProperties(props); String path = appProps.getLastOpenedPath(); Assert.assertNull(path); }
|
public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test public void testGetPropertiesAndPathWithOnlySpaces() throws IOException { File propsFile = new File(getDestinationDirectory(), TEST_FILE); PropertiesLoader loader = new PropertiesLoader(propsFile); ApplicationProperties appProps = new ApplicationProperties(loader); Properties props = loader.load(); props.put(Config.LAST_DIRECTORY, " "); loader.saveProperties(props); String path = appProps.getLastOpenedPath(); Assert.assertNull(path); }
|
public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test public void getImplementationVersion() throws Exception { PowerMockito.spy(ApplicationUtils.class); PowerMockito.doReturn("1.0.0").when(ApplicationUtils.class, "getVersionFromManifest"); String s = ApplicationUtils.getVersion(); PowerMockito.verifyStatic(Package.class); Assert.assertEquals("1.0.0", s); }
|
public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); static final String getVersion(); }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); static final String getVersion(); static final String UNNOWN_VERSION; }
|
@Test public void testGetPropertiesAndPathIsNotExist() throws IOException { File propsFile = new File(getDestinationDirectory(), TEST_FILE); PropertiesLoader loader = new PropertiesLoader(propsFile); ApplicationProperties appProps = new ApplicationProperties(loader); Properties props = loader.load(); props.put(Config.LAST_DIRECTORY, new File(propsFile.getParentFile(), "someNameFolder/file.txt").getAbsolutePath()); loader.saveProperties(props); String path = appProps.getLastOpenedPath(); Assert.assertNull(path); }
|
public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test public void testLoadWithException() throws IOException { PropertiesLoader loader = Mockito.mock(PropertiesLoader.class); BDDMockito.when(loader.load()).thenThrow(new IOException()); ApplicationProperties appProps = Mockito.spy(new ApplicationProperties(loader)); String path = appProps.getLastOpenedPath(); Assert.assertNull(path); }
|
public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
ApplicationProperties { public String getLastOpenedPath() { if (!isInitialized) { loadProperties(); } String path = properties.getProperty(Config.LAST_DIRECTORY); if (null == path || path.trim().isEmpty()) { return null; } else { File f = new File(path); if (!f.exists()) { return null; } } return path; } ApplicationProperties(PropertiesLoader loader); String getLastOpenedPath(); void saveLastOpenedPath(File path); void setPropertiesLoader(PropertiesLoader loader); }
|
@Test(expected = ParseException.class) public void testParseNoGuiAndSourceFolderWithoutValue() throws ParseException, FileNotFoundException { String[] args = new String[]{"--noGui", "--sourceFolder", "--destinationFolder", DESTINATION_FOLDER_PATH, "--pattern", "*.json"}; ApplicationCommandLine.parse(args); }
|
public static ApplicationCommandLine parse(String[] args) throws java.text.ParseException, FileNotFoundException { CommandLineParser parser = new DefaultParser(); ApplicationCommandLine cmd = null; try { cmd = new ApplicationCommandLine(parser.parse(OPTIONS, args, true)); cmd.checkInputParameters(); } catch (ParseException ex) { throw new java.text.ParseException(ex.getMessage(), 0); } return cmd; }
|
ApplicationCommandLine { public static ApplicationCommandLine parse(String[] args) throws java.text.ParseException, FileNotFoundException { CommandLineParser parser = new DefaultParser(); ApplicationCommandLine cmd = null; try { cmd = new ApplicationCommandLine(parser.parse(OPTIONS, args, true)); cmd.checkInputParameters(); } catch (ParseException ex) { throw new java.text.ParseException(ex.getMessage(), 0); } return cmd; } }
|
ApplicationCommandLine { public static ApplicationCommandLine parse(String[] args) throws java.text.ParseException, FileNotFoundException { CommandLineParser parser = new DefaultParser(); ApplicationCommandLine cmd = null; try { cmd = new ApplicationCommandLine(parser.parse(OPTIONS, args, true)); cmd.checkInputParameters(); } catch (ParseException ex) { throw new java.text.ParseException(ex.getMessage(), 0); } return cmd; } private ApplicationCommandLine(CommandLine cmd); }
|
ApplicationCommandLine { public static ApplicationCommandLine parse(String[] args) throws java.text.ParseException, FileNotFoundException { CommandLineParser parser = new DefaultParser(); ApplicationCommandLine cmd = null; try { cmd = new ApplicationCommandLine(parser.parse(OPTIONS, args, true)); cmd.checkInputParameters(); } catch (ParseException ex) { throw new java.text.ParseException(ex.getMessage(), 0); } return cmd; } private ApplicationCommandLine(CommandLine cmd); static ApplicationCommandLine parse(String[] args); static void printHelp(); boolean isNoGuiEnabled(); File getSourceFolder(); File getDestinationFolder(); String getPattern(); boolean isForceOverwrite(); }
|
ApplicationCommandLine { public static ApplicationCommandLine parse(String[] args) throws java.text.ParseException, FileNotFoundException { CommandLineParser parser = new DefaultParser(); ApplicationCommandLine cmd = null; try { cmd = new ApplicationCommandLine(parser.parse(OPTIONS, args, true)); cmd.checkInputParameters(); } catch (ParseException ex) { throw new java.text.ParseException(ex.getMessage(), 0); } return cmd; } private ApplicationCommandLine(CommandLine cmd); static ApplicationCommandLine parse(String[] args); static void printHelp(); boolean isNoGuiEnabled(); File getSourceFolder(); File getDestinationFolder(); String getPattern(); boolean isForceOverwrite(); }
|
@Test public void testPrintHelp() { ApplicationCommandLine.printHelp(); }
|
public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HELP_WINDOW_SIZE, "\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=[path_to_source_folder] " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=[path_to_destination_folder] " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=[*.json|*.xml]", ", where:", OPTIONS, "example:\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=C:\\temp\\input " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=C:\\temp\\output " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=*.json\n\n"); }
|
ApplicationCommandLine { public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HELP_WINDOW_SIZE, "\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=[path_to_source_folder] " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=[path_to_destination_folder] " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=[*.json|*.xml]", ", where:", OPTIONS, "example:\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=C:\\temp\\input " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=C:\\temp\\output " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=*.json\n\n"); } }
|
ApplicationCommandLine { public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HELP_WINDOW_SIZE, "\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=[path_to_source_folder] " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=[path_to_destination_folder] " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=[*.json|*.xml]", ", where:", OPTIONS, "example:\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=C:\\temp\\input " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=C:\\temp\\output " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=*.json\n\n"); } private ApplicationCommandLine(CommandLine cmd); }
|
ApplicationCommandLine { public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HELP_WINDOW_SIZE, "\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=[path_to_source_folder] " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=[path_to_destination_folder] " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=[*.json|*.xml]", ", where:", OPTIONS, "example:\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=C:\\temp\\input " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=C:\\temp\\output " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=*.json\n\n"); } private ApplicationCommandLine(CommandLine cmd); static ApplicationCommandLine parse(String[] args); static void printHelp(); boolean isNoGuiEnabled(); File getSourceFolder(); File getDestinationFolder(); String getPattern(); boolean isForceOverwrite(); }
|
ApplicationCommandLine { public static void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(HELP_WINDOW_SIZE, "\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=[path_to_source_folder] " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=[path_to_destination_folder] " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=[*.json|*.xml]", ", where:", OPTIONS, "example:\n java -jar xml2json.jar " + PARAM_SIGN + Config.PAR_NO_GUI + " " + PARAM_SIGN + Config.PAR_SOURCE_FOLDER + "=C:\\temp\\input " + PARAM_SIGN + Config.PAR_DESTINATION_FOLDER + "=C:\\temp\\output " + PARAM_SIGN + Config.PAR_SOURCE_FILE_PATTERN + "=*.json\n\n"); } private ApplicationCommandLine(CommandLine cmd); static ApplicationCommandLine parse(String[] args); static void printHelp(); boolean isNoGuiEnabled(); File getSourceFolder(); File getDestinationFolder(); String getPattern(); boolean isForceOverwrite(); }
|
@Test public void testIsReadWriteable() throws NoSuchFieldException { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); Assert.assertTrue(provider.isReadWriteable(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE)); type = getClass().getDeclaredField("sampleTypeList").getGenericType(); Assert.assertTrue(provider.isReadWriteable(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE)); type = getClass().getDeclaredField("objectList").getGenericType(); Assert.assertFalse(provider.isReadWriteable(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE)); type = getClass().getDeclaredField("sampleTypeIterable").getGenericType(); Assert.assertFalse(provider.isReadWriteable(Iterable.class, type, annotations, MediaType.APPLICATION_JSON_TYPE)); type = getClass().getDeclaredField("sampleTypeList").getGenericType(); Assert.assertFalse(provider.isReadWriteable(List.class, type, new Annotation[0], MediaType.APPLICATION_JSON_TYPE)); Assert.assertFalse(provider.isReadWriteable(List.class, type, annotations, MediaType.APPLICATION_XML_TYPE)); }
|
@Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (!isSupported(mediaType)) { return false; } Class<?> componentType = getComponentType(type, genericType); return componentType != null && getJsonXML(componentType, annotations) != null && isBindable(componentType); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (!isSupported(mediaType)) { return false; } Class<?> componentType = getComponentType(type, genericType); return componentType != null && getJsonXML(componentType, annotations) != null && isBindable(componentType); } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (!isSupported(mediaType)) { return false; } Class<?> componentType = getComponentType(type, genericType); return componentType != null && getJsonXML(componentType, annotations) != null && isBindable(componentType); } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (!isSupported(mediaType)) { return false; } Class<?> componentType = getComponentType(type, genericType); return componentType != null && getJsonXML(componentType, annotations) != null && isBindable(componentType); } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { if (!isSupported(mediaType)) { return false; } Class<?> componentType = getComponentType(type, genericType); return componentType != null && getJsonXML(componentType, annotations) != null && isBindable(componentType); } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadRootElementList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); String json = "{\"sampleRootElement\":[{\"@attribute\":\"hello\"},{\"@attribute\":\"world\"}]}"; @SuppressWarnings("unchecked") List<SampleRootElement> list = (List<SampleRootElement>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(2, list.size()); Assert.assertEquals("hello", list.get(0).attribute); Assert.assertEquals("world", list.get(1).attribute); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadRootElementList_DocumentArray() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); String json = "[{\"sampleRootElement\":{\"@attribute\":\"hello\"}},{\"sampleRootElement\":{\"@attribute\":\"world\"}}]"; @SuppressWarnings("unchecked") List<SampleRootElement> list = (List<SampleRootElement>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(2, list.size()); Assert.assertEquals("hello", list.get(0).attribute); Assert.assertEquals("world", list.get(1).attribute); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadSampleTypeList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleTypeList").getGenericType(); String json = "{\"sampleType\":[{\"element\":\"hello\"},{\"element\":\"world\"}]}"; @SuppressWarnings("unchecked") List<SampleType> list = (List<SampleType>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(2, list.size()); Assert.assertEquals("hello", list.get(0).element); Assert.assertEquals("world", list.get(1).element); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadSampleTypeList_DocumentArray() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleTypeList").getGenericType(); String json = "[{\"sampleType\":{\"element\":\"hello\"}},{\"sampleType\":{\"element\":\"world\"}}]"; @SuppressWarnings("unchecked") List<SampleType> list = (List<SampleType>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(2, list.size()); Assert.assertEquals("hello", list.get(0).element); Assert.assertEquals("world", list.get(1).element); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadSampleTypeListWithNullValues() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleTypeList").getGenericType(); String json = "[null,{\"sampleType\":{\"element\":\"hi!\"}},null]"; @SuppressWarnings("unchecked") List<SampleType> list = (List<SampleType>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(3, list.size()); Assert.assertNull(list.get(0)); Assert.assertEquals("hi!", list.get(1).element); Assert.assertNull(list.get(2)); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void getImplementationVersionEmptyValue() throws Exception { PowerMockito.spy(ApplicationUtils.class); PowerMockito.doReturn("").when(ApplicationUtils.class, "getVersionFromManifest"); String s = ApplicationUtils.getVersion(); PowerMockito.verifyStatic(Package.class); Assert.assertEquals(ApplicationUtils.UNNOWN_VERSION, s); }
|
public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); static final String getVersion(); }
|
ApplicationUtils { public static final String getVersion() { String version = getVersionFromManifest(); if (null == version || version.isEmpty()) { version = UNNOWN_VERSION; } return version; } private ApplicationUtils(); static final String getVersion(); static final String UNNOWN_VERSION; }
|
@Test public void testReadEmptyList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); String json = "{}"; @SuppressWarnings("unchecked") List<SampleRootElement> list = (List<SampleRootElement>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(0, list.size()); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadEmptyList2() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); String json = "{\"sampleRootElement\":[]}"; @SuppressWarnings("unchecked") List<SampleRootElement> list = (List<SampleRootElement>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(0, list.size()); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadEmptyList3() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); String json = "[]"; @SuppressWarnings("unchecked") List<SampleRootElement> list = (List<SampleRootElement>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(0, list.size()); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testReadEmptyListWithVirtualRoot() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLVirtualSampleRootElement.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); String json = "[]"; @SuppressWarnings("unchecked") List<SampleRootElement> list = (List<SampleRootElement>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(0, list.size()); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testWriteSampleRootElementList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); List<SampleRootElement> list = new ArrayList<SampleRootElement>(); list.add(new SampleRootElement()); list.get(0).attribute = "hello"; list.add(new SampleRootElement()); list.get(1).attribute = "world"; StringWriter writer = new StringWriter(); provider.write(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, list); String json = "[{\"sampleRootElement\":{\"@attribute\":\"hello\"}},{\"sampleRootElement\":{\"@attribute\":\"world\"}}]"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testWriteSampleTypeList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleTypeList").getGenericType(); List<SampleType> list = new ArrayList<SampleType>(); list.add(new SampleType()); list.get(0).element = "hello"; list.add(new SampleType()); list.get(1).element = "world"; StringWriter writer = new StringWriter(); provider.write(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, list); String json = "[{\"sampleType\":{\"element\":\"hello\"}},{\"sampleType\":{\"element\":\"world\"}}]"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testWriteEmptyList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); List<SampleRootElement> list = new ArrayList<SampleRootElement>(); StringWriter writer = new StringWriter(); provider.write(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, list); String json = "[]"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testWriteEmptyListWithVirtualRoot() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLVirtualSampleRootElement.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); List<SampleRootElement> list = new ArrayList<SampleRootElement>(); StringWriter writer = new StringWriter(); provider.write(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, list); String json = "[]"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object entry); }
|
@Test public void testGetAnnotation() { Annotation[] annotations = new Annotation[2]; annotations[0] = SampleType.class.getAnnotation(XmlType.class); annotations[1] = JsonXMLDefault.class.getAnnotation(JsonXML.class); Assert.assertEquals(XmlType.class, AbstractJsonXMLProvider.getAnnotation(annotations, XmlType.class).annotationType()); Assert.assertEquals(JsonXML.class, AbstractJsonXMLProvider.getAnnotation(annotations, JsonXML.class).annotationType()); Assert.assertNull(AbstractJsonXMLProvider.getAnnotation(annotations, XmlRootElement.class)); }
|
protected static <A extends Annotation> A getAnnotation(Annotation[] annotations, Class<A> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationType) { return annotationType.cast(annotation); } } return null; }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected static <A extends Annotation> A getAnnotation(Annotation[] annotations, Class<A> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationType) { return annotationType.cast(annotation); } } return null; } }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected static <A extends Annotation> A getAnnotation(Annotation[] annotations, Class<A> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationType) { return annotationType.cast(annotation); } } return null; } AbstractJsonXMLProvider(Providers providers); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected static <A extends Annotation> A getAnnotation(Annotation[] annotations, Class<A> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationType) { return annotationType.cast(annotation); } } return null; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected static <A extends Annotation> A getAnnotation(Annotation[] annotations, Class<A> annotationType) { for (Annotation annotation : annotations) { if (annotation.annotationType() == annotationType) { return annotationType.cast(annotation); } } return null; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
@Test public void testGetCharset() { Assert.assertEquals("UTF-8", new TestProvider().getCharset(MediaType.APPLICATION_JSON_TYPE)); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("charset", "ASCII"); MediaType customMediaType = new MediaType("application", "json", parameters); Assert.assertEquals("ASCII", new TestProvider().getCharset(customMediaType)); }
|
protected String getCharset(MediaType mediaType) { Map<String, String> parameters = mediaType.getParameters(); return parameters.containsKey("charset") ? parameters.get("charset") : "UTF-8"; }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected String getCharset(MediaType mediaType) { Map<String, String> parameters = mediaType.getParameters(); return parameters.containsKey("charset") ? parameters.get("charset") : "UTF-8"; } }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected String getCharset(MediaType mediaType) { Map<String, String> parameters = mediaType.getParameters(); return parameters.containsKey("charset") ? parameters.get("charset") : "UTF-8"; } AbstractJsonXMLProvider(Providers providers); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected String getCharset(MediaType mediaType) { Map<String, String> parameters = mediaType.getParameters(); return parameters.containsKey("charset") ? parameters.get("charset") : "UTF-8"; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected String getCharset(MediaType mediaType) { Map<String, String> parameters = mediaType.getParameters(); return parameters.containsKey("charset") ? parameters.get("charset") : "UTF-8"; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
@Test public void testGetConvertedFileForJson() { File sourceFile = new File("someJsonFile.json"); File outputDirectory = new File("."); File outFile = ConverterUtils.getConvertedFile(sourceFile, outputDirectory); Assert.assertEquals("someJsonFile.xml", outFile.getName()); }
|
public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); static File getConvertedFile(File sourceFile, File destinationFolder); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); static File getConvertedFile(File sourceFile, File destinationFolder); }
|
@Test public void testGetJsonXML() { JsonXML typeAnnotation = SampleRootElement.class.getAnnotation(JsonXML.class); Assert.assertEquals(typeAnnotation, new TestProvider().getJsonXML(SampleRootElement.class, new Annotation[0])); Annotation[] resourceAnnotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Assert.assertEquals(resourceAnnotations[0], new TestProvider().getJsonXML(SampleType.class, resourceAnnotations)); Assert.assertNull(new TestProvider().getJsonXML(SampleType.class, new Annotation[0])); }
|
protected JsonXML getJsonXML(Class<?> type, Annotation[] resourceAnnotations) { JsonXML result = getAnnotation(resourceAnnotations, JsonXML.class); if (result == null) { result = type.getAnnotation(JsonXML.class); } return result; }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected JsonXML getJsonXML(Class<?> type, Annotation[] resourceAnnotations) { JsonXML result = getAnnotation(resourceAnnotations, JsonXML.class); if (result == null) { result = type.getAnnotation(JsonXML.class); } return result; } }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected JsonXML getJsonXML(Class<?> type, Annotation[] resourceAnnotations) { JsonXML result = getAnnotation(resourceAnnotations, JsonXML.class); if (result == null) { result = type.getAnnotation(JsonXML.class); } return result; } AbstractJsonXMLProvider(Providers providers); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected JsonXML getJsonXML(Class<?> type, Annotation[] resourceAnnotations) { JsonXML result = getAnnotation(resourceAnnotations, JsonXML.class); if (result == null) { result = type.getAnnotation(JsonXML.class); } return result; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected JsonXML getJsonXML(Class<?> type, Annotation[] resourceAnnotations) { JsonXML result = getAnnotation(resourceAnnotations, JsonXML.class); if (result == null) { result = type.getAnnotation(JsonXML.class); } return result; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
@Test public void testGetSize() { Assert.assertEquals(-1, new TestProvider().getSize(null, null, null, null, null)); }
|
@Override public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return -1; }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return -1; } }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return -1; } AbstractJsonXMLProvider(Providers providers); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return -1; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { @Override public long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return -1; } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
@Test public void testIsSupported() { Assert.assertTrue(new TestProvider().isSupported(MediaType.APPLICATION_JSON_TYPE)); Assert.assertTrue(new TestProvider().isSupported(new MediaType("text", "json"))); Assert.assertTrue(new TestProvider().isSupported(new MediaType("text", "JSON"))); Assert.assertTrue(new TestProvider().isSupported(new MediaType("text", "special+json"))); Assert.assertFalse(new TestProvider().isSupported(MediaType.APPLICATION_XML_TYPE)); }
|
protected boolean isSupported(MediaType mediaType) { return "json".equalsIgnoreCase(mediaType.getSubtype()) || mediaType.getSubtype().endsWith("+json"); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected boolean isSupported(MediaType mediaType) { return "json".equalsIgnoreCase(mediaType.getSubtype()) || mediaType.getSubtype().endsWith("+json"); } }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected boolean isSupported(MediaType mediaType) { return "json".equalsIgnoreCase(mediaType.getSubtype()) || mediaType.getSubtype().endsWith("+json"); } AbstractJsonXMLProvider(Providers providers); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected boolean isSupported(MediaType mediaType) { return "json".equalsIgnoreCase(mediaType.getSubtype()) || mediaType.getSubtype().endsWith("+json"); } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
AbstractJsonXMLProvider extends JsonXMLBinder implements MessageBodyReader<Object>, MessageBodyWriter<Object> { protected boolean isSupported(MediaType mediaType) { return "json".equalsIgnoreCase(mediaType.getSubtype()) || mediaType.getSubtype().endsWith("+json"); } AbstractJsonXMLProvider(Providers providers); @Override boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); abstract Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader entityStream); @Override final Object readFrom(
Class<Object> type, // <-- how sad...
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream); abstract void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer entityStream,
Object entry); @Override final void writeTo(
Object entry,
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
OutputStream entityStream); }
|
@Test public void testIsReadWriteable() { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] jsonXMLAnnotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Assert.assertTrue(provider.isReadWriteable(SampleRootElement.class, null, jsonXMLAnnotations, MediaType.APPLICATION_JSON_TYPE)); Assert.assertTrue(provider.isReadWriteable(SampleType.class, null, jsonXMLAnnotations, MediaType.APPLICATION_JSON_TYPE)); Assert.assertFalse(provider.isReadWriteable(Object.class, null, jsonXMLAnnotations, MediaType.APPLICATION_JSON_TYPE)); Assert.assertFalse(provider.isReadWriteable(SampleType.class, null, new Annotation[0], MediaType.APPLICATION_JSON_TYPE)); Assert.assertFalse(provider.isReadWriteable(SampleRootElement.class, null, jsonXMLAnnotations, MediaType.APPLICATION_XML_TYPE)); }
|
@Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return isSupported(mediaType) && getJsonXML(type, annotations) != null && isBindable(type); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return isSupported(mediaType) && getJsonXML(type, annotations) != null && isBindable(type); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return isSupported(mediaType) && getJsonXML(type, annotations) != null && isBindable(type); } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return isSupported(mediaType) && getJsonXML(type, annotations) != null && isBindable(type); } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override protected boolean isReadWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return isSupported(mediaType) && getJsonXML(type, annotations) != null && isBindable(type); } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testReadSampleRootElement() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[0]; String json = "{\"sampleRootElement\":{\"@attribute\":\"hello\",\"elements\":[\"world\"]}}"; SampleRootElement sampleRootElement = (SampleRootElement)provider.read(SampleRootElement.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals("hello", sampleRootElement.attribute); Assert.assertEquals("world", sampleRootElement.elements.get(0)); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testReadSampleType() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; String json = "{\"sampleType\":{\"element\":\"hi!\"}}"; SampleType sampleType = (SampleType)provider.read(SampleType.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals("hi!", sampleType.element); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testWriteSampleRootElement() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[0]; SampleRootElement sampleRootElement = new SampleRootElement(); sampleRootElement.attribute = "hello"; sampleRootElement.elements = Arrays.asList("world"); StringWriter writer = new StringWriter(); provider.write(SampleRootElement.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, sampleRootElement); String json = "{\"sampleRootElement\":{\"@attribute\":\"hello\",\"elements\":[\"world\"]}}"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testWriteSampleType() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; SampleType sampleType = new SampleType(); sampleType.element = "hi!"; StringWriter writer = new StringWriter(); provider.write(SampleType.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, sampleType); String json = "{\"sampleType\":{\"element\":\"hi!\"}}"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testReadNull() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[0]; String json = "null"; SampleRootElement sampleRootElement = (SampleRootElement)provider.read(SampleRootElement.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertNull(sampleRootElement); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testReadNullWithVirtualRoot() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLVirtualSampleRootElement.class.getAnnotation(JsonXML.class)}; String json = "null"; SampleRootElement sampleRootElement = (SampleRootElement)provider.read(SampleRootElement.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertNotNull(sampleRootElement); }
|
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { return readObject(type, config, getContext(type, mediaType), stream); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testGetConvertedFileForXml() { File sourceFile = new File("someFile.xml"); File outputDirectory = new File("."); File outFile = ConverterUtils.getConvertedFile(sourceFile, outputDirectory); Assert.assertEquals("someFile.json", outFile.getName()); }
|
public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); static File getConvertedFile(File sourceFile, File destinationFolder); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); static File getConvertedFile(File sourceFile, File destinationFolder); }
|
@Test public void testWriteNull() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[0]; StringWriter writer = new StringWriter(); provider.write(SampleRootElement.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, null); String json = "null"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test public void testWriteNullWithVirtualRoot() throws Exception { JsonXMLObjectProvider provider = new JsonXMLObjectProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLVirtualSampleRootElement.class.getAnnotation(JsonXML.class)}; StringWriter writer = new StringWriter(); provider.write(SampleRootElement.class, null, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, null); String json = "null"; Assert.assertEquals(json, writer.toString()); }
|
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
JsonXMLObjectProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object value) throws IOException, WebApplicationException { JsonXML config = getJsonXML(type, annotations); try { writeObject(type, config, getContext(type, mediaType), stream, value); } catch (XMLStreamException | JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLObjectProvider(@Context Providers providers); @Override Object read(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
Reader stream); @Override void write(
Class<?> type,
Type genericType,
Annotation[] annotations,
MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders,
Writer stream,
Object value); }
|
@Test(expected = NullPointerException.class) public void testGetConvertedFileWithUnsupportedFile() { File sourceFile = new File("someIncorrectFile.txt"); File outputDirectory = new File("."); ConverterUtils.getConvertedFile(sourceFile, outputDirectory); }
|
public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); static File getConvertedFile(File sourceFile, File destinationFolder); }
|
ConverterUtils { public static File getConvertedFile(File sourceFile, File destinationFolder) { FileTypeEnum fileType = FileTypeEnum.parseByFileName(sourceFile.getName()); String convertedFileName = ""; String fileNameWithoutExtension = sourceFile.getName().substring(0, sourceFile.getName().lastIndexOf('.')); switch (fileType) { case JSON: convertedFileName = fileNameWithoutExtension + FileTypeEnum.XML.getExtension(); break; case XML: convertedFileName = fileNameWithoutExtension + FileTypeEnum.JSON.getExtension(); break; default: throw new UnsupportedFileType("Unsupported file's extension"); } return new File(destinationFolder, convertedFileName); } private ConverterUtils(); static File getConvertedFile(File sourceFile, File destinationFolder); }
|
@Test public void testFilteringXmlByPattern() { String pattern = "*.xml"; File file = new File("SomeFileWithXml.xml"); CustomPatternFileFilter filter = new CustomPatternFileFilter(pattern); Assert.assertTrue(filter.accept(file)); }
|
@Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
CustomPatternFileFilter implements FileFilter { @Override public boolean accept(File file) { String fileNameInLowerCase = file.getName().toLowerCase(); FileTypeEnum fileType = FileTypeEnum.parseByFileName(fileNameInLowerCase); return (null != fileType) && fileNameInLowerCase.matches(pattern); } CustomPatternFileFilter(String pattern); @Override boolean accept(File file); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.