All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bt.protocol.Request Maven / Gradle / Ivy

There is a newer version: 1.10
Show newest version
package bt.protocol;

/**
 * @since 1.0
 */
public final class Request implements Message {

    private int pieceIndex;
    private int offset;
    private int length;

    /**
     * @since 1.0
     */
    public Request(int pieceIndex, int offset, int length) throws InvalidMessageException {

        if (pieceIndex < 0 || offset < 0 || length <= 0) {
            throw new InvalidMessageException("Illegal arguments: piece index (" +
                    pieceIndex + "), offset (" + offset + "), length (" + length + ")");
        }

        this.pieceIndex = pieceIndex;
        this.offset = offset;
        this.length = length;
    }

    /**
     * @since 1.0
     */
    public int getPieceIndex() {
        return pieceIndex;
    }

    /**
     * @since 1.0
     */
    public int getOffset() {
        return offset;
    }

    /**
     * @since 1.0
     */
    public int getLength() {
        return length;
    }

    @Override
    public String toString() {
        return "[" + this.getClass().getSimpleName() + "] piece index {" + pieceIndex + "}, offset {" + offset +
                "}, length {" + length + "}";
    }

    @Override
    public Integer getMessageId() {
        return StandardBittorrentProtocol.REQUEST_ID;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy