@Override
    public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        if(file.isPlaceholder()) {
            final DescriptiveUrl link = new DriveUrlProvider().toUrl(file).find(DescriptiveUrl.Type.http);
            if(DescriptiveUrl.EMPTY.equals(link)) {
                log.warn(String.format("Missing web link for file %s", file));
                return new NullInputStream(file.attributes().getSize());
            }
            // Write web link file
            return IOUtils.toInputStream(UrlFileWriterFactory.get().write(link), Charset.defaultCharset());
        }
        else {
            final HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MEDIA_TYPE);
            if(status.isAppend()) {
                final HttpRange range = HttpRange.withStatus(status);
                final String header;
                if(TransferStatus.UNKNOWN_LENGTH == 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.setRange(header);
                // Disable compression
                headers.setAcceptEncoding("identity");
            }
            if(file.attributes().isDuplicate()) {
                // Read previous version
                try {
                    final Drive.Revisions.Get request = session.getClient().revisions().get(fileid.getFileId(file), file.attributes().getVersionId());
                    request.setRequestHeaders(headers);
                    return request.executeMediaAsInputStream();
                }
                catch(IOException e) {
                    throw new DriveExceptionMappingService(fileid).map("Download {0} failed", e, file);
                }
            }
            else {
                try {
                    try {
                        final Drive.Files.Get request = session.getClient().files().get(fileid.getFileId(file));
                        request.setRequestHeaders(headers);
                        request.setSupportsTeamDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable"));
                        return request.executeMediaAsInputStream();
                    }
                    catch(IOException e) {
                        throw new DriveExceptionMappingService(fileid).map("Download {0} failed", e, file);
                    }
                }
                catch(RetriableAccessDeniedException e) {
                    throw e;
                }
                catch(AccessDeniedException e) {
                    if(!PreferencesFactory.get().getBoolean(String.format("connection.unsecure.download.%s", session.getHost().getHostname()))) {
                        // Not previously dismissed
                        callback.warn(session.getHost(),
                                MessageFormat.format(LocaleFactory.localizedString("Download {0} failed", "Error"), file.getName()),
                                "Acknowledge the risk of downloading known malware or other abusive file.",
                                LocaleFactory.localizedString("Continue", "Credentials"), LocaleFactory.localizedString("Cancel", "Localizable"),
                                String.format("connection.unsecure.download.%s", session.getHost().getHostname()));
                    }
                    try {
                        final Drive.Files.Get request = session.getClient().files().get(fileid.getFileId(file));
                        request.setAcknowledgeAbuse(true);
                        request.setRequestHeaders(headers);
                        request.setSupportsTeamDrives(new HostPreferences(session.getHost()).getBoolean("googledrive.teamdrive.enable"));
                        return request.executeMediaAsInputStream();
                    }
                    catch(IOException f) {
                        throw new DriveExceptionMappingService(fileid).map("Download {0} failed", f, file);
                    }
                }
            }
        }
    }
@Test(expected = NotfoundException.class)
    public void testReadNotFound() throws Exception {
        final TransferStatus status = new TransferStatus();
        new DriveReadFeature(session, new DriveFileIdProvider(session)).read(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, "nosuchname", EnumSet.of(Path.Type.file)), status, new DisabledConnectionCallback());
    }