< prev index next >
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpResponse.java
Print this page
*** 342,369 ****
/**
* Returns a {@code BodyHandler<String>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <String>} obtained from
* {@link BodySubscriber#asString(Charset) BodySubscriber.asString(Charset)}.
! * If a charset is provided, the body is decoded using it. If charset is
! * {@code null} then the handler tries to determine the character set
! * from the {@code Content-encoding} header. If that charset is not
! * supported then {@link java.nio.charset.StandardCharsets#UTF_8 UTF_8}
! * is used.
*
* @param charset The name of the charset to interpret the body as. If
* {@code null} then the charset is determined from the
* <i>Content-encoding</i> header.
* @return a response body handler
*/
public static BodyHandler<String> asString(Charset charset) {
! return (status, headers) -> {
! if (charset != null) {
! return BodySubscriber.asString(charset);
! }
! return BodySubscriber.asString(charsetFrom(headers));
! };
}
/**
* Returns a {@code BodyHandler<Path>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <Path>} obtained from
--- 342,361 ----
/**
* Returns a {@code BodyHandler<String>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <String>} obtained from
* {@link BodySubscriber#asString(Charset) BodySubscriber.asString(Charset)}.
! * The body is decoded using the given character set.
*
* @param charset The name of the charset to interpret the body as. If
* {@code null} then the charset is determined from the
* <i>Content-encoding</i> header.
* @return a response body handler
*/
public static BodyHandler<String> asString(Charset charset) {
! Objects.requireNonNull(charset);
! return (status, headers) -> BodySubscriber.asString(charset);
}
/**
* Returns a {@code BodyHandler<Path>} that returns a
* {@link BodySubscriber BodySubscriber}{@code <Path>} obtained from
*** 384,398 ****
* invoked to check delete access if the file is opened with
* the {@code DELETE_ON_CLOSE} option.
*/
public static BodyHandler<Path> asFile(Path file, OpenOption... openOptions) {
Objects.requireNonNull(file);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
String fn = pathForSecurityCheck(file);
sm.checkWrite(fn);
- List<OpenOption> opts = Arrays.asList(openOptions);
if (opts.contains(StandardOpenOption.DELETE_ON_CLOSE))
sm.checkDelete(fn);
if (opts.contains(StandardOpenOption.READ))
sm.checkRead(fn);
}
--- 376,390 ----
* invoked to check delete access if the file is opened with
* the {@code DELETE_ON_CLOSE} option.
*/
public static BodyHandler<Path> asFile(Path file, OpenOption... openOptions) {
Objects.requireNonNull(file);
+ List<OpenOption> opts = List.of(openOptions);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
String fn = pathForSecurityCheck(file);
sm.checkWrite(fn);
if (opts.contains(StandardOpenOption.DELETE_ON_CLOSE))
sm.checkDelete(fn);
if (opts.contains(StandardOpenOption.READ))
sm.checkRead(fn);
}
*** 448,462 ****
*/
//####: check if the dir exists and is writable??
public static BodyHandler<Path> asFileDownload(Path directory,
OpenOption... openOptions) {
Objects.requireNonNull(directory);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
String fn = pathForSecurityCheck(directory);
sm.checkWrite(fn);
- List<OpenOption> opts = Arrays.asList(openOptions);
if (opts.contains(StandardOpenOption.DELETE_ON_CLOSE))
sm.checkDelete(fn);
if (opts.contains(StandardOpenOption.READ))
sm.checkRead(fn);
}
--- 440,454 ----
*/
//####: check if the dir exists and is writable??
public static BodyHandler<Path> asFileDownload(Path directory,
OpenOption... openOptions) {
Objects.requireNonNull(directory);
+ List<OpenOption> opts = List.of(openOptions);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
String fn = pathForSecurityCheck(directory);
sm.checkWrite(fn);
if (opts.contains(StandardOpenOption.DELETE_ON_CLOSE))
sm.checkDelete(fn);
if (opts.contains(StandardOpenOption.READ))
sm.checkRead(fn);
}
*** 492,501 ****
--- 484,494 ----
*
* @param consumer a Consumer to accept the response body
* @return a response body handler
*/
public static BodyHandler<Void> asByteArrayConsumer(Consumer<Optional<byte[]>> consumer) {
+ Objects.requireNonNull(consumer);
return (status, headers) -> BodySubscriber.asByteArrayConsumer(consumer);
}
/**
* Returns a {@code BodyHandler<byte[]>} that returns a
*** 545,554 ****
--- 538,548 ----
* @return a body handler
* @throws IllegalArgumentException if {@code bufferSize <= 0}
*/
public static <T> BodyHandler<T> buffering(BodyHandler<T> downstreamHandler,
int bufferSize) {
+ Objects.requireNonNull(downstreamHandler);
if (bufferSize <= 0)
throw new IllegalArgumentException("must be greater than 0");
return (status, headers) -> BodySubscriber
.buffering(downstreamHandler.apply(status, headers),
bufferSize);
*** 611,620 ****
--- 605,615 ----
*
* @param charset the character set to convert the String with
* @return a body subscriber
*/
public static BodySubscriber<String> asString(Charset charset) {
+ Objects.requireNonNull(charset);
return new ResponseSubscribers.ByteArraySubscriber<>(
bytes -> new String(bytes, charset)
);
}
*** 660,674 ****
* invoked to check delete access if the file is opened with the
* {@code DELETE_ON_CLOSE} option.
*/
public static BodySubscriber<Path> asFile(Path file, OpenOption... openOptions) {
Objects.requireNonNull(file);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
String fn = pathForSecurityCheck(file);
sm.checkWrite(fn);
- List<OpenOption> opts = Arrays.asList(openOptions);
if (opts.contains(StandardOpenOption.DELETE_ON_CLOSE))
sm.checkDelete(fn);
if (opts.contains(StandardOpenOption.READ))
sm.checkRead(fn);
}
--- 655,669 ----
* invoked to check delete access if the file is opened with the
* {@code DELETE_ON_CLOSE} option.
*/
public static BodySubscriber<Path> asFile(Path file, OpenOption... openOptions) {
Objects.requireNonNull(file);
+ List<OpenOption> opts = List.of(openOptions);
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
String fn = pathForSecurityCheck(file);
sm.checkWrite(fn);
if (opts.contains(StandardOpenOption.DELETE_ON_CLOSE))
sm.checkDelete(fn);
if (opts.contains(StandardOpenOption.READ))
sm.checkRead(fn);
}
< prev index next >