@@ -0,0 +1,2742 @@
+package com.novoda.downloadmanager;%0A%0Aimport android.database.Cursor;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aclass PartialDownloadMigrationExtractor %7B%0A%0A    private static final String BATCHES_QUERY = %22SELECT batches._id, batches.batch_title FROM batches INNER JOIN DownloadsByBatch ON %22 +%0A            %22DownloadsByBatch.batch_id = batches._id WHERE DownloadsByBatch.batch_total_bytes != DownloadsByBatch.batch_current_bytes %22 +%0A            %22GROUP BY batches._id%22;%0A    private static final String URIS_QUERY = %22SELECT uri, _data, current_bytes, total_bytes FROM Downloads WHERE batch_id = ?%22;%0A    private static final int BATCH_ID_COLUMN = 0;%0A    private static final int URI_COLUMN = 0;%0A    private static final int TITLE_COLUMN = 1;%0A    private static final int FILE_NAME_COLUMN = 1;%0A    private static final int CURRENT_FILE_SIZE_COLUMN = 2;%0A    private static final int TOTAL_FILE_SIZE_COLUMN = 3;%0A%0A    private final SqlDatabaseWrapper database;%0A%0A    PartialDownloadMigrationExtractor(SqlDatabaseWrapper database) %7B%0A        this.database = database;%0A    %7D%0A%0A    List%3CMigration%3E extractMigrations() %7B%0A        Cursor batchesCursor = database.rawQuery(BATCHES_QUERY);%0A%0A        List%3CMigration%3E migrations = new ArrayList%3C%3E();%0A        while (batchesCursor.moveToNext()) %7B%0A%0A            String batchId = batchesCursor.getString(BATCH_ID_COLUMN);%0A            String batchTitle = batchesCursor.getString(TITLE_COLUMN);%0A%0A            Cursor uriCursor = database.rawQuery(URIS_QUERY, batchId);%0A            Batch.Builder newBatchBuilder = new Batch.Builder(DownloadBatchIdCreator.createFrom(batchId), batchTitle);%0A            List%3CMigration.FileMetadata%3E fileMetadataList = new ArrayList%3C%3E();%0A%0A            while (uriCursor.moveToNext()) %7B%0A                String uri = uriCursor.getString(URI_COLUMN);%0A                String originalFileName = uriCursor.getString(FILE_NAME_COLUMN);%0A%0A                long currentRawFileSize = uriCursor.getLong(CURRENT_FILE_SIZE_COLUMN);%0A                if (originalFileName == null %7C%7C originalFileName.isEmpty()) %7B%0A                    currentRawFileSize = 0;%0A                %7D%0A%0A                newBatchBuilder.addFile(uri);%0A%0A                long totalRawFileSize = uriCursor.getLong(TOTAL_FILE_SIZE_COLUMN);%0A                FileSize fileSize = new LiteFileSize(currentRawFileSize, totalRawFileSize);%0A                Migration.FileMetadata fileMetadata = new Migration.FileMetadata(originalFileName, fileSize, uri);%0A                fileMetadataList.add(fileMetadata);%0A            %7D%0A            uriCursor.close();%0A%0A            Batch batch = newBatchBuilder.build();%0A            migrations.add(new Migration(batch, fileMetadataList));%0A        %7D%0A        batchesCursor.close();%0A        return migrations;%0A    %7D%0A%7D%0A

Create a PartialDownloadMigrationExtractor.