add test case
[vfc/nfvo/driver/ems.git] / ems / boco / src / main / java / org / onap / vfc / nfvo / emsdriver / commons / ftp / AFtpRemoteFile.java
1 /**
2  * Copyright 2017 BOCO Corporation.  CMCC 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.vfc.nfvo.emsdriver.commons.ftp;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.util.Date;
21
22 import org.apache.commons.net.ftp.FTPClient;
23 import org.apache.commons.net.ftp.FTPFile;
24
25 public class AFtpRemoteFile implements RemoteFile{
26         protected FTPClient ftpClient = null;
27         protected FTPFile ftpFile = null;
28         protected String currDir = null;
29         
30         public AFtpRemoteFile(FTPFile rfile, FTPClient ftpClient, String currDir) 
31                 throws IOException {
32                 this.ftpClient = ftpClient;
33                 this.ftpFile = rfile;
34                 this.currDir = currDir;
35         }
36         
37         public long getSize() {
38                 return ftpFile.getSize();
39         }
40         
41         public String getFileName() {
42                 return ftpFile.getName();
43         }
44         
45         public String getAbsFileName() {
46                 return currDir.concat(getFileName());
47         }
48         
49         public boolean isDirectory() {
50                 return ftpFile.isDirectory();
51         }
52         public boolean isFile() {
53                 return ftpFile.isFile();
54         }
55         
56         public String getOwner() {
57                 return ftpFile.getUser();
58         }
59
60         public Date getModifyDate() {
61                 return ftpFile.getTimestamp().getTime();
62         }
63         public boolean renameTo(String newName) throws IOException {
64                 return ftpClient.rename(
65                                 currDir.concat(getFileName()), newName);
66         }
67         public boolean remove() throws IOException {
68                 return ftpClient.deleteFile(
69                                 currDir.concat(getFileName()));
70         }
71         
72         public InputStream getInputStream() throws IOException {
73                 return ftpClient.retrieveFileStream(this.getAbsFileName());
74         }
75         
76         public void release() {
77                 ftpClient = null;
78                 ftpFile = null;
79                 currDir = null;
80         }
81 }