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