]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/deploy/LocalFilesDeployment.java
bc66c60f11db5cb5a3a1e99043dc6d643caa1d47
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.core
.deploy
;
20 import java
.io
.IOException
;
21 import java
.io
.InputStream
;
22 import java
.io
.OutputStream
;
25 import org
.apache
.commons
.io
.FileUtils
;
26 import org
.apache
.commons
.io
.IOUtils
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.springframework
.core
.io
.Resource
;
30 public class LocalFilesDeployment
implements Runnable
{
31 private String targetBase
= "";
32 private ResourceSet resourceSet
;
34 public LocalFilesDeployment() {
37 public LocalFilesDeployment(ResourceSet resourceSet
) {
38 this.resourceSet
= resourceSet
;
42 Map
<String
, Resource
> resources
= resourceSet
.listResources();
43 for (String relPath
: resources
.keySet()) {
44 File targetFile
= new File(targetBase
+ File
.separator
+ relPath
);
45 File parentDir
= targetFile
.getParentFile();
46 if (!parentDir
.exists())
49 Resource resource
= resources
.get(relPath
);
51 InputStream in
= null;
52 OutputStream out
= null;
54 in
= resource
.getInputStream();
55 out
= FileUtils
.openOutputStream(targetFile
);
56 IOUtils
.copy(in
, out
);
57 } catch (IOException e
) {
58 throw new SlcException("Cannot extract " + resource
+ " to "
61 IOUtils
.closeQuietly(in
);
62 IOUtils
.closeQuietly(out
);
67 public void setTargetBase(String targetBase
) {
68 this.targetBase
= targetBase
;
71 public void setResourceSet(ResourceSet resourceSet
) {
72 this.resourceSet
= resourceSet
;