@Test public void testReadInterrupt() throws Exception { final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.ch", new Credentials( PreferencesFactory.get().getProperty("connection.login.anon.name"), null )); final DAVSession session = new DAVSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()); service.connect(session, PathCache.empty(), new DisabledCancelCallback()); final Path test = new Path("/trunk/LICENSE.txt", EnumSet.of(Path.Type.file)); final TransferStatus status = new TransferStatus(); { final InputStream in = new DAVReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in.read()); in.close(); } { final InputStream in = new DAVReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); in.close(); } session.close(); }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<Header> headers = new ArrayList<Header>(this.headers()); if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if(-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if(log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } headers.add(new BasicHeader(HttpHeaders.RANGE, header)); headers.add(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } try { final StringBuilder resource = new StringBuilder(new DAVPathEncoder().encode(file)); if(!status.getParameters().isEmpty()) { resource.append("?"); } for(Map.Entry<String, String> parameter : status.getParameters().entrySet()) { if(!resource.toString().endsWith("?")) { resource.append("&"); } resource.append(URIEncoder.encode(parameter.getKey())) .append("=") .append(URIEncoder.encode(parameter.getValue())); } final ContentLengthStatusInputStream stream = session.getClient().get(resource.toString(), headers); if(status.isAppend()) { if(stream.getCode() == HttpStatus.SC_OK) { log.warn(String.format("Range header not supported. Skipping %d bytes in file %s.", status.getOffset(), file)); stream.skip(status.getOffset()); } } return stream; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Download {0} failed", e, file); } }
DAVReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<Header> headers = new ArrayList<Header>(this.headers()); if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if(-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if(log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } headers.add(new BasicHeader(HttpHeaders.RANGE, header)); headers.add(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } try { final StringBuilder resource = new StringBuilder(new DAVPathEncoder().encode(file)); if(!status.getParameters().isEmpty()) { resource.append("?"); } for(Map.Entry<String, String> parameter : status.getParameters().entrySet()) { if(!resource.toString().endsWith("?")) { resource.append("&"); } resource.append(URIEncoder.encode(parameter.getKey())) .append("=") .append(URIEncoder.encode(parameter.getValue())); } final ContentLengthStatusInputStream stream = session.getClient().get(resource.toString(), headers); if(status.isAppend()) { if(stream.getCode() == HttpStatus.SC_OK) { log.warn(String.format("Range header not supported. Skipping %d bytes in file %s.", status.getOffset(), file)); stream.skip(status.getOffset()); } } return stream; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Download {0} failed", e, file); } } }
DAVReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<Header> headers = new ArrayList<Header>(this.headers()); if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if(-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if(log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } headers.add(new BasicHeader(HttpHeaders.RANGE, header)); headers.add(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } try { final StringBuilder resource = new StringBuilder(new DAVPathEncoder().encode(file)); if(!status.getParameters().isEmpty()) { resource.append("?"); } for(Map.Entry<String, String> parameter : status.getParameters().entrySet()) { if(!resource.toString().endsWith("?")) { resource.append("&"); } resource.append(URIEncoder.encode(parameter.getKey())) .append("=") .append(URIEncoder.encode(parameter.getValue())); } final ContentLengthStatusInputStream stream = session.getClient().get(resource.toString(), headers); if(status.isAppend()) { if(stream.getCode() == HttpStatus.SC_OK) { log.warn(String.format("Range header not supported. Skipping %d bytes in file %s.", status.getOffset(), file)); stream.skip(status.getOffset()); } } return stream; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Download {0} failed", e, file); } } DAVReadFeature(final DAVSession session); }
DAVReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<Header> headers = new ArrayList<Header>(this.headers()); if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if(-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if(log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } headers.add(new BasicHeader(HttpHeaders.RANGE, header)); headers.add(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } try { final StringBuilder resource = new StringBuilder(new DAVPathEncoder().encode(file)); if(!status.getParameters().isEmpty()) { resource.append("?"); } for(Map.Entry<String, String> parameter : status.getParameters().entrySet()) { if(!resource.toString().endsWith("?")) { resource.append("&"); } resource.append(URIEncoder.encode(parameter.getKey())) .append("=") .append(URIEncoder.encode(parameter.getValue())); } final ContentLengthStatusInputStream stream = session.getClient().get(resource.toString(), headers); if(status.isAppend()) { if(stream.getCode() == HttpStatus.SC_OK) { log.warn(String.format("Range header not supported. Skipping %d bytes in file %s.", status.getOffset(), file)); stream.skip(status.getOffset()); } } return stream; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Download {0} failed", e, file); } } DAVReadFeature(final DAVSession session); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file); Set<Header> headers(); }
DAVReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<Header> headers = new ArrayList<Header>(this.headers()); if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); final String header; if(-1 == range.getEnd()) { header = String.format("bytes=%d-", range.getStart()); } else { header = String.format("bytes=%d-%d", range.getStart(), range.getEnd()); } if(log.isDebugEnabled()) { log.debug(String.format("Add range header %s for file %s", header, file)); } headers.add(new BasicHeader(HttpHeaders.RANGE, header)); headers.add(new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "identity")); } try { final StringBuilder resource = new StringBuilder(new DAVPathEncoder().encode(file)); if(!status.getParameters().isEmpty()) { resource.append("?"); } for(Map.Entry<String, String> parameter : status.getParameters().entrySet()) { if(!resource.toString().endsWith("?")) { resource.append("&"); } resource.append(URIEncoder.encode(parameter.getKey())) .append("=") .append(URIEncoder.encode(parameter.getValue())); } final ContentLengthStatusInputStream stream = session.getClient().get(resource.toString(), headers); if(status.isAppend()) { if(stream.getCode() == HttpStatus.SC_OK) { log.warn(String.format("Range header not supported. Skipping %d bytes in file %s.", status.getOffset(), file)); stream.skip(status.getOffset()); } } return stream; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new HttpExceptionMappingService().map("Download {0} failed", e, file); } } DAVReadFeature(final DAVSession session); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file); Set<Header> headers();  }