DownloadInfo implements Parcelable, Comparable<DownloadInfo> { public List<DownloadPiece> makePieces() { List<DownloadPiece> pieces = new ArrayList<>(); long piecesSize = -1; long lastPieceSize = -1; if (totalBytes != -1) { piecesSize = totalBytes / numPieces; lastPieceSize = piecesSize + totalBytes % numPieces; } long curBytes = 0; for (int i = 0; i < numPieces; i++) { long pieceSize = (i == numPieces - 1 ? lastPieceSize : piecesSize); pieces.add(new DownloadPiece(id, i, pieceSize, curBytes)); curBytes += pieceSize; } return pieces; } DownloadInfo(@NonNull Uri dirPath,
                        @NonNull String url,
                        @NonNull String fileName); @Ignore  DownloadInfo(@NonNull Parcel source); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); void setNumPieces(int numPieces); int getNumPieces(); List<DownloadPiece> makePieces(); long pieceStartPos(@NonNull DownloadPiece piece); long pieceEndPos(@NonNull DownloadPiece piece); long getDownloadedBytes(@NonNull DownloadPiece piece); @Override int compareTo(@NonNull DownloadInfo another); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static final int MIN_PIECES; static final int MAX_PIECES; static final int VISIBILITY_VISIBLE; static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED; static final int VISIBILITY_HIDDEN; static final int VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION; static final int MIN_RETRY_AFTER; static final int MAX_RETRY_AFTER; @PrimaryKey
    @NonNull
    public UUID id; @TypeConverters({UriConverter.class})
    @NonNull
    public Uri dirPath; @NonNull
    public String url; @NonNull
    public String fileName; public String description; public String mimeType; public long totalBytes; public int statusCode; public boolean unmeteredConnectionsOnly; public boolean retry; public boolean partialSupport; public String statusMsg; public long dateAdded; public int visibility; public boolean hasMetadata; public String userAgent; public int numFailed; public int retryAfter; public long lastModify; public String checksum; static final Parcelable.Creator<DownloadInfo> CREATOR; }
@Test public void makePiecesTest() { info.totalBytes = 3; info.setNumPieces(3); checkPiecesAlignment(info, new long[][] { {0, 0}, {1, 1}, {2, 2} }); info.totalBytes = 1024; info.setNumPieces(15); checkPiecesAlignment(info, new long[][] { {0, 67}, {68, 135}, {136, 203}, {204, 271}, {272, 339}, {340, 407}, {408, 475}, {476, 543}, {544, 611}, {612, 679}, {680, 747}, {748, 815}, {816, 883}, {884, 951}, {952, 1023}, }); }