All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feilong.net.filetransfer.FileTransfer Maven / Gradle / Ivy

Go to download

feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.

There is a newer version: 4.0.8
Show newest version
/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.net.filetransfer;

import java.util.Map;

import com.feilong.io.entity.FileInfoEntity;

/**
 * 通用的文件传输 .
 * 
 * 

开放出来的方法有:

* *
* 下载: *
    *
  • {@link #download(String, String...)}
  • *
* * 上传: *
    *
  • {@link #upload(String, String...)}
  • *
* * 删除: *
    *
  • {@link #delete(String[])}
  • *
* *
* * @author feilong * @since 1.7.1 */ public interface FileTransfer{ //-----------------------------下载----------------------------------------------------- /** * 打开一次链接,将一批远程文件/文件夹 (remotePaths)循环下载到本地目录 localAbsoluteDirectoryPath. * *

说明:

*
*
    *
  1. 如果 localAbsoluteDirectoryPath本地目录地址不存在,会自动级联创建
  2. *
  3. 如果 remotePaths里面有文件是个文件(file),会将此文件直接下载到 localAbsoluteDirectoryPath 目录下面
  4. *
  5. * 如果 remotePaths里面有文件是个文件夹(Directory),会先在 localAbsoluteDirectoryPath 下面创建同名文件夹,再递归下载文件(相当于整个文件夹下载下来) *
  6. *
  7. 如果 localAbsoluteDirectoryPath 目录下面已经存在和remotePaths里面同名的文件,那么会下载覆盖
  8. *
*
* *

示例:

* *
* *
     * String[] remotePaths = {
     *                          "/upload/Inbound/InventoryAdjustments/Archive/2016-07-15_11-58-58.389-INVENTORY_ADJUSTMENTS_3PL_20160715-154626-073.XML",
     *                          "/upload/Inbound/InventoryAdjustments/Archive/2016-07-22_10-46-00.318-INVENTORY_ADJUSTMENTS_3PL_20160722-144626-073.XML" };
     * String localAbsoluteDirectoryPath = "E:\\test\\1";
     * fileTransfer.download(localAbsoluteDirectoryPath, remotePaths);
     * 
* *
* * @param localAbsoluteDirectoryPath * 本地绝对的目录
* 如果不存在,支持级联创建
* 如果 localAbsoluteDirectoryPath 是null,抛出 {@link NullPointerException}
* 如果 localAbsoluteDirectoryPath 是blank,抛出 {@link IllegalArgumentException}
* @param remotePaths * 一批远程文件远程路径,
* 可以是文件,也可以文件夹
* 如果 remotePaths 是null,抛出 {@link NullPointerException}
* 如果 remotePaths 是empty,抛出 {@link IllegalArgumentException}
* 任意一个值 null或者empty, {@link IllegalArgumentException} */ void download(String localAbsoluteDirectoryPath,String...remotePaths); //-----------------------------上传----------------------------------------------------- /** * 支持将多个不定路径文件 batchLocalFileFullPaths 上传到远程文件夹 remoteDirectory. * *
     * 
     * String[] batchLocalFileFullPaths = { "E:\\test", "E:\\1.jpg" };
     * 
     * String remoteDirectory = "/webstore/InlineSales_Test/2011-07-05/";
     * 
* *

说明:

*
*
    *
  1. 如果 localFileFullPath 是个文件(file), 会将此文件直接上传到 remoteDirectory 目录下面
  2. *
  3. 如果 localFileFullPath 是个文件夹(Directory), 首先会先在 remoteDirectory 下面创建同名文件夹,并递归上传文件(相当于整个文件夹上传)
  4. *
  5. 新的文件的名称和你上传文件的名称一样的,也就是,你传的什么名称文件/文件夹到服务器就是什么名称文件/文件夹
  6. *
*
* * @param remoteDirectory * 远程文件夹名称,你要传到哪个文件夹下面 * @param batchLocalFileFullPaths * 上传的文件名(数组),全路径
* 不能为 null或者empty,否则 {@link IllegalArgumentException}
* 任意一个值 null或者empty, {@link IllegalArgumentException}
* 任意一个值localFileFullPath文件不存在, {@link IllegalArgumentException} * @return 全部成功返回true,否则一旦有失败则返回false
* 如果 remoteDirectory 是null,抛出 {@link NullPointerException}
* 如果 remoteDirectory 是blank,抛出 {@link IllegalArgumentException}
*/ boolean upload(String remoteDirectory,String...batchLocalFileFullPaths); //-----------------------------删除----------------------------------------------------- /** * 删除远程的一组文件 remoteAbsolutePaths. * *
     * 
     * String[] remoteAbsolutePaths = { "/webstore/InlineSales_Test/2011-07-05/test", "/webstore/InlineSales_Test/2011-07-05/1.cvs" };
     * 
* *

说明:

*
*
    *
  1. 不管是windows还是linux、unix,都不能在同一目录结构下创建同名的文件夹和文件
  2. *
  3. 如果 remoteAbsolutePath 是个文件(file), 会将此文件直接删除
  4. *
  5. 如果 remoteAbsolutePath 是个文件夹(Directory),首先递归删除该文件夹下面 所有的文件/文件夹再删除此文件夹
  6. *
  7. 不支持删除 '/'根目录 (危险)
  8. *
*
* * @param remoteAbsolutePaths * 一组文件,绝对路径
* 任意一个值 null或者empty, {@link IllegalArgumentException}
* 任意一个值= / , {@link IllegalArgumentException} 危险!! * @return 如果 remoteAbsolutePaths 是null,抛出 {@link NullPointerException}
* 如果 remoteAbsolutePaths 是empty,抛出 {@link IllegalArgumentException}
* * 删除成功返回true,否则false
* 不支持 删除全部 危险
* 一旦有一个文件 null或者empty抛错 */ boolean delete(String...remoteAbsolutePaths); //----------------------------读取----------------------------------------------------- /** * 获得某特定文件夹下面指定文件名相关信息. * *

* 注意:该方法不支持级联, 只支持获取 remotePath 下面的一级目录或者文件 *

* *

示例:

* *
* * 比如 /upload/test/HERSCHEL 下面有 文件夹 test ,以及 sales_20200601101812.txt ,ST_20200601101812.txt 两个文件 * *
     * String remoteAbsolutePath = "/upload/test/HERSCHEL";
     * LOGGER.debug(JsonUtil.format(fileTransfer.getFileEntityMap(remoteAbsolutePath)));
     * 
     * 
* * 返回: * *
    {
            "ST_20200601101812.txt":         {
                "fileType": "FILE",
                "formatLastModified": "01-19 17:56",
                "formatSize": "23.23KB",
                "lastModified": 1590977895,
                "name": "ST_20200601101812.txt",
                "size": 23788
            },
            "sales_20200601101812.txt":         {
                "fileType": "FILE",
                "formatLastModified": "01-19 17:56",
                "formatSize": "185.78KB",
                "lastModified": 1590977894,
                "name": "sales_20200601101812.txt",
                "size": 190240
            },
            "test":         {
                "fileType": "DIRECTORY",
                "formatLastModified": "01-19 18:38",
                "formatSize": "4KB",
                "lastModified": 1593510879,
                "name": "test",
                "size": 4096
            }
        }
     * 
     * 
* *
* * @param remotePath * 远程地址 * @param fileNames * 文件名称组 * @return 如果 remotePath 是null,抛出 {@link NullPointerException}
* 如果 remotePath 是blank,抛出 {@link IllegalArgumentException}
* 如果 fileNames 是null 或者是 empty,那么返回这个 remotePath 下面所有的文件
* 如果 remotePath 不存在,会抛出异常,示例 com.feilong.net.filetransfer.FileTransferException: * remotePath:[/home/appuser/2013-12-04-1938],cause by:[2: No such file]
* 如果 remotePath 是个空的文件夹,会返回 empty MAP */ Map getFileEntityMap(String remotePath,String...fileNames); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy