use of java.util.function.BiConsumer in project spring-cloud-gcp by spring-cloud.
the class MappingSpannerWriteConverter method attemptSetIterableValue.
private boolean attemptSetIterableValue(Iterable value, ValueBinder<WriteBuilder> valueBinder, SpannerPersistentProperty spannerPersistentProperty) {
Class innerType = ConversionUtils.boxIfNeeded(spannerPersistentProperty.getColumnInnerType());
if (innerType == null || !iterablePropertyType2ToMethodMap.containsKey(innerType)) {
return false;
}
BiConsumer toMethod = iterablePropertyType2ToMethodMap.get(innerType);
toMethod.accept(valueBinder, value);
return true;
}
use of java.util.function.BiConsumer in project reactor-core by reactor.
the class MonoStreamCollectorTest method scanStreamCollectorSubscriber.
@Test
public void scanStreamCollectorSubscriber() {
CoreSubscriber<List<String>> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
Collector<String, ?, List<String>> collector = Collectors.toList();
@SuppressWarnings("unchecked") BiConsumer<Integer, String> accumulator = (BiConsumer<Integer, String>) collector.accumulator();
@SuppressWarnings("unchecked") Function<Integer, List<String>> finisher = (Function<Integer, List<String>>) collector.finisher();
MonoStreamCollector.StreamCollectorSubscriber<String, Integer, List<String>> test = new MonoStreamCollector.StreamCollectorSubscriber<>(actual, 1, accumulator, finisher);
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onError(new IllegalStateException("boom"));
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
use of java.util.function.BiConsumer in project keycloak by keycloak.
the class DefaultTokenManager method decodeClientJWT.
@Override
public <T> T decodeClientJWT(String jwt, ClientModel client, BiConsumer<JOSE, ClientModel> jwtValidator, Class<T> clazz) {
if (jwt == null) {
return null;
}
JOSE joseToken = JOSEParser.parse(jwt);
jwtValidator.accept(joseToken, client);
if (joseToken instanceof JWE) {
try {
Optional<KeyWrapper> activeKey;
String kid = joseToken.getHeader().getKeyId();
Stream<KeyWrapper> keys = session.keys().getKeysStream(session.getContext().getRealm());
if (kid == null) {
activeKey = keys.filter(k -> KeyUse.ENC.equals(k.getUse()) && k.getPublicKey() != null).sorted(Comparator.comparingLong(KeyWrapper::getProviderPriority).reversed()).findFirst();
} else {
activeKey = keys.filter(k -> KeyUse.ENC.equals(k.getUse()) && k.getKid().equals(kid)).findAny();
}
JWE jwe = JWE.class.cast(joseToken);
Key privateKey = activeKey.map(KeyWrapper::getPrivateKey).orElseThrow(() -> new RuntimeException("Could not find private key for decrypting token"));
jwe.getKeyStorage().setDecryptionKey(privateKey);
byte[] content = jwe.verifyAndDecodeJwe().getContent();
try {
JOSE jws = JOSEParser.parse(new String(content));
if (jws instanceof JWSInput) {
jwtValidator.accept(jws, client);
return verifyJWS(client, clazz, (JWSInput) jws);
}
} catch (Exception ignore) {
// try to decrypt content as is
}
return JsonSerialization.readValue(content, clazz);
} catch (IOException cause) {
throw new RuntimeException("Failed to deserialize JWT", cause);
} catch (JWEException cause) {
throw new RuntimeException("Failed to decrypt JWT", cause);
}
}
return verifyJWS(client, clazz, (JWSInput) joseToken);
}
use of java.util.function.BiConsumer in project graal by oracle.
the class MemoryFileSystem method newByteChannel.
@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
if (options.contains(StandardOpenOption.APPEND) && options.contains(StandardOpenOption.READ)) {
throw new IllegalArgumentException("READ + APPEND not allowed.");
}
if (options.contains(StandardOpenOption.SYNC) || options.contains(StandardOpenOption.DSYNC)) {
throw new IllegalArgumentException("Not supported yet.");
}
final Path absolutePath = toAbsolutePath(path);
final Path parentPath = absolutePath.getParent();
if (parentPath == null) {
throw new IOException(path.toString() + " is a directory.");
}
boolean read = options.contains(StandardOpenOption.READ);
boolean write = options.contains(StandardOpenOption.WRITE);
boolean append = options.contains(StandardOpenOption.APPEND);
if (!read && !write) {
if (append) {
write = true;
} else {
read = true;
}
}
final Map.Entry<Long, Map<String, Long>> e = readDir(parentPath);
final long parentInode = e.getKey();
final Map<String, Long> parentDirents = e.getValue();
final String fileName = absolutePath.getFileName().toString();
Long inode = parentDirents.get(fileName);
if (inode == null) {
if (!options.contains(StandardOpenOption.WRITE) || !(options.contains(StandardOpenOption.CREATE) || options.contains(StandardOpenOption.CREATE_NEW))) {
throw new NoSuchFileException(path.toString());
}
if (!inodes.get(parentInode).permissions.contains(AccessMode.WRITE)) {
throw new IOException("Read only dir: " + path);
}
inode = nextInode++;
inodes.put(inode, FileInfo.newBuilder(FileType.FILE).permissions(attrs).build());
blocks.put(inode, EMPTY);
parentDirents.put(fileName, inode);
writeDir(parentInode, parentDirents);
} else {
if (options.contains(StandardOpenOption.CREATE_NEW)) {
throw new FileAlreadyExistsException(path.toString());
}
final FileInfo fileInfo = inodes.get(inode);
if (!fileInfo.isFile()) {
throw new IOException(path.toString() + " is a directory.");
}
if (read && !fileInfo.permissions.contains(AccessMode.READ)) {
throw new IOException("Cannot read: " + path);
}
if (write && !fileInfo.permissions.contains(AccessMode.WRITE)) {
throw new IOException("Read only: " + path);
}
}
final boolean deleteOnClose = options.contains(StandardOpenOption.DELETE_ON_CLOSE);
final byte[] origData = blocks.get(inode);
final byte[] data = write && options.contains(StandardOpenOption.TRUNCATE_EXISTING) ? EMPTY : Arrays.copyOf(origData, origData.length);
final long inodeFin = inode;
final BiConsumer<byte[], Long> syncAction = new BiConsumer<byte[], Long>() {
@Override
public void accept(byte[] t, Long u) {
blocks.put(inodeFin, Arrays.copyOf(t, (int) u.longValue()));
}
};
final boolean readFin = read;
final boolean writeFin = write;
final BiConsumer<byte[], Long> metaSyncAction = new BiConsumer<byte[], Long>() {
@Override
public void accept(byte[] t, Long u) {
final long time = System.currentTimeMillis();
final FileInfo fileInfo = inodes.get(inodeFin);
if (readFin) {
fileInfo.atime = time;
}
if (writeFin) {
fileInfo.mtime = time;
}
}
};
final BiConsumer<byte[], Long> closeAction = new BiConsumer<byte[], Long>() {
@Override
public void accept(byte[] t, Long u) {
if (deleteOnClose) {
try {
delete(absolutePath);
} catch (IOException ioe) {
sthrow(ioe);
}
} else {
syncAction.accept(t, u);
metaSyncAction.accept(t, u);
}
}
@SuppressWarnings("unchecked")
private <E extends Throwable> void sthrow(Throwable t) throws E {
throw (E) t;
}
};
return new ChannelImpl(data, closeAction, read, write, append);
}
use of java.util.function.BiConsumer in project sonar-java by SonarSource.
the class ProgramState method cleanupConstraints.
public ProgramState cleanupConstraints(Collection<SymbolicValue> protectedSymbolicValues) {
class CleanAction implements BiConsumer<SymbolicValue, ConstraintsByDomain> {
boolean newProgramState = false;
PMap<SymbolicValue, ConstraintsByDomain> newConstraints = constraints;
PMap<SymbolicValue, Integer> newReferences = references;
@Override
public void accept(SymbolicValue symbolicValue, ConstraintsByDomain constraintPMap) {
constraintPMap.forEach((domain, constraint) -> {
if (!protectedSymbolicValues.contains(symbolicValue) && !isReachable(symbolicValue, newReferences) && isDisposable(symbolicValue, constraint) && !inStack(stack, symbolicValue)) {
newProgramState = true;
ConstraintsByDomain removed = newConstraints.get(symbolicValue).remove(domain);
if (removed.isEmpty()) {
newConstraints = newConstraints.remove(symbolicValue);
} else {
newConstraints = newConstraints.put(symbolicValue, removed);
}
newReferences = newReferences.remove(symbolicValue);
}
});
}
}
CleanAction cleanAction = new CleanAction();
constraints.forEach(cleanAction);
return cleanAction.newProgramState ? new ProgramState(values, cleanAction.newReferences, cleanAction.newConstraints, visitedPoints, stack, exitSymbolicValue) : this;
}
Aggregations