use of ch.ethz.ssh2.SFTPv3FileHandle in project orion-kit by lijiahangmax.
the class SftpExecutor method touch.
/**
* 创建文件
*
* @param path 文件绝对路径
* @param truncate 是否截断
*/
public void touch(String path, boolean truncate) {
try {
this.mkdirs(Files1.getParentPath(path), DEFAULT_PERMISSIONS);
SFTPv3FileHandle handle;
if (truncate) {
handle = client.createFileTruncate(path);
} else {
handle = client.createFile(path);
}
handle.getClient().closeFile(handle);
} catch (Exception e) {
throw Exceptions.sftp(e);
}
}
use of ch.ethz.ssh2.SFTPv3FileHandle in project orion-kit by lijiahangmax.
the class SftpExecutor method write.
/**
* 拼接/替换/写入到文件
*
* @param path 文件绝对路径
* @param in 输入流
* @param fileOffset 文件偏移量
* @param entry 写入信息
* @param lines 行
* @param type 1write 2replace 3append
* @throws IOException IOException
*/
private void write(String path, long fileOffset, InputStream in, StreamEntry entry, List<String> lines, int type) throws IOException {
SFTPv3FileHandle handle = null;
try {
this.touch(path, type == 1);
if (type == 3) {
handle = client.openFileRWAppend(path);
} else {
handle = client.openFileRW(path);
}
this.write(handle, fileOffset, in, entry, lines);
} catch (Exception e) {
throw Exceptions.io("cannot write file " + path, e);
} finally {
if (handle != null) {
handle.getClient().closeFile(handle);
}
}
}
use of ch.ethz.ssh2.SFTPv3FileHandle in project hudson-2.x by hudson.
the class SFTPClient method writeToFile.
/**
* Creates a new file and writes to it.
*/
public OutputStream writeToFile(String path) throws IOException {
final SFTPv3FileHandle h = createFile(path);
return new OutputStream() {
private long offset = 0;
public void write(int b) throws IOException {
write(new byte[] { (byte) b });
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
SFTPClient.this.write(h, offset, b, off, len);
offset += len;
}
@Override
public void close() throws IOException {
closeFile(h);
}
};
}
use of ch.ethz.ssh2.SFTPv3FileHandle in project hudson-2.x by hudson.
the class SFTPClient method read.
public InputStream read(String file) throws IOException {
final SFTPv3FileHandle h = openFileRO(file);
return new InputStream() {
private long offset = 0;
public int read() throws IOException {
byte[] b = new byte[1];
if (read(b) < 0)
return -1;
return b[0];
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int r = SFTPClient.this.read(h, offset, b, off, len);
if (r < 0)
return -1;
offset += r;
return r;
}
@Override
public long skip(long n) throws IOException {
offset += n;
return n;
}
@Override
public void close() throws IOException {
closeFile(h);
}
};
}
use of ch.ethz.ssh2.SFTPv3FileHandle in project Payara by payara.
the class SFTPClient method writeToFile.
/**
* Creates a new file and writes to it.
*/
public OutputStream writeToFile(String path) throws IOException {
path = normalizePath(path);
final SFTPv3FileHandle h = createFile(path);
return new OutputStream() {
private long offset = 0;
public void write(int b) throws IOException {
write(new byte[] { (byte) b });
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
SFTPClient.this.write(h, offset, b, off, len);
offset += len;
}
@Override
public void close() throws IOException {
closeFile(h);
}
};
}
Aggregations