0d3df052bdbc78ec4e79a990c11a7f14a92b3308
[vfc/nfvo/catalog.git] /
1 /**
2  * Copyright 2016 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openo.commontosca.catalog.filemanage.http;
17
18 import org.openo.commontosca.catalog.filemanage.FileManager;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import java.io.File;
23 import java.io.IOException;
24
25
26 public class HttpFileManagerImpl implements FileManager {
27   private static final Logger LOGGER = LoggerFactory.getLogger(HttpFileManagerImpl.class);
28
29   @Override
30   public boolean upload(String srcPath, String dstPath) {
31     boolean flag = true;
32     LOGGER.info("start upload file.srcPath:" + srcPath + " dstPath" + dstPath);
33     File srcFile = new File(srcPath);
34     if (!srcFile.exists()) {
35       LOGGER.error("src file not exist!");
36       return false;
37     }
38     // File dstFile = new File(ToolUtil.getHttpServerPath() + dstPath);
39     // LOGGER.info("dstFile AbsolutePath:" + dstFile.getAbsolutePath());
40     String targetDir = ToolUtil.getHttpServerAbsolutePath() + dstPath;
41     try {
42       ToolUtil.copyDirectory(srcPath, targetDir, true);
43     } catch (IOException e1) {
44       flag = false;
45       LOGGER.error("copy file failed.errorMsg:" + e1.getMessage());
46     }
47     LOGGER.info("upload file success!");
48     return flag;
49   }
50
51   @Override
52   public boolean download(String srcPath, String dstPath) {
53     // TODO Auto-generated method stub
54     return false;
55   }
56
57   @Override
58   public boolean delete(String srcPath) {
59     boolean flag = true;
60     LOGGER.info("start delete file from http server.srcPath:" + srcPath);
61     flag = ToolUtil.deleteDir(new File(ToolUtil.getHttpServerAbsolutePath() + srcPath));
62     LOGGER.info("delete file from http server end.flag:" + flag);
63     return flag;
64   }
65
66
67 }