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

org.zodiac.netty.http.headers.BoundedRangeNetty Maven / Gradle / Ivy

package org.zodiac.netty.http.headers;

import io.netty.channel.DefaultFileRegion;
import io.netty.channel.FileRegion;
import io.netty.util.AsciiString;
import java.io.File;
import java.nio.file.Path;

public final class BoundedRangeNetty extends BoundedRange {

    public BoundedRangeNetty(long start, long end) {
        super(start, end);
    }

    public BoundedRangeNetty(long start, long end, long of) {
        super(start, end, of);
    }

    public BoundedRangeNetty(CharSequence value) {
        super(value);
    }

    public FileRegion toRegion(File f) {
        long st = start();
        return new DefaultFileRegion(f, st, (end() + 1) - st);
    }

    public FileRegion toRegion(Path f) {
        long st = start();
        return new DefaultFileRegion(f.toFile(), st, (end() + 1) - st);
    }

    public CharSequence toCharSequence() {
        long start = start();
        long end = end();
        long of = of();
        if (start == -1L && end == -1L) {
            AsciiString.of("bytes */" + of);
        }
        return AsciiString.of("bytes " + start + "-" + end + "/" + (of == -1L ? "*" : of));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy