JarExporter.java
4.35 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.RepositoryException
* org.apache.commons.io.IOUtils
* org.apache.commons.io.output.CloseShieldOutputStream
*/
package com.day.jcr.vault.fs.io;
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 com.day.jcr.vault.fs.io.AbstractExporter;
import com.day.jcr.vault.fs.io.ExportInfo;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.jcr.RepositoryException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.CloseShieldOutputStream;
public class JarExporter
extends AbstractExporter {
private JarOutputStream jOut;
private OutputStream out;
private File jarFile;
public JarExporter(File jarFile) {
this.jarFile = jarFile;
}
public JarExporter(OutputStream out) {
this.out = out;
}
public void open() throws IOException {
if (this.jOut == null) {
if (this.jarFile != null) {
this.jOut = new JarOutputStream(new FileOutputStream(this.jarFile));
} else if (this.out != null) {
this.jOut = new JarOutputStream(this.out);
} else {
throw new IllegalArgumentException("Either out or jarFile needs to be set.");
}
}
}
public void close() throws IOException {
if (this.jOut != null) {
this.jOut.close();
this.jOut = null;
}
}
public void createDirectory(VaultFile file, String relPath) throws RepositoryException, IOException {
ZipEntry e = new ZipEntry(this.getPlatformFilePath(file, relPath) + "/");
this.jOut.putNextEntry(e);
this.jOut.closeEntry();
this.track("A", relPath);
this.exportInfo.update(ExportInfo.Type.MKDIR, e.getName());
}
public void createDirectory(String relPath) throws IOException {
ZipEntry e = new ZipEntry(relPath + "/");
this.jOut.putNextEntry(e);
this.jOut.closeEntry();
this.exportInfo.update(ExportInfo.Type.MKDIR, e.getName());
}
public void writeFile(VaultFile file, String relPath) throws RepositoryException, IOException {
ZipEntry e = new ZipEntry(this.getPlatformFilePath(file, relPath));
Artifact a = file.getArtifact();
if (a.getLastModified() > 0) {
e.setTime(a.getLastModified());
}
this.track("A", relPath);
this.exportInfo.update(ExportInfo.Type.ADD, e.getName());
this.jOut.putNextEntry(e);
switch (a.getPreferredAccess()) {
case NONE: {
throw new RepositoryException("Artifact has no content.");
}
case SPOOL: {
CloseShieldOutputStream nout = new CloseShieldOutputStream((OutputStream)this.jOut);
a.spool((OutputStream)nout);
break;
}
case STREAM: {
CloseShieldOutputStream nout = new CloseShieldOutputStream((OutputStream)this.jOut);
InputStream in = a.getInputStream();
IOUtils.copy((InputStream)in, (OutputStream)nout);
in.close();
}
}
this.jOut.closeEntry();
}
public void writeFile(InputStream in, String relPath) throws IOException {
ZipEntry e = new ZipEntry(relPath);
this.exportInfo.update(ExportInfo.Type.ADD, e.getName());
this.jOut.putNextEntry(e);
CloseShieldOutputStream nout = new CloseShieldOutputStream((OutputStream)this.jOut);
IOUtils.copy((InputStream)in, (OutputStream)nout);
in.close();
this.jOut.closeEntry();
}
public void write(ZipFile zip, ZipEntry entry) throws IOException {
this.track("A", entry.getName());
this.exportInfo.update(ExportInfo.Type.ADD, entry.getName());
ZipEntry copy = new ZipEntry(entry);
this.jOut.putNextEntry(copy);
if (!entry.isDirectory()) {
InputStream in = zip.getInputStream(entry);
IOUtils.copy((InputStream)in, (OutputStream)this.jOut);
in.close();
}
this.jOut.closeEntry();
}
}