Changeset 2522


Ignore:
Timestamp:
Jun 25, 2014, 1:45:46 PM (9 years ago)
Author:
Nicklas Nordborg
Message:

References #611: Create package for supporting external files via SFTP

Implement support for ResumableConnectionManager.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.xfiles/trunk/src/net/sf/basedb/xfiles/sftp/SftpConnectionManager.java

    r2520 r2522  
    3636import net.sf.basedb.util.uri.CloseResourceInputStream;
    3737import net.sf.basedb.util.uri.ConnectionParameters;
    38 import net.sf.basedb.util.uri.ConnectionManager;
     38import net.sf.basedb.util.uri.ResumableConnectionManager;
    3939import net.sf.basedb.util.uri.UriMetadata;
    4040import net.sf.basedb.xfiles.MultiCloseable;
     
    5151*/
    5252public class SftpConnectionManager
    53   implements ConnectionManager
     53  implements ResumableConnectionManager
    5454{
    5555
     
    6565 
    6666  /*
    67     From the UriHandler interface
    68     -----------------------------
     67    From the ResumableConnectionManager interface
     68    ---------------------------------------------
    6969  */
    7070  @Override
     
    7676  @Override
    7777  public InputStream getInputStream()
     78    throws IOException
     79  {
     80    return getInputStream(0);
     81  }
     82
     83  @Override
     84  public InputStream getInputStream(long offset)
    7885    throws IOException
    7986  {
     
    8895      sftp = ssh.newSFTPClient();
    8996      remote = sftp.open(uri.getPath(), EnumSet.of(OpenMode.READ));
     97      // Constructor is only accepting an 'int' parameter so we need to use skip() instead
     98      InputStream tmp = remote.new RemoteFileInputStream();
     99      if (offset > 0) tmp.skip(offset);
    90100      stream = new CloseResourceInputStream(
    91         new BufferedInputStream(remote.new RemoteFileInputStream(), XFiles.DEFAULT_BUFFER_SIZE),
     101        new BufferedInputStream(tmp, XFiles.DEFAULT_BUFFER_SIZE),
    92102        new MultiCloseable(remote, sftp, ssh));
    93103    }
Note: See TracChangeset for help on using the changeset viewer.