Commit 26466679 by eguven Committed by Santiago Seifert

Added CacheDataSourceFactory, FileDataSourceFactory and CacheDataSinkFactory.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132556806
parent cab02289
...@@ -23,6 +23,18 @@ import java.io.IOException; ...@@ -23,6 +23,18 @@ import java.io.IOException;
public interface DataSink { public interface DataSink {
/** /**
* A factory for {@link DataSink} instances.
*/
interface Factory {
/**
* Creates a {@link DataSink} instance.
*/
DataSink createDataSink();
}
/**
* Opens the sink to consume the specified data. * Opens the sink to consume the specified data.
* *
* @param dataSpec Defines the data to be consumed. * @param dataSpec Defines the data to be consumed.
......
/*
* Copyright (C) 2016 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;
/**
* A {@link DataSource.Factory} that produces {@link FileDataSource}.
*/
public final class FileDataSourceFactory implements DataSource.Factory {
private final TransferListener<? super FileDataSource> listener;
public FileDataSourceFactory() {
this(null);
}
public FileDataSourceFactory(TransferListener<? super FileDataSource> listener) {
this.listener = listener;
}
@Override
public DataSource createDataSource() {
return new FileDataSource(listener);
}
}
/*
* Copyright (C) 2016 The Android Open Sink 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.cache;
import com.google.android.exoplayer2.upstream.DataSink;
/**
* A {@link DataSink.Factory} that produces {@link CacheDataSink}.
*/
public final class CacheDataSinkFactory implements DataSink.Factory {
private final Cache cache;
private final long maxCacheFileSize;
/**
* @see CacheDataSink#CacheDataSink(Cache, long)
*/
public CacheDataSinkFactory(Cache cache, long maxCacheFileSize) {
this.cache = cache;
this.maxCacheFileSize = maxCacheFileSize;
}
@Override
public DataSink createDataSink() {
return new CacheDataSink(cache, maxCacheFileSize);
}
}
/*
* Copyright (C) 2016 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.cache;
import com.google.android.exoplayer2.upstream.DataSink;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSource.Factory;
import com.google.android.exoplayer2.upstream.FileDataSourceFactory;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource.EventListener;
/**
* A {@link DataSource.Factory} that produces {@link CacheDataSource}.
*/
public final class CacheDataSourceFactory implements DataSource.Factory {
private final Cache cache;
private final DataSource.Factory upstreamFactory;
private final DataSource.Factory cacheReadDataSourceFactory;
private final DataSink.Factory cacheWriteDataSinkFactory;
private final int flags;
private final EventListener eventListener;
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int)
*/
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory, int flags) {
this(cache, upstreamFactory, flags, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE);
}
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, int, long)
*/
public CacheDataSourceFactory(Cache cache, DataSource.Factory upstreamFactory, int flags,
long maxCacheFileSize) {
this(cache, upstreamFactory, new FileDataSourceFactory(),
new CacheDataSinkFactory(cache, maxCacheFileSize), flags, null);
}
/**
* @see CacheDataSource#CacheDataSource(Cache, DataSource, DataSource, DataSink, int,
* EventListener)
*/
public CacheDataSourceFactory(Cache cache, Factory upstreamFactory,
Factory cacheReadDataSourceFactory,
DataSink.Factory cacheWriteDataSinkFactory, int flags, EventListener eventListener) {
this.cache = cache;
this.upstreamFactory = upstreamFactory;
this.cacheReadDataSourceFactory = cacheReadDataSourceFactory;
this.cacheWriteDataSinkFactory = cacheWriteDataSinkFactory;
this.flags = flags;
this.eventListener = eventListener;
}
@Override
public DataSource createDataSource() {
return new CacheDataSource(cache, upstreamFactory.createDataSource(),
cacheReadDataSourceFactory.createDataSource(),
cacheWriteDataSinkFactory.createDataSink(), flags, eventListener);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment