Changeset 6493


Ignore:
Timestamp:
Jun 25, 2014, 1:37:10 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1820: Improve support for resuming downloads from external files

Added ResumableConnectionManager and implemented this for the built-in HttpConnectionManager.

Location:
branches/3.3-stable/src/core/net/sf/basedb
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-stable/src/core/net/sf/basedb/core/File.java

    r6491 r6493  
    3939import net.sf.basedb.util.uri.ConnectionManager;
    4040import net.sf.basedb.util.uri.ConnectionManagerUtil;
     41import net.sf.basedb.util.uri.ResumableConnectionManager;
    4142import net.sf.basedb.util.uri.UriMetadata;
    4243
     
    14521453    InputStream download = null;
    14531454    Location location = getLocation();
     1455    boolean offsetHandled = false;
    14541456    try
    14551457    {
     
    14581460        ConnectionParameters server = getServerInfo();
    14591461        ConnectionManager manager = ConnectionManagerUtil.createConnectionManager(this, server);
    1460         download = manager.getInputStream();
     1462        if (manager instanceof ResumableConnectionManager)
     1463        {
     1464          download = ((ResumableConnectionManager)manager).getInputStream(offset);
     1465          offsetHandled = true;
     1466        }
     1467        else
     1468        {
     1469          download = manager.getInputStream();
     1470        }
    14611471        setMetadataFromURI(manager.getMetadata());
    14621472        if (download == null)
     
    14901500      }
    14911501     
    1492       if (offset > 0)
     1502      if (offset > 0 && !offsetHandled)
    14931503      {
    14941504        if (!(download.skip(offset) == offset) && download.read() != -1)
  • branches/3.3-stable/src/core/net/sf/basedb/util/uri/ConnectionManager.java

    r5582 r6493  
    3333  for each use of an URI. Implementations doens't have to provide a public
    3434  no-argument constructor.
     35  <p>
     36  NOTE! Also consider implementing the {@link ResumableConnectionManager}
     37  interface if the protocol supports setting a start offset for the
     38  download.
    3539
    3640  @author Nicklas
  • branches/3.3-stable/src/core/net/sf/basedb/util/uri/ConnectionManagerFactory.java

    r5599 r6493  
    7979    the given URI. Unless otherwise noted it is expected that
    8080    this method create a new connection manager for each call.
     81    <p>
     82    NOTE! Also consider if it is possible for the connection manager
     83    to implement the {@link ResumableConnectionManager} interface.
     84    This will improve support for resuming downloads at a specified
     85    location.
    8186   
    8287    @param uri The URI to access (required)
  • branches/3.3-stable/src/core/net/sf/basedb/util/uri/http/HttpConnectionManager.java

    r5870 r6493  
    4646import net.sf.basedb.util.uri.CloseResourceInputStream;
    4747import net.sf.basedb.util.uri.ConnectionParameters;
    48 import net.sf.basedb.util.uri.ConnectionManager;
     48import net.sf.basedb.util.uri.ResumableConnectionManager;
    4949import net.sf.basedb.util.uri.UriMetadata;
    5050
     
    6060*/
    6161public class HttpConnectionManager
    62   implements ConnectionManager
     62  implements ResumableConnectionManager
    6363{
    6464
     
    8383    return uri;
    8484  }
    85 
     85 
    8686  @Override
    8787  public InputStream getInputStream()
     88    throws IOException
     89  {
     90    return getInputStream(0);
     91  }
     92
     93  @Override
     94  public InputStream getInputStream(long offset)
    8895    throws IOException
    8996  {
     
    94101    {
    95102      HttpGet get = new HttpGet(uri);
     103      if (offset > 0)
     104      {
     105        get.addHeader("Range", "bytes="+offset + "-");
     106      }
    96107      client = createHttpClient(uri, parameters);
    97108      HttpResponse response = client.execute(get);
Note: See TracChangeset for help on using the changeset viewer.