Skip to content

Commit 70baa56

Browse files
committed
🎉 VideoCache 1.0 released
0 parents  commit 70baa56

37 files changed

Lines changed: 2042 additions & 0 deletions

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.iml
2+
.DS_Store
3+
.gradle
4+
5+
/.idea
6+
/build
7+
/local.properties
8+
/gradle.properties
9+
/library/build
10+
/sample/build
11+
/test/build

build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
classpath 'com.android.tools.build:gradle:1.0.0-rc4'
7+
}
8+
}
9+
10+
allprojects {
11+
repositories {
12+
mavenCentral()
13+
}
14+
}

gradle/wrapper/gradle-wrapper.jar

48.7 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Wed Apr 10 15:27:10 PDT 2013
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip

gradlew

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apply plugin: 'java'
2+
3+
dependencies {
4+
compile 'com.google.android:android:1.6_r2'
5+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.danikula.videocache;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.util.Arrays;
5+
6+
import static com.danikula.videocache.Preconditions.checkArgument;
7+
import static com.danikula.videocache.Preconditions.checkNotNull;
8+
9+
/**
10+
* Simple memory based {@link Cache} implementation.
11+
*
12+
* @author Alexey Danilov ([email protected]).
13+
*/
14+
public class ByteArrayCache implements Cache {
15+
16+
private volatile byte[] data;
17+
private volatile boolean completed;
18+
19+
public ByteArrayCache() {
20+
this(new byte[0]);
21+
}
22+
23+
public ByteArrayCache(byte[] data) {
24+
this.data = Preconditions.checkNotNull(data);
25+
}
26+
27+
28+
@Override
29+
public int read(byte[] buffer, long offset, int length) throws ProxyCacheException {
30+
if (offset >= data.length) {
31+
return -1;
32+
}
33+
if (offset > Integer.MAX_VALUE) {
34+
throw new IllegalArgumentException("Too long offset for memory cache " + offset);
35+
}
36+
return new ByteArrayInputStream(data).read(buffer, (int) offset, length);
37+
}
38+
39+
@Override
40+
public int available() throws ProxyCacheException {
41+
return data.length;
42+
}
43+
44+
@Override
45+
public void append(byte[] newData, int length) throws ProxyCacheException {
46+
Preconditions.checkNotNull(data);
47+
Preconditions.checkArgument(length >= 0 && length <= newData.length);
48+
49+
byte[] appendedData = Arrays.copyOf(data, data.length + length);
50+
System.arraycopy(newData, 0, appendedData, data.length, length);
51+
data = appendedData;
52+
}
53+
54+
@Override
55+
public void close() throws ProxyCacheException {
56+
}
57+
58+
@Override
59+
public void complete() {
60+
completed = true;
61+
}
62+
63+
@Override
64+
public boolean isCompleted() {
65+
return completed;
66+
}
67+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.danikula.videocache;
2+
3+
import java.io.ByteArrayInputStream;
4+
5+
/**
6+
* Simple memory based {@link Source} implementation.
7+
*
8+
* @author Alexey Danilov ([email protected]).
9+
*/
10+
public class ByteArraySource implements Source {
11+
12+
private final byte[] data;
13+
private ByteArrayInputStream arrayInputStream;
14+
15+
public ByteArraySource(byte[] data) {
16+
this.data = data;
17+
}
18+
19+
@Override
20+
public int read(byte[] buffer) throws ProxyCacheException {
21+
return arrayInputStream.read(buffer, 0, buffer.length);
22+
}
23+
24+
@Override
25+
public int available() throws ProxyCacheException {
26+
return data.length;
27+
}
28+
29+
@Override
30+
public void open(int offset) throws ProxyCacheException {
31+
arrayInputStream = new ByteArrayInputStream(data);
32+
arrayInputStream.skip(offset);
33+
}
34+
35+
@Override
36+
public void close() throws ProxyCacheException {
37+
}
38+
}
39+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.danikula.videocache;
2+
3+
/**
4+
* Cache for proxy.
5+
*
6+
* @author Alexey Danilov ([email protected]).
7+
*/
8+
public interface Cache {
9+
10+
int available() throws ProxyCacheException;
11+
12+
int read(byte[] buffer, long offset, int length) throws ProxyCacheException;
13+
14+
void append(byte[] data, int length) throws ProxyCacheException;
15+
16+
void close() throws ProxyCacheException;
17+
18+
void complete() throws ProxyCacheException;
19+
20+
boolean isCompleted();
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.danikula.videocache;
2+
3+
/**
4+
* @author Egor Makovsky ([email protected]).
5+
*/
6+
public interface CacheListener {
7+
void onError(ProxyCacheException e);
8+
9+
void onCacheDataAvailable(int cachePercentage);
10+
}

0 commit comments

Comments
 (0)