VaultFileInputStream.java
2.3 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.RepositoryException
*/
package com.day.jcr.vault.fs;
import com.day.jcr.vault.fs.api.AccessType;
import com.day.jcr.vault.fs.api.Artifact;
import com.day.jcr.vault.fs.api.VaultFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.jcr.RepositoryException;
public class VaultFileInputStream
extends InputStream {
private final InputStream base;
private File tmpFile;
public VaultFileInputStream(VaultFile file) throws IOException {
Artifact a = file.getArtifact();
if (a == null || a.getPreferredAccess() == AccessType.NONE) {
throw new IOException("invalid access.");
}
try {
if (a.getPreferredAccess() == AccessType.STREAM) {
this.base = a.getInputStream();
} else {
this.tmpFile = File.createTempFile("vltfs", ".spool");
FileOutputStream out = new FileOutputStream(this.tmpFile);
a.spool(out);
out.close();
this.base = new FileInputStream(this.tmpFile);
}
}
catch (RepositoryException e) {
throw new IOException(e.toString());
}
}
public int read() throws IOException {
return this.base.read();
}
public int read(byte[] b) throws IOException {
return this.base.read(b);
}
public int read(byte[] b, int off, int len) throws IOException {
return this.base.read(b, off, len);
}
public long skip(long n) throws IOException {
return this.base.skip(n);
}
public int available() throws IOException {
return this.base.available();
}
public void close() throws IOException {
this.base.close();
if (this.tmpFile != null) {
this.tmpFile.delete();
this.tmpFile.deleteOnExit();
this.tmpFile = null;
}
}
public void mark(int readlimit) {
this.base.mark(readlimit);
}
public void reset() throws IOException {
this.base.reset();
}
public boolean markSupported() {
return this.base.markSupported();
}
}