Mercurial > 510Connectbot
comparison src/ch/ethz/ssh2/SFTPOutputStream.java @ 273:91a31873c42a ganymed
start conversion from trilead to ganymed
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 18 Jul 2014 11:21:46 -0700 |
parents | |
children | 071eccdff8ea |
comparison
equal
deleted
inserted
replaced
272:ce2f4e397703 | 273:91a31873c42a |
---|---|
1 /* | |
2 * Copyright (c) 2011 David Kocher. All rights reserved. | |
3 * Please refer to the LICENSE.txt for licensing details. | |
4 */ | |
5 package ch.ethz.ssh2; | |
6 | |
7 import java.io.IOException; | |
8 import java.io.OutputStream; | |
9 | |
10 /** | |
11 * @version $Id: SFTPOutputStream.java 151 2014-04-28 10:03:39Z dkocher@sudo.ch $ | |
12 */ | |
13 public class SFTPOutputStream extends OutputStream { | |
14 | |
15 private SFTPFileHandle handle; | |
16 | |
17 /** | |
18 * Offset (in bytes) in the file to write | |
19 */ | |
20 private long writeOffset = 0; | |
21 | |
22 public SFTPOutputStream(SFTPFileHandle handle) { | |
23 this.handle = handle; | |
24 } | |
25 | |
26 /** | |
27 * Writes <code>len</code> bytes from the specified byte array | |
28 * starting at offset <code>off</code> to this output stream. | |
29 * The general contract for <code>write(b, off, len)</code> is that | |
30 * some of the bytes in the array <code>b</code> are written to the | |
31 * output stream in order; element <code>b[off]</code> is the first | |
32 * byte written and <code>b[off+len-1]</code> is the last byte written | |
33 * by this operation. | |
34 * | |
35 * @see SFTPClient#write(SFTPFileHandle, long, byte[], int, int) | |
36 */ | |
37 @Override | |
38 public void write(byte[] buffer, int offset, int len) throws IOException { | |
39 // We can just blindly write the whole buffer at once. | |
40 // if <code>len</code> > 32768, then the write operation will | |
41 // be split into multiple writes in SFTPv3Client#write. | |
42 handle.getClient().write(handle, writeOffset, buffer, offset, len); | |
43 | |
44 writeOffset += len; | |
45 } | |
46 | |
47 @Override | |
48 public void write(int b) throws IOException { | |
49 byte[] buffer = new byte[1]; | |
50 buffer[0] = (byte) b; | |
51 handle.getClient().write(handle, writeOffset, buffer, 0, 1); | |
52 | |
53 writeOffset += 1; | |
54 } | |
55 | |
56 public long skip(long n) { | |
57 writeOffset += n; | |
58 return n; | |
59 } | |
60 | |
61 @Override | |
62 public void close() throws IOException { | |
63 handle.getClient().closeFile(handle); | |
64 } | |
65 } |