net.lenni0451.commons.httpclient.content.impl.ByteArrayContent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of httpclient Show documentation
Show all versions of httpclient Show documentation
A java library with many useful functions and classes
The newest version!
package net.lenni0451.commons.httpclient.content.impl;
import net.lenni0451.commons.httpclient.constants.ContentTypes;
import net.lenni0451.commons.httpclient.content.HttpContent;
import net.lenni0451.commons.httpclient.model.ContentType;
import javax.annotation.Nonnull;
import java.util.Arrays;
public class ByteArrayContent extends HttpContent {
private final byte[] content;
private final int start;
private final int length;
public ByteArrayContent(final byte[] content) {
this(content, 0, content.length);
}
public ByteArrayContent(final byte[] content, final int start, final int length) {
super(ContentTypes.APPLICATION_OCTET_STREAM);
this.content = content;
this.start = start;
this.length = length;
}
public ByteArrayContent(final ContentType contentType, final byte[] content) {
this(contentType, content, 0, content.length);
}
public ByteArrayContent(final ContentType contentType, final byte[] content, final int start, final int length) {
super(contentType);
this.content = content;
this.start = start;
this.length = length;
}
@Override
public int getContentLength() {
return this.content.length;
}
@Nonnull
@Override
protected byte[] compute() {
return Arrays.copyOfRange(this.content, this.start, this.start + this.length);
}
}