From 48ded2421114c4c87ef3f8005c9f793a5d077cbd Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Tue, 10 Jan 2012 14:24:22 -0800 Subject: ganymed-ssh2-build251beta1 Signed-off-by: Mike Lockwood --- src/main/java/ch/ethz/ssh2/SFTPOutputStream.java | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/main/java/ch/ethz/ssh2/SFTPOutputStream.java (limited to 'src/main/java/ch/ethz/ssh2/SFTPOutputStream.java') diff --git a/src/main/java/ch/ethz/ssh2/SFTPOutputStream.java b/src/main/java/ch/ethz/ssh2/SFTPOutputStream.java new file mode 100644 index 0000000..62139db --- /dev/null +++ b/src/main/java/ch/ethz/ssh2/SFTPOutputStream.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011 David Kocher. All rights reserved. + * Please refer to the LICENSE.txt for licensing details. + */ +package ch.ethz.ssh2; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * @version $Id:$ + */ +public class SFTPOutputStream extends OutputStream +{ + + private SFTPv3FileHandle handle; + + /** + * Offset (in bytes) in the file to write + */ + private long writeOffset = 0; + + public SFTPOutputStream(SFTPv3FileHandle handle) { + this.handle = handle; + } + + /** + * Writes len bytes from the specified byte array + * starting at offset off to this output stream. + * The general contract for write(b, off, len) is that + * some of the bytes in the array b are written to the + * output stream in order; element b[off] is the first + * byte written and b[off+len-1] is the last byte written + * by this operation. + * + * @see SFTPv3Client#write(SFTPv3FileHandle,long,byte[],int,int) + */ + @Override + public void write(byte[] buffer, int offset, int len) throws IOException + { + // We can just blindly write the whole buffer at once. + // if len > 32768, then the write operation will + // be split into multiple writes in SFTPv3Client#write. + handle.getClient().write(handle, writeOffset, buffer, offset, len); + + writeOffset += len; + } + + @Override + public void write(int b) throws IOException { + byte[] buffer = new byte[1]; + buffer[0] = (byte) b; + handle.getClient().write(handle, writeOffset, buffer, 0, 1); + + writeOffset += 1; + } + + public long skip(long n) { + writeOffset += n; + return n; + } + + @Override + public void close() throws IOException { + handle.getClient().closeFile(handle); + } +} \ No newline at end of file -- cgit v1.2.3