@Test public void testReadRange() throws Exception { final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); container.attributes().setRegion("IAD"); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new SwiftTouchFeature(session, new SwiftRegionService(session)).touch(test, new TransferStatus()); final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes(); final SwiftRegionService regionService = new SwiftRegionService(session); final HttpResponseOutputStream<StorageObject> out = new SwiftWriteFeature(session, regionService).write(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); assertNotNull(out.getStatus()); final TransferStatus status = new TransferStatus(); status.setLength(content.length); status.setAppend(true); status.setOffset(100L); final InputStream in = new SwiftReadFeature(session, regionService).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); assertEquals(content.length, status.getLength(), 0L); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100); new StreamCopier(status, status).transfer(in, buffer); final byte[] reference = new byte[content.length - 100]; System.arraycopy(content, 100, reference, 0, content.length - 100); assertArrayEquals(reference, buffer.toByteArray()); in.close(); new SwiftDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { status.setChecksum(Checksum.NONE); final Response response; if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); if(-1 == range.getEnd()) { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart()); } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart(), range.getLength()); } } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file)); } return new HttpMethodReleaseInputStream(response.getResponse()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } }
SwiftReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { status.setChecksum(Checksum.NONE); final Response response; if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); if(-1 == range.getEnd()) { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart()); } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart(), range.getLength()); } } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file)); } return new HttpMethodReleaseInputStream(response.getResponse()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } } }
SwiftReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { status.setChecksum(Checksum.NONE); final Response response; if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); if(-1 == range.getEnd()) { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart()); } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart(), range.getLength()); } } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file)); } return new HttpMethodReleaseInputStream(response.getResponse()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } } SwiftReadFeature(final SwiftSession session, final SwiftRegionService regionService); }
SwiftReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { status.setChecksum(Checksum.NONE); final Response response; if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); if(-1 == range.getEnd()) { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart()); } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart(), range.getLength()); } } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file)); } return new HttpMethodReleaseInputStream(response.getResponse()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } } SwiftReadFeature(final SwiftSession session, final SwiftRegionService regionService); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file); }
SwiftReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { status.setChecksum(Checksum.NONE); final Response response; if(status.isAppend()) { final HttpRange range = HttpRange.withStatus(status); if(-1 == range.getEnd()) { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart()); } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart(), range.getLength()); } } else { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file)); } return new HttpMethodReleaseInputStream(response.getResponse()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Download {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e, file); } } SwiftReadFeature(final SwiftSession session, final SwiftRegionService regionService); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file);  }