List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:com.github.horrorho.inflatabledonkey.util.ProcessManager.java
Optional<byte[]> pipe(Process process, InputStream in) throws IOException, InterruptedException { try (InputStream decoderIn = process.getInputStream(); OutputStream decoderOut = process.getOutputStream()) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Thread write = new Thread(() -> copy(in, decoderOut)); Thread read = new Thread(() -> copy(decoderIn, out)); write.start();/*from www . j a va2 s .com*/ read.start(); if (!process.waitFor(timeoutMS, TimeUnit.MILLISECONDS)) { logger.warn("-- pipe() - timed out"); // copy threads will shortly exit on exceptions as their streams are closed. return Optional.empty(); } read.join(timeoutMS); return Optional.of(out.toByteArray()); } finally { if (logger.isWarnEnabled()) { error(process); } } }
From source file:io.github.lxgaming.teleportbow.commands.AbstractCommand.java
public final Optional<String> getPrimaryAlias() { for (String alias : getAliases()) { if (StringUtils.isNotBlank(alias)) { return Optional.of(alias); }//from w w w . java 2s . c om } return Optional.empty(); }
From source file:com.netflix.genie.core.services.impl.LocalJobKillServiceImplUnitTests.java
/** * Make sure we don't execute any functionality if the job is already not running. * * @throws GenieException on any error//from w ww . j a va 2 s . com */ @Test public void wontKillJobIfAlreadyNotRunning() throws GenieException { final JobExecution jobExecution = Mockito.mock(JobExecution.class); Mockito.when(this.jobSearchService.getJobStatus(ID)).thenReturn(JobStatus.RUNNING); Mockito.when(jobExecution.getExitCode()).thenReturn(Optional.of(1)); Mockito.when(this.jobSearchService.getJobExecution(ID)).thenReturn(jobExecution); this.service.killJob(ID); }
From source file:com.opopov.cloud.image.service.ImageStitchingServiceImpl.java
private Optional<BufferedImage> decompressImage(ResponseEntity<byte[]> resp) { if (resp.getStatusCode() != HttpStatus.OK) { return Optional.empty(); }/*w w w .ja v a 2 s .co m*/ byte[] compressedBytes = resp.getBody(); try { BufferedImage image = ImageIO.read(new ByteArrayInputStream(compressedBytes)); return Optional.of(image); } catch (IOException e) { return Optional.empty(); } }
From source file:io.knotx.mocks.adapter.MockActionAdapterHandler.java
private Pair<Optional<String>, JsonObject> toTransitionPair(Map.Entry<String, Object> entry) { return Pair.of(Optional.of(entry.getKey()), ((JsonObject) entry.getValue()).getJsonObject("response")); }
From source file:com.ejisto.util.collector.FieldNode.java
public Optional<FieldNode> findClosestParent(MockedField mockedField) { final Optional<FieldNode> parent = children.stream().filter(c -> c.isParentOf(mockedField)) .map(c -> c.findClosestParent(mockedField)).filter(Optional::isPresent).map(Optional::get) .findAny();//from w ww . j ava 2s. co m if (parent.isPresent()) { return parent; } return Optional.of(this); }
From source file:com.amazonaws.service.apigateway.importer.impl.sdk.ApiGatewaySdkApiImporter.java
protected Optional<Resource> getRootResource(RestApi api) { for (Resource r : buildResourceList(api)) { if ("/".equals(r.getPath())) { return Optional.of(r); }//from w w w .java2 s. c o m } return Optional.empty(); }
From source file:org.graylog2.indexer.cluster.jest.JestUtils.java
private static List<JsonObject> extractRootCauses(JsonObject jsonObject) { return Optional.of(jsonObject).map(json -> asJsonObject(json.get("error"))) .map(error -> asJsonArray(error.get("root_cause"))).map(Iterable::spliterator) .map(x -> StreamSupport.stream(x, false)).orElse(Stream.empty()).map(GsonUtils::asJsonObject) .collect(Collectors.toList()); }
From source file:net.hamnaberg.json.Property.java
public static Property template(String name) { return value(name, Optional.of(capitalize(name)), Value.NONE); }
From source file:com.helion3.prism.api.parameters.ParameterTime.java
@Override public Optional<Pair<String, String>> processDefault(QuerySession session, Query query) { String since = Prism.getConfig().getNode("defaults", "since").getString(); try {// w w w . jav a2s . co m Date date = DateUtil.parseTimeStringToDate(since, false); query.addCondition(FieldCondition.of(DataQueries.Created, MatchRule.GREATER_THAN_EQUAL, date)); return Optional.of(Pair.of("since", since)); } catch (Exception e) { e.printStackTrace(); } return Optional.empty(); }