ByteArraySource.java
903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 long length() throws ProxyCacheException {
return data.length;
}
@Override
public void open(long offset) throws ProxyCacheException {
arrayInputStream = new ByteArrayInputStream(data);
arrayInputStream.skip(offset);
}
@Override
public void close() throws ProxyCacheException {
}
}