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

bt.data.range.BlockRange Maven / Gradle / Ivy

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

import bt.data.BlockSet;

/**
 * @since 1.3
 */
public class BlockRange> implements Range>, DelegatingRange {

    private final Range delegate;
    private final long offset;

    private final MutableBlockSet blockSet;

    /**
     * Create a block-structured data range.
     *
     * @since 1.2
     */
    BlockRange(Range delegate, long blockSize) {
        this(delegate, 0, new MutableBlockSet(delegate.length(), blockSize));
    }

    private BlockRange(Range delegate,
                       long offset,
                       MutableBlockSet blockSet) {
        this.delegate = delegate;
        this.offset = offset;
        this.blockSet = blockSet;
    }

    /**
     * @since 1.3
     */
    public BlockSet getBlockSet() {
        return blockSet;
    }

    @Override
    public long length() {
        return delegate.length();
    }

    @Override
    public BlockRange getSubrange(long offset, long length) {
        return new BlockRange<>(delegate.getSubrange(offset, length), offset, blockSet);
    }

    @Override
    public BlockRange getSubrange(long offset) {
        return new BlockRange<>(delegate.getSubrange(offset), offset, blockSet);
    }

    @Override
    public byte[] getBytes() {
        return delegate.getBytes();
    }

    @Override
    public void putBytes(byte[] block) {
        delegate.putBytes(block);
        blockSet.markAvailable(offset, block.length);
    }

    @SuppressWarnings("unchecked")
    @Override
    public T getDelegate() {
        return (T) delegate;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy