]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/LocalFilesDeployment.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.core
.deploy
;
19 import java
.io
.IOException
;
20 import java
.io
.InputStream
;
21 import java
.io
.OutputStream
;
24 import org
.apache
.commons
.io
.FileUtils
;
25 import org
.apache
.commons
.io
.IOUtils
;
26 import org
.argeo
.slc
.SlcException
;
27 import org
.springframework
.core
.io
.Resource
;
29 public class LocalFilesDeployment
implements Runnable
{
30 private String targetBase
= "";
31 private ResourceSet resourceSet
;
33 public LocalFilesDeployment() {
36 public LocalFilesDeployment(ResourceSet resourceSet
) {
37 this.resourceSet
= resourceSet
;
41 Map
<String
, Resource
> resources
= resourceSet
.listResources();
42 for (String relPath
: resources
.keySet()) {
43 File targetFile
= new File(targetBase
+ File
.separator
+ relPath
);
44 File parentDir
= targetFile
.getParentFile();
45 if (!parentDir
.exists())
48 Resource resource
= resources
.get(relPath
);
50 InputStream in
= null;
51 OutputStream out
= null;
53 in
= resource
.getInputStream();
54 out
= FileUtils
.openOutputStream(targetFile
);
55 IOUtils
.copy(in
, out
);
56 } catch (IOException e
) {
57 throw new SlcException("Cannot extract " + resource
+ " to "
60 IOUtils
.closeQuietly(in
);
61 IOUtils
.closeQuietly(out
);
66 public void setTargetBase(String targetBase
) {
67 this.targetBase
= targetBase
;
70 public void setResourceSet(ResourceSet resourceSet
) {
71 this.resourceSet
= resourceSet
;