@Test public void testRead() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials( System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key") )); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final byte[] content = new RandomStringGenerator.Builder().build().generate(1000).getBytes(); final TransferStatus status = new TransferStatus().length(content.length); status.setChecksum(new CRC32ChecksumCompute().compute(new ByteArrayInputStream(content), status)); final OutputStream out = new S3WriteFeature(session).write(test, status, new DisabledConnectionCallback()); assertNotNull(out); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); out.close(); new SpectraBulkService(session).pre(Transfer.Type.download, Collections.singletonMap(new TransferItem(test), status), new DisabledConnectionCallback()); final InputStream in = new SpectraReadFeature(session).read(test, status, new DisabledConnectionCallback()); assertNotNull(in); final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length); new StreamCopier(status, status).transfer(in, buffer); assertArrayEquals(content, buffer.toByteArray()); in.close(); new SpectraDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
@Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<TransferStatus> chunks = bulk.query(Transfer.Type.download, file, status); chunks.sort(Comparator.comparingLong(TransferStatus::getOffset)); final List<LazyInputStream> streams = new ArrayList<>(); for(TransferStatus chunk : chunks) { final LazyInputStream in = new LazyInputStream(new LazyInputStream.OpenCallback() { @Override public InputStream open() throws IOException { try { return session.getClient().getObjectImpl( false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()) .getDataInputStream(); } catch(ServiceException e) { throw new IOException(e.getMessage(), e); } } }); streams.add(in); } return new SequenceInputStream(Collections.enumeration(streams)); }
SpectraReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<TransferStatus> chunks = bulk.query(Transfer.Type.download, file, status); chunks.sort(Comparator.comparingLong(TransferStatus::getOffset)); final List<LazyInputStream> streams = new ArrayList<>(); for(TransferStatus chunk : chunks) { final LazyInputStream in = new LazyInputStream(new LazyInputStream.OpenCallback() { @Override public InputStream open() throws IOException { try { return session.getClient().getObjectImpl( false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()) .getDataInputStream(); } catch(ServiceException e) { throw new IOException(e.getMessage(), e); } } }); streams.add(in); } return new SequenceInputStream(Collections.enumeration(streams)); } }
SpectraReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<TransferStatus> chunks = bulk.query(Transfer.Type.download, file, status); chunks.sort(Comparator.comparingLong(TransferStatus::getOffset)); final List<LazyInputStream> streams = new ArrayList<>(); for(TransferStatus chunk : chunks) { final LazyInputStream in = new LazyInputStream(new LazyInputStream.OpenCallback() { @Override public InputStream open() throws IOException { try { return session.getClient().getObjectImpl( false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()) .getDataInputStream(); } catch(ServiceException e) { throw new IOException(e.getMessage(), e); } } }); streams.add(in); } return new SequenceInputStream(Collections.enumeration(streams)); } SpectraReadFeature(final SpectraSession session);  SpectraReadFeature(final SpectraSession session, final SpectraBulkService bulk); }
SpectraReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<TransferStatus> chunks = bulk.query(Transfer.Type.download, file, status); chunks.sort(Comparator.comparingLong(TransferStatus::getOffset)); final List<LazyInputStream> streams = new ArrayList<>(); for(TransferStatus chunk : chunks) { final LazyInputStream in = new LazyInputStream(new LazyInputStream.OpenCallback() { @Override public InputStream open() throws IOException { try { return session.getClient().getObjectImpl( false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()) .getDataInputStream(); } catch(ServiceException e) { throw new IOException(e.getMessage(), e); } } }); streams.add(in); } return new SequenceInputStream(Collections.enumeration(streams)); } SpectraReadFeature(final SpectraSession session);  SpectraReadFeature(final SpectraSession session, final SpectraBulkService bulk); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file); }
SpectraReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { final List<TransferStatus> chunks = bulk.query(Transfer.Type.download, file, status); chunks.sort(Comparator.comparingLong(TransferStatus::getOffset)); final List<LazyInputStream> streams = new ArrayList<>(); for(TransferStatus chunk : chunks) { final LazyInputStream in = new LazyInputStream(new LazyInputStream.OpenCallback() { @Override public InputStream open() throws IOException { try { return session.getClient().getObjectImpl( false, containerService.getContainer(file).getName(), containerService.getKey(file), null, null, null, null, null, null, file.attributes().getVersionId(), new HashMap<String, Object>(), chunk.getParameters()) .getDataInputStream(); } catch(ServiceException e) { throw new IOException(e.getMessage(), e); } } }); streams.add(in); } return new SequenceInputStream(Collections.enumeration(streams)); } SpectraReadFeature(final SpectraSession session);  SpectraReadFeature(final SpectraSession session, final SpectraBulkService bulk); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); @Override boolean offset(final Path file);  }