public abstract class BaseSftpExecutor extends Object implements ISftpExecutor
Modifier and Type | Field and Description |
---|---|
protected int |
bufferSize
默认缓冲区大小
|
protected String |
charset
编码格式
|
Modifier | Constructor and Description |
---|---|
protected |
BaseSftpExecutor() |
Modifier and Type | Method and Description |
---|---|
void |
append(String path,
byte[] bs,
int off,
int len)
拼接 文件不存在则报错
|
void |
append(String path,
InputStream in)
拼接流 文件不存在则报错
|
protected abstract void |
doAppend(String path,
InputStream in,
StreamEntry entry)
执行拼接
|
protected void |
doMakeDir(String path,
Consumer<String> creative)
执行创建文件夹
|
protected abstract void |
doMove(String source,
String target)
移动文件
|
protected abstract long |
doTransfer(String path,
OutputStream out,
long skip,
int size,
boolean close)
执行传输
|
void |
downloadDir(String remoteDir,
String localDir,
boolean child)
下载文件夹
远程文件夹不存在/是个文件 则会报错
|
void |
downloadFile(String remoteFile,
OutputStream out,
boolean close)
下载文件
远程文件不存在则会报错
|
void |
downloadFile(String remoteFile,
String localFile)
下载文件
远程文件不存在则会报错
|
protected abstract void |
doWrite(String path,
InputStream in,
StreamEntry entry)
执行写入
|
int |
getBufferSize()
获取缓冲区大小
|
String |
getCharset()
获取文件名编码
|
protected boolean |
isSameParentPath(String source,
String target)
检查是否为相同父级目录
|
List<SftpFile> |
listDirs(String path,
boolean child)
文件夹列表
文件夹不存在则返回空集合
|
List<SftpFile> |
listFiles(String path,
boolean child,
boolean dir)
文件列表
文件夹不存在则返回空集合
|
List<SftpFile> |
listFilesFilter(String path,
SftpFileFilter filter,
boolean child,
boolean dir)
查询文件列表
文件夹不存在则返回空集合
|
void |
makeDirectories(String path)
创建文件夹 递归
文件夹存在 父文件夹不存 不会报错
路径是文件并且已存在 则会报错
|
void |
move(String source,
String target)
移动文件 / 改名
原始文件存在 则会报错
目标文件存在 不会报错
|
void |
remove(String path)
递归删除文件或文件夹
文件不存在 不会报错
|
long |
transfer(String path,
OutputStream out,
long skip,
int size)
读取字节到输出流
文件不存在则报错
|
long |
transfer(String path,
String file,
long skip)
读取文件到本地
文件不存在则报错
|
void |
uploadDir(String remoteDir,
String localDir,
boolean child)
上传文件夹
/root/target > /home/ljh/target
如果远程文件夹不设置 /target 则会将 /home/ljh/target 的文件传输到 /root
远程文件夹不存在不会报错
远程文件夹是个文件则会报错
|
void |
uploadFile(String remoteFile,
InputStream in,
boolean close)
上传文件
远程文件存在则会覆盖
远程文件是个文件夹则会报错
|
void |
uploadFile(String remoteFile,
String localFile)
上传文件
远程文件存在则会覆盖
远程文件是个文件夹则会报错
|
void |
write(String path,
byte[] bs,
int off,
int len)
写入 文件不存在则报错
|
void |
write(String path,
InputStream in)
写入流 文件不存在则报错
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
append, append, bufferSize, changeGroup, changeMode, changeOwner, charset, download, download, downloadDir, downloadDir, downloadDir, downloadFile, downloadFile, getFile, getFile, getHome, getLinkPath, getPath, getServerVersion, getSize, hardLink, isConnected, isExist, link, list, listDirs, listFiles, listFiles, listFilesFilter, listFilesFilter, makeDirectory, openInputStream, openInputStream, openOutputStream, openOutputStream, read, read, read, read, removeDir, removeFile, sendSignal, setFileAttribute, setModifyTime, symLink, touch, touch, touchTruncate, transfer, transfer, transfer, transfer, transfer, truncate, upload, upload, uploadDir, uploadDir, uploadDir, uploadFile, uploadFile, write, write
close
protected String charset
protected int bufferSize
public void makeDirectories(String path)
ISftpExecutor
文件夹存在 父文件夹不存 不会报错 路径是文件并且已存在 则会报错
makeDirectories
in interface ISftpExecutor
path
- 文件夹绝对路径public void remove(String path)
ISftpExecutor
文件不存在 不会报错
remove
in interface ISftpExecutor
path
- 路径public void move(String source, String target)
ISftpExecutor
原始文件存在 则会报错 目标文件存在 不会报错
move
in interface ISftpExecutor
source
- 原文件绝对路径target
- 目标文件(绝对路径 相对路径) / 文件名称public long transfer(String path, OutputStream out, long skip, int size) throws IOException
ISftpExecutor
文件不存在则报错
transfer
in interface ISftpExecutor
path
- 文件绝对路径out
- 输出流skip
- 跳过字数size
- 读取长度 -1 读取全部IOException
- IOExceptionpublic long transfer(String path, String file, long skip) throws IOException
ISftpExecutor
文件不存在则报错
transfer
in interface ISftpExecutor
path
- 文件绝对路径file
- 本地文件路径skip
- 跳过字数IOException
- IOExceptionpublic void write(String path, InputStream in) throws IOException
ISftpExecutor
write
in interface ISftpExecutor
path
- pathin
- inIOException
- IOExceptionpublic void write(String path, byte[] bs, int off, int len) throws IOException
ISftpExecutor
write
in interface ISftpExecutor
path
- pathbs
- bsoff
- offlen
- lenIOException
- IOExceptionpublic void append(String path, InputStream in) throws IOException
ISftpExecutor
append
in interface ISftpExecutor
path
- pathin
- inIOException
- IOExceptionpublic void append(String path, byte[] bs, int off, int len) throws IOException
ISftpExecutor
append
in interface ISftpExecutor
path
- pathbs
- bsoff
- offlen
- lenIOException
- IOExceptionpublic void uploadFile(String remoteFile, String localFile) throws IOException
ISftpExecutor
远程文件存在则会覆盖 远程文件是个文件夹则会报错
uploadFile
in interface ISftpExecutor
remoteFile
- 远程文件localFile
- 本地文件IOException
- IOExceptionpublic void uploadFile(String remoteFile, InputStream in, boolean close) throws IOException
ISftpExecutor
远程文件存在则会覆盖
远程文件是个文件夹则会报错
uploadFile
in interface ISftpExecutor
remoteFile
- 远程文件in
- inputclose
- closeIOException
- IOExceptionpublic void uploadDir(String remoteDir, String localDir, boolean child) throws IOException
ISftpExecutor
/root/target > /home/ljh/target 如果远程文件夹不设置 /target 则会将 /home/ljh/target 的文件传输到 /root
远程文件夹不存在不会报错 远程文件夹是个文件则会报错
uploadDir
in interface ISftpExecutor
remoteDir
- 远程文件夹localDir
- 本地文件夹 上传时不包含此文件夹child
- 是否遍历上传IOException
- IOExceptionpublic void downloadFile(String remoteFile, String localFile) throws IOException
ISftpExecutor
远程文件不存在则会报错
downloadFile
in interface ISftpExecutor
remoteFile
- 远程文件路径localFile
- 本地文件路径IOException
- IOExceptionpublic void downloadFile(String remoteFile, OutputStream out, boolean close) throws IOException
ISftpExecutor
远程文件不存在则会报错
downloadFile
in interface ISftpExecutor
remoteFile
- 远程文件路径out
- outputclose
- 是否自动关闭IOException
- IOExceptionpublic void downloadDir(String remoteDir, String localDir, boolean child) throws IOException
ISftpExecutor
远程文件夹不存在/是个文件 则会报错
downloadDir
in interface ISftpExecutor
remoteDir
- 远程文件夹localDir
- 本地文件夹child
- 是否递归子文件夹下载IOException
- IOExceptionpublic List<SftpFile> listFiles(String path, boolean child, boolean dir)
ISftpExecutor
文件夹不存在则返回空集合
listFiles
in interface ISftpExecutor
path
- 文件夹绝对路径child
- 是否递归子文件夹dir
- 是否添加文件夹public List<SftpFile> listDirs(String path, boolean child)
ISftpExecutor
文件夹不存在则返回空集合
listDirs
in interface ISftpExecutor
path
- 文件夹绝对路径child
- 是否递归public List<SftpFile> listFilesFilter(String path, SftpFileFilter filter, boolean child, boolean dir)
ISftpExecutor
文件夹不存在则返回空集合
listFilesFilter
in interface ISftpExecutor
path
- 文件夹绝对路径filter
- 过滤器child
- 是否递归子文件夹dir
- 是否添加文件夹protected abstract void doMove(String source, String target)
source
- 原文件绝对路径target
- 目标文件 绝对路径 相对路径都可以protected void doMakeDir(String path, Consumer<String> creative)
path
- pathcreative
- 创建器protected abstract long doTransfer(String path, OutputStream out, long skip, int size, boolean close) throws IOException
path
- pathout
- outskip
- skipsize
- sizeclose
- closeIOException
- IOExceptionprotected abstract void doWrite(String path, InputStream in, StreamEntry entry) throws IOException
path
- pathin
- inentry
- entryIOException
- IOExceptionprotected abstract void doAppend(String path, InputStream in, StreamEntry entry) throws IOException
path
- pathin
- inentry
- entryIOException
- IOExceptionprotected boolean isSameParentPath(String source, String target)
source
- sourcetarget
- targetpublic int getBufferSize()
ISftpExecutor
getBufferSize
in interface ISftpExecutor
public String getCharset()
ISftpExecutor
getCharset
in interface ISftpExecutor
Copyright © 2024. All rights reserved.