本文整理汇总了Java中java.util.OptionalLong.getAsLong方法的典型用法代码示例。如果您正苦于以下问题:Java OptionalLong.getAsLong方法的具体用法?Java OptionalLong.getAsLong怎么用?Java OptionalLong.getAsLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.OptionalLong
的用法示例。
在下文中一共展示了OptionalLong.getAsLong方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import java.util.OptionalLong; //导入方法依赖的package包/类
public RawHttpResponse<CloseableHttpResponse> send(RawHttpRequest request) throws IOException {
RequestBuilder builder = RequestBuilder.create(request.getMethod());
builder.setUri(request.getUri());
builder.setVersion(toProtocolVersion(request.getStartLine().getHttpVersion()));
request.getHeaders().getHeaderNames().forEach((name) ->
request.getHeaders().get(name).forEach(value ->
builder.addHeader(new BasicHeader(name, value))));
request.getBody().ifPresent(b -> builder.setEntity(new InputStreamEntity(b.asStream())));
CloseableHttpResponse response = httpClient.execute(builder.build());
RawHttpHeaders headers = readHeaders(response);
@Nullable LazyBodyReader body;
if (response.getEntity() != null) {
OptionalLong headerLength = RawHttp.parseContentLength(headers);
@Nullable Long length = headerLength.isPresent() ? headerLength.getAsLong() : null;
BodyType bodyType = RawHttp.getBodyType(headers, length);
body = new LazyBodyReader(bodyType, response.getEntity().getContent(), length, false);
} else {
body = null;
}
return new RawHttpResponse<>(response, request, adaptStatus(response.getStatusLine()), headers, body);
}
示例2: createBodyReader
import java.util.OptionalLong; //导入方法依赖的package包/类
@Nullable
private BodyReader createBodyReader(InputStream inputStream, RawHttpHeaders headers, boolean hasBody) {
@Nullable BodyReader bodyReader;
if (hasBody) {
@Nullable Long bodyLength = null;
OptionalLong headerLength = parseContentLength(headers);
if (headerLength.isPresent()) {
bodyLength = headerLength.getAsLong();
}
BodyType bodyType = getBodyType(headers, bodyLength);
bodyReader = new LazyBodyReader(bodyType, inputStream, bodyLength, options.allowNewLineWithoutReturn());
} else {
bodyReader = null;
}
return bodyReader;
}
示例3: invokeAll
import java.util.OptionalLong; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "OptionalUsedAsFieldOrParameterType"})
private <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, OptionalLong timeoutNanos)
throws InterruptedException {
Objects.requireNonNull(tasks, "'tasks' should not be 'null'.");
CompletableFuture[] futures = new CompletableFuture[tasks.size()];
int index = 0;
for (Callable<T> task : tasks) {
futures[index++] = submit(task);
}
boolean completeWithTimeout = timeoutNanos.isPresent();
try {
if (completeWithTimeout) {
CompletableFuture.allOf(futures)
.get(timeoutNanos.getAsLong(), TimeUnit.NANOSECONDS);
completeWithTimeout = false;
} else {
CompletableFuture.allOf(futures)
.get();
}
} catch (ExecutionException | TimeoutException ignored) {
logger.error("Got exception while waiting for completion of '{}' tasks.", tasks.size(), ignored);
}
if (completeWithTimeout) {
TimeoutException timeoutException = new TimeoutException(
"Got timeout after '" + timeoutNanos.getAsLong() + "' nanos."
);
for (CompletableFuture future : futures) {
future.completeExceptionally(timeoutException);
}
}
return Arrays.stream(futures)
.map(future -> (Future<T>) future)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
示例4: toJdbc
import java.util.OptionalLong; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @see jp.co.future.uroborosql.parameter.mapper.BindParameterMapper#toJdbc(java.lang.Object, java.sql.Connection, jp.co.future.uroborosql.parameter.mapper.BindParameterMapperManager)
*/
@Override
public Object toJdbc(final OptionalLong original, final Connection connection,
final BindParameterMapperManager parameterMapperManager) {
return original.isPresent() ? original.getAsLong() : null;
}
示例5: testEmptyGet
import java.util.OptionalLong; //导入方法依赖的package包/类
@Test(expectedExceptions=NoSuchElementException.class)
public void testEmptyGet() {
OptionalLong empty = OptionalLong.empty();
long got = empty.getAsLong();
}