mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-01-25 04:47:54 +08:00
40 lines
901 B
Java
40 lines
901 B
Java
package com.danikula.videocache;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
/**
|
|
* Simple memory based {@link Source} implementation.
|
|
*
|
|
* @author Alexey Danilov (danikula@gmail.com).
|
|
*/
|
|
public class ByteArraySource implements Source {
|
|
|
|
private final byte[] data;
|
|
private ByteArrayInputStream arrayInputStream;
|
|
|
|
public ByteArraySource(byte[] data) {
|
|
this.data = data;
|
|
}
|
|
|
|
@Override
|
|
public int read(byte[] buffer) throws ProxyCacheException {
|
|
return arrayInputStream.read(buffer, 0, buffer.length);
|
|
}
|
|
|
|
@Override
|
|
public int length() throws ProxyCacheException {
|
|
return data.length;
|
|
}
|
|
|
|
@Override
|
|
public void open(int offset) throws ProxyCacheException {
|
|
arrayInputStream = new ByteArrayInputStream(data);
|
|
arrayInputStream.skip(offset);
|
|
}
|
|
|
|
@Override
|
|
public void close() throws ProxyCacheException {
|
|
}
|
|
}
|
|
|