@Test public void testReadZeroLength() throws Exception { final Host host = new Host(new AzureProtocol(), "kahy9boj3eib.blob.core.windows.net", new Credentials( System.getProperties().getProperty("azure.account"), System.getProperties().getProperty("azure.key") )); final AzureSession session = new AzureSession(host); new LoginConnectionService(new DisabledLoginCallback(), new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener()).connect(session, PathCache.empty(), new DisabledCancelCallback()); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); new AzureTouchFeature(session, null).touch(test, new TransferStatus()); final InputStream in = new AzureReadFeature(session, null).read(test, new TransferStatus().length(0L), new DisabledConnectionCallback()); assertNotNull(in); in.close(); new AzureDeleteFeature(session, null).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 { try { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); if(0L == blob.getProperties().getLength()) { return new NullInputStream(0L); } final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1); final BlobInputStream in = blob.openInputStream(AccessCondition.generateEmptyCondition(), options, context); if(status.isAppend()) { try { return StreamCopier.skip(in, status.getOffset()); } catch(IndexOutOfBoundsException e) { throw new DefaultExceptionMappingService().map(e); } } return new ProxyInputStream(in) { @Override protected void handleIOException(final IOException e) throws IOException { if(StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) { log.warn(String.format("Ignore failure %s", e)); return; } final Throwable cause = ExceptionUtils.getRootCause(e); if(cause instanceof StorageException) { throw new IOException(e.getMessage(), new AzureExceptionMappingService().map((StorageException) cause)); } throw e; } }; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Download {0} failed", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } }
AzureReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); if(0L == blob.getProperties().getLength()) { return new NullInputStream(0L); } final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1); final BlobInputStream in = blob.openInputStream(AccessCondition.generateEmptyCondition(), options, context); if(status.isAppend()) { try { return StreamCopier.skip(in, status.getOffset()); } catch(IndexOutOfBoundsException e) { throw new DefaultExceptionMappingService().map(e); } } return new ProxyInputStream(in) { @Override protected void handleIOException(final IOException e) throws IOException { if(StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) { log.warn(String.format("Ignore failure %s", e)); return; } final Throwable cause = ExceptionUtils.getRootCause(e); if(cause instanceof StorageException) { throw new IOException(e.getMessage(), new AzureExceptionMappingService().map((StorageException) cause)); } throw e; } }; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Download {0} failed", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } }
AzureReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); if(0L == blob.getProperties().getLength()) { return new NullInputStream(0L); } final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1); final BlobInputStream in = blob.openInputStream(AccessCondition.generateEmptyCondition(), options, context); if(status.isAppend()) { try { return StreamCopier.skip(in, status.getOffset()); } catch(IndexOutOfBoundsException e) { throw new DefaultExceptionMappingService().map(e); } } return new ProxyInputStream(in) { @Override protected void handleIOException(final IOException e) throws IOException { if(StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) { log.warn(String.format("Ignore failure %s", e)); return; } final Throwable cause = ExceptionUtils.getRootCause(e); if(cause instanceof StorageException) { throw new IOException(e.getMessage(), new AzureExceptionMappingService().map((StorageException) cause)); } throw e; } }; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Download {0} failed", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureReadFeature(final AzureSession session, final OperationContext context); }
AzureReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); if(0L == blob.getProperties().getLength()) { return new NullInputStream(0L); } final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1); final BlobInputStream in = blob.openInputStream(AccessCondition.generateEmptyCondition(), options, context); if(status.isAppend()) { try { return StreamCopier.skip(in, status.getOffset()); } catch(IndexOutOfBoundsException e) { throw new DefaultExceptionMappingService().map(e); } } return new ProxyInputStream(in) { @Override protected void handleIOException(final IOException e) throws IOException { if(StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) { log.warn(String.format("Ignore failure %s", e)); return; } final Throwable cause = ExceptionUtils.getRootCause(e); if(cause instanceof StorageException) { throw new IOException(e.getMessage(), new AzureExceptionMappingService().map((StorageException) cause)); } throw e; } }; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Download {0} failed", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureReadFeature(final AzureSession session, final OperationContext context); @Override boolean offset(final Path file); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback); }
AzureReadFeature implements Read { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { final CloudBlob blob = session.getClient().getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); if(0L == blob.getProperties().getLength()) { return new NullInputStream(0L); } final BlobRequestOptions options = new BlobRequestOptions(); options.setConcurrentRequestCount(1); final BlobInputStream in = blob.openInputStream(AccessCondition.generateEmptyCondition(), options, context); if(status.isAppend()) { try { return StreamCopier.skip(in, status.getOffset()); } catch(IndexOutOfBoundsException e) { throw new DefaultExceptionMappingService().map(e); } } return new ProxyInputStream(in) { @Override protected void handleIOException(final IOException e) throws IOException { if(StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) { log.warn(String.format("Ignore failure %s", e)); return; } final Throwable cause = ExceptionUtils.getRootCause(e); if(cause instanceof StorageException) { throw new IOException(e.getMessage(), new AzureExceptionMappingService().map((StorageException) cause)); } throw e; } }; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Download {0} failed", e, file); } catch(URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } } AzureReadFeature(final AzureSession session, final OperationContext context); @Override boolean offset(final Path file); @Override InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback);  }