diff --git a/library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestContentProvider.java b/library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestContentProvider.java index c259d2f7b7..a5e53d02d3 100644 --- a/library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestContentProvider.java +++ b/library/core/src/androidTest/java/com/google/android/exoplayer2/upstream/TestContentProvider.java @@ -23,6 +23,8 @@ import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.os.ParcelFileDescriptor; +import android.system.ErrnoException; +import android.system.OsConstants; import androidx.annotation.Nullable; import com.google.android.exoplayer2.testutil.TestUtil; import java.io.FileNotFoundException; @@ -110,12 +112,17 @@ public final class TestContentProvider extends ContentProvider String mimeType, @Nullable Bundle opts, @Nullable Object args) { - try { + try (FileOutputStream outputStream = new FileOutputStream(output.getFileDescriptor())) { byte[] data = TestUtil.getByteArray(getContext(), getFileName(uri)); - FileOutputStream outputStream = new FileOutputStream(output.getFileDescriptor()); outputStream.write(data); - outputStream.close(); } catch (IOException e) { + if (e.getCause() instanceof ErrnoException + && ((ErrnoException) e.getCause()).errno == OsConstants.EPIPE) { + // Swallow the exception if it's caused by a broken pipe - this indicates the reader has + // closed the pipe and is therefore no longer interested in the data being written. + // [See internal b/186728171]. + return; + } throw new RuntimeException("Error writing to pipe", e); } }