de.mklinger.qetcher.client.httpclient.BodyHandlers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qetcher-client-bundle Show documentation
Show all versions of qetcher-client-bundle Show documentation
Qetcher Java client, OSGi bundle, minimal dependencies
package de.mklinger.commons.httpclient;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import de.mklinger.commons.httpclient.HttpResponse.BodyHandler;
import de.mklinger.commons.httpclient.internal.ByteArrayCompleteListener;
import de.mklinger.commons.httpclient.internal.DiscardBodyCompleteListener;
import de.mklinger.commons.httpclient.internal.FileCompleteListener;
import de.mklinger.commons.httpclient.internal.StringBodyHandler;
/**
* @author Marc Klinger - mklinger[at]mklinger[dot]de
*/
public class BodyHandlers {
private BodyHandlers() {
}
public static BodyHandler asFile(final Path file, final OpenOption... openOptions) {
return (statusCode, responseHeaders) -> new FileCompleteListener(file, openOptions);
}
public static BodyHandler asFile(final Path file) {
return asFile(file, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
}
public static BodyHandler asByteArray() {
return (statusCode, responseHeaders) -> new ByteArrayCompleteListener();
}
public static BodyHandler asString() {
return new StringBodyHandler();
}
public static BodyHandler discard(final U value) {
return (statusCode, responseHeaders) -> new DiscardBodyCompleteListener<>(value);
}
public static BodyHandler discard() {
return discard(null);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy