class B2ReadFeature implements Read {

    @Override
    public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        try {
            if(file.getType().contains(Path.Type.upload)) {
                return new NullInputStream(0L);
            }
            if(status.isAppend()) {
                final HttpRange range = HttpRange.withStatus(status);
                return session.getClient().downloadFileRangeByIdToStream(
                    fileid.getFileid(file, new DisabledListProgressListener()),
                        range.getStart(), range.getEnd()
                );
            }
            final B2DownloadFileResponse response = session.getClient().downloadFileById(fileid.getFileid(file, new DisabledListProgressListener()));
            return new HttpMethodReleaseInputStream(response.getResponse());
        }
        catch(B2ApiException e) {
            if(StringUtils.equals("file_state_none", e.getMessage())) {
                // Pending large file upload
                return new NullInputStream(0L);
            }
            throw new B2ExceptionMappingService().map("Download {0} failed", e, file);
        }
        catch(IOException e) {
            throw new DefaultIOExceptionMappingService().map("Download {0} failed", e, file);
        }
    }

    public  B2ReadFeature(final B2Session session, final B2FileidProvider fileid);

}