]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.spring/src/org/argeo/slc/core/deploy/LocalFilesDeployment.java
1 package org
.argeo
.slc
.core
.deploy
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
6 import java
.io
.OutputStream
;
9 import org
.apache
.commons
.io
.FileUtils
;
10 import org
.apache
.commons
.io
.IOUtils
;
11 import org
.argeo
.slc
.SlcException
;
12 import org
.springframework
.core
.io
.Resource
;
14 public class LocalFilesDeployment
implements Runnable
{
15 private String targetBase
= "";
16 private ResourceSet resourceSet
;
18 public LocalFilesDeployment() {
21 public LocalFilesDeployment(ResourceSet resourceSet
) {
22 this.resourceSet
= resourceSet
;
26 Map
<String
, Resource
> resources
= resourceSet
.listResources();
27 for (String relPath
: resources
.keySet()) {
28 File targetFile
= new File(targetBase
+ File
.separator
+ relPath
);
29 File parentDir
= targetFile
.getParentFile();
30 if (!parentDir
.exists())
33 Resource resource
= resources
.get(relPath
);
35 InputStream in
= null;
36 OutputStream out
= null;
38 in
= resource
.getInputStream();
39 out
= FileUtils
.openOutputStream(targetFile
);
40 IOUtils
.copy(in
, out
);
41 } catch (IOException e
) {
42 throw new SlcException("Cannot extract " + resource
+ " to "
45 IOUtils
.closeQuietly(in
);
46 IOUtils
.closeQuietly(out
);
51 public void setTargetBase(String targetBase
) {
52 this.targetBase
= targetBase
;
55 public void setResourceSet(ResourceSet resourceSet
) {
56 this.resourceSet
= resourceSet
;