blob: 884399f25d950fd07b22d45fda1d14f87b27c3db (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.restapi.controller;
import com.yahoo.io.IOUtils;
import com.yahoo.slime.Inspector;
import com.yahoo.slime.SlimeUtils;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.function.Function;
class RequestUtils {
static <T> T requireField(Inspector inspector, String field, Function<String, T> mapper) {
return SlimeUtils.optionalString(inspector.field(field))
.map(mapper::apply)
.orElseThrow(() -> new IllegalArgumentException("Expected field \"" + field + "\" in request"));
}
static byte[] toJsonBytes(InputStream jsonStream) {
try {
return IOUtils.readBytes(jsonStream, 1000 * 1000);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
|