diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DummyDataSource.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DummyDataSource.java new file mode 100644 index 0000000000..c20868ef00 --- /dev/null +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DummyDataSource.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2.upstream; + +import android.net.Uri; +import java.io.IOException; + +/** + * A dummy DataSource which provides no data. {@link #open(DataSpec)} throws {@link IOException}. + */ +public final class DummyDataSource implements DataSource { + + public static final DummyDataSource INSTANCE = new DummyDataSource(); + + /** A factory that that produces {@link DummyDataSource}. */ + public static final Factory FACTORY = new Factory() { + @Override + public DataSource createDataSource() { + return new DummyDataSource(); + } + }; + + private DummyDataSource() {} + + @Override + public long open(DataSpec dataSpec) throws IOException { + throw new IOException("Dummy source"); + } + + @Override + public int read(byte[] buffer, int offset, int readLength) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public Uri getUri() { + return null; + } + + @Override + public void close() throws IOException { + // do nothing. + } + +} diff --git a/library/dash/src/androidTest/java/com/google/android/exoplayer2/source/dash/DashUtilTest.java b/library/dash/src/androidTest/java/com/google/android/exoplayer2/source/dash/DashUtilTest.java index 3ee76f43bb..c9f1ca1030 100644 --- a/library/dash/src/androidTest/java/com/google/android/exoplayer2/source/dash/DashUtilTest.java +++ b/library/dash/src/androidTest/java/com/google/android/exoplayer2/source/dash/DashUtilTest.java @@ -23,10 +23,8 @@ import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet; import com.google.android.exoplayer2.source.dash.manifest.Period; import com.google.android.exoplayer2.source.dash.manifest.Representation; import com.google.android.exoplayer2.source.dash.manifest.SegmentBase.SingleSegmentBase; -import com.google.android.exoplayer2.testutil.FakeDataSource; -import com.google.android.exoplayer2.upstream.DataSource; +import com.google.android.exoplayer2.upstream.DummyDataSource; import com.google.android.exoplayer2.util.MimeTypes; -import java.io.IOException; import java.util.Arrays; import junit.framework.TestCase; @@ -37,25 +35,25 @@ public final class DashUtilTest extends TestCase { public void testLoadDrmInitDataFromManifest() throws Exception { Period period = newPeriod(newAdaptationSets(newRepresentations(newDrmInitData()))); - DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period); + DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period); assertEquals(newDrmInitData(), drmInitData); } public void testLoadDrmInitDataMissing() throws Exception { Period period = newPeriod(newAdaptationSets(newRepresentations(null /* no init data */))); - DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period); + DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period); assertNull(drmInitData); } public void testLoadDrmInitDataNoRepresentations() throws Exception { Period period = newPeriod(newAdaptationSets(/* no representation */)); - DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period); + DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period); assertNull(drmInitData); } public void testLoadDrmInitDataNoAdaptationSets() throws Exception { Period period = newPeriod(/* no adaptation set */); - DrmInitData drmInitData = DashUtil.loadDrmInitData(newDataSource(), period); + DrmInitData drmInitData = DashUtil.loadDrmInitData(DummyDataSource.INSTANCE, period); assertNull(drmInitData); } @@ -81,11 +79,4 @@ public final class DashUtilTest extends TestCase { new byte[]{1, 4, 7, 0, 3, 6})); } - private static DataSource newDataSource() { - // TODO: Use DummyDataSource when available. - FakeDataSource fakeDataSource = new FakeDataSource(); - fakeDataSource.getDataSet().newDefaultData().appendReadError(new IOException("Unexpected")); - return fakeDataSource; - } - }