com.google.android.exoplayer2.util.Util.sneakyThrow()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(1.8k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中com.google.android.exoplayer2.util.Util.sneakyThrow()方法的一些代码示例,展示了Util.sneakyThrow()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.sneakyThrow()方法的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称:Util
方法名:sneakyThrow

Util.sneakyThrow介绍

[英]A hacky method that always throws t even if t is a checked exception, and is not declared to be thrown.
[中]一种黑客方法,即使t是已检查的异常,也总是抛出t,并且未声明要抛出。

代码示例

代码示例来源:origin: google/ExoPlayer

  1. @Override
  2. public void close() throws IOException {
  3. closed = true;
  4. Throwable thrown = null;
  5. try {
  6. flush();
  7. } catch (Throwable e) {
  8. thrown = e;
  9. }
  10. try {
  11. out.close();
  12. } catch (Throwable e) {
  13. if (thrown == null) {
  14. thrown = e;
  15. }
  16. }
  17. if (thrown != null) {
  18. Util.sneakyThrow(thrown);
  19. }
  20. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Runs the provided {@link Runnable} on the playback thread, blocking until execution completes.
  3. *
  4. * @param runnable The {@link Runnable} to run.
  5. */
  6. public void runOnPlaybackThread(final Runnable runnable) {
  7. final Throwable[] throwable = new Throwable[1];
  8. final ConditionVariable finishedCondition = new ConditionVariable();
  9. playbackHandler.post(
  10. () -> {
  11. try {
  12. runnable.run();
  13. } catch (Throwable e) {
  14. throwable[0] = e;
  15. } finally {
  16. finishedCondition.open();
  17. }
  18. });
  19. assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
  20. if (throwable[0] != null) {
  21. Util.sneakyThrow(throwable[0]);
  22. }
  23. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Runs the provided {@link Runnable} on the playback thread, blocking until execution completes.
  3. *
  4. * @param runnable The {@link Runnable} to run.
  5. */
  6. public void runOnPlaybackThread(final Runnable runnable) {
  7. final Throwable[] throwable = new Throwable[1];
  8. final ConditionVariable finishedCondition = new ConditionVariable();
  9. playbackHandler.post(
  10. () -> {
  11. try {
  12. runnable.run();
  13. } catch (Throwable e) {
  14. throwable[0] = e;
  15. } finally {
  16. finishedCondition.open();
  17. }
  18. });
  19. assertThat(finishedCondition.block(TIMEOUT_MS)).isTrue();
  20. if (throwable[0] != null) {
  21. Util.sneakyThrow(throwable[0]);
  22. }
  23. }

相关文章