BlobFactoryImpl.java
1.57 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Decompiled with CFR 0_118.
*/
package com.day.crx.delite.impl.support;
import com.day.crx.delite.impl.support.Blob;
import com.day.crx.delite.impl.support.BlobFactory;
import com.day.crx.delite.impl.support.BlobImpl;
import com.day.crx.delite.impl.support.BlobOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class BlobFactoryImpl
implements BlobFactory {
private final Set<BlobImpl> blobs = new HashSet<BlobImpl>();
public Blob create(byte[] bytes, int off, int len) throws IOException {
byte[] data = new byte[len];
System.arraycopy(bytes, off, data, 0, len);
return this.register(new BlobImpl(this, data));
}
public Blob create(byte[] bytes) throws IOException {
return this.create(bytes, 0, bytes.length);
}
public BlobOutputStream createOutputStream() throws IOException {
return new BlobOutputStream(this);
}
BlobImpl register(BlobImpl blob) {
this.blobs.add(blob);
return blob;
}
void discard(BlobImpl blob) throws IOException {
blob.discard();
}
File allocateTmpFile() throws IOException {
return File.createTempFile("__crx", ".dat");
}
void freeTmpFile(File file) throws IOException {
file.deleteOnExit();
file.delete();
}
public void close() throws IOException {
Iterator<BlobImpl> iter = this.blobs.iterator();
while (iter.hasNext()) {
iter.next().close();
iter.remove();
}
}
}