Uses of Interface
java.util.function.Consumer
Package
Description
Provides a simple high-level Http server API, which can be used to build
embedded HTTP servers.
Provides classes that are fundamental to the design of the Java
programming language.
Provides classfile parsing, generation, and transformation library.
Provides interfaces describing classfile attributes for the
java.lang.classfile
PREVIEW library.Provides specific components, transformations, and tools built on top of the
java.lang.classfile
PREVIEW library.Provides low-level access to memory and functions outside the Java runtime.
HTTP Client and WebSocket APIs
Defines channels, which represent connections to entities that are capable of
performing I/O operations, such as files and sockets; defines selectors, for
multiplexed, non-blocking I/O operations.
Contains the collections framework, some internationalization support classes,
a service loader, properties, random number generation, string parsing
and scanning classes, base64 encoding and decoding, a bit array, and
several miscellaneous utility classes.
Utility classes commonly useful in concurrent programming.
Functional interfaces provide target types for lambda expressions
and method references.
Classes to support functional-style operations on streams of elements, such
as map-reduce transformations on collections.
This package contains classes for consuming Flight Recorder data.
Provides interfaces for creating tools, such as a Read-Eval-Print Loop (REPL),
which interactively evaluate "snippets" of Java programming language code.
Provides implementation support for building JShell execution engines.
This package contains classes to control and monitor Flight Recorder over Java Management Extensions (JMX).
-
Uses of Consumer in com.sun.net.httpserver
Modifier and TypeMethodDescriptionstatic Filter
Filter.afterHandler
(String description, Consumer<HttpExchange> operation) Returns a post-processingFilter
with the given description and operation.static Filter
Filter.beforeHandler
(String description, Consumer<HttpExchange> operation) Returns a pre-processingFilter
with the given description and operation. -
Uses of Consumer in java.lang
Modifier and TypeMethodDescriptiondefault void
Performs the given action for each element of theIterable
until all elements have been processed or the action throws an exception.void
StackWalker.forEach
(Consumer<? super StackWalker.StackFrame> action) Performs the given action on each element ofStackFrame
stream of the current thread, traversing from the top frame of the stack, which is the method calling thisforEach
method. -
Uses of Consumer in java.lang.classfilePREVIEW
Modifier and TypeInterfaceDescriptioninterface
Preview.A builder for classfiles.interface
ClassFileBuilderPREVIEW<E extends ClassFileElementPREVIEW,
B extends ClassFileBuilderPREVIEW<E, B>> Preview.A builder for a classfile or portion of a classfile.interface
Preview.A builder for code attributes (method bodies).static interface
Preview.A builder for blocks of code.interface
Preview.A builder for fields.interface
Preview.A builder for methods.Modifier and TypeMethodDescriptiondefault CodeBuilderPREVIEW
CodeBuilder.block
(Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> handler) Add a lexical block to the method being built.byte[]
ClassFile.build
(ClassEntryPREVIEW thisClassEntry, ConstantPoolBuilderPREVIEW constantPool, Consumer<? super ClassBuilderPREVIEW> handler) Build a classfile into a byte array using the provided constant pool builder.default byte[]
ClassFile.build
(ClassDesc thisClass, Consumer<? super ClassBuilderPREVIEW> handler) Build a classfile into a byte array.default byte[]
ClassFile.buildModule
(ModuleAttributePREVIEW moduleAttribute, Consumer<? super ClassBuilderPREVIEW> handler) Build a module descriptor into a byte array.default void
ClassFile.buildModuleTo
(Path path, ModuleAttributePREVIEW moduleAttribute, Consumer<? super ClassBuilderPREVIEW> handler) Build a module descriptor into a file.default void
ClassFile.buildTo
(Path path, ClassEntryPREVIEW thisClassEntry, ConstantPoolBuilderPREVIEW constantPool, Consumer<? super ClassBuilderPREVIEW> handler) Build a classfile into a file using the provided constant pool builder.default void
Build a classfile into a file.CodeBuilder.CatchBuilder.catching
(ClassDesc exceptionType, Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> catchHandler) Adds a catch block that catches an exception of the given type.void
CodeBuilder.CatchBuilder.catchingAll
(Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> catchAllHandler) Adds a "catch" block that catches all exceptions.CodeBuilder.CatchBuilder.catchingMulti
(List<ClassDesc> exceptionTypes, Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> catchHandler) Adds a catch block that catches exceptions of the given types.static ClassTransformPREVIEW
ClassTransform.endHandler
(Consumer<ClassBuilderPREVIEW> finisher) Create a class transform that passes each element through to the builder, and calls the specified function when transformation is complete.static CodeTransformPREVIEW
CodeTransform.endHandler
(Consumer<CodeBuilderPREVIEW> finisher) Create a code transform that passes each element through to the builder, and calls the specified function when transformation is complete.static FieldTransformPREVIEW
FieldTransform.endHandler
(Consumer<FieldBuilderPREVIEW> finisher) Create a field transform that passes each element through to the builder, and calls the specified function when transformation is complete.static MethodTransformPREVIEW
MethodTransform.endHandler
(Consumer<MethodBuilderPREVIEW> finisher) Create a method transform that passes each element through to the builder, and calls the specified function when transformation is complete.void
Invoke the provided handler with each element contained in this compound elementdefault CodeBuilderPREVIEW
Add an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.default CodeBuilderPREVIEW
CodeBuilder.ifThen
(Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> thenHandler) Add an "if-then" block that is conditional on the boolean value on top of the operand stack.default CodeBuilderPREVIEW
CodeBuilder.ifThenElse
(OpcodePREVIEW opcode, Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> thenHandler, Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> elseHandler) Add an "if-then-else" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.default CodeBuilderPREVIEW
CodeBuilder.ifThenElse
(Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> thenHandler, Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> elseHandler) Add an "if-then-else" block that is conditional on the boolean value on top of the operand stack.default CodeBuilderPREVIEW
CodeBuilder.transforming
(CodeTransformPREVIEW transform, Consumer<CodeBuilderPREVIEW> handler) Apply a transform to the code built by a handler, directing results to this builder.default CodeBuilderPREVIEW
CodeBuilder.trying
(Consumer<CodeBuilder.BlockCodeBuilderPREVIEW> tryHandler, Consumer<CodeBuilder.CatchBuilderPREVIEW> catchesHandler) Adds a "try-catch" block comprising one try block and zero or more catch blocks.MethodBuilder.withCode
(Consumer<? super CodeBuilderPREVIEW> code) Build the method body for this method.ClassBuilder.withField
(Utf8EntryPREVIEW name, Utf8EntryPREVIEW descriptor, Consumer<? super FieldBuilderPREVIEW> handler) Adds a field.default ClassBuilderPREVIEW
ClassBuilder.withField
(String name, ClassDesc descriptor, Consumer<? super FieldBuilderPREVIEW> handler) Adds a field.ClassBuilder.withMethod
(Utf8EntryPREVIEW name, Utf8EntryPREVIEW descriptor, int methodFlags, Consumer<? super MethodBuilderPREVIEW> handler) Adds a method.default ClassBuilderPREVIEW
ClassBuilder.withMethod
(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super MethodBuilderPREVIEW> handler) Adds a method.default ClassBuilderPREVIEW
ClassBuilder.withMethodBody
(Utf8EntryPREVIEW name, Utf8EntryPREVIEW descriptor, int methodFlags, Consumer<? super CodeBuilderPREVIEW> handler) Adds a method, with only aCode
attribute.default ClassBuilderPREVIEW
ClassBuilder.withMethodBody
(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super CodeBuilderPREVIEW> handler) Adds a method, with only aCodeAttribute
PREVIEW. -
Uses of Consumer in java.lang.classfile.attributePREVIEW
Modifier and TypeMethodDescriptionstatic ModuleAttributePREVIEW
ModuleAttribute.of
(ModuleEntryPREVIEW moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilderPREVIEW> attrHandler) Returns aModule
attribute.static ModuleAttributePREVIEW
ModuleAttribute.of
(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilderPREVIEW> attrHandler) Returns aModule
attribute. -
Uses of Consumer in java.lang.classfile.componentsPREVIEW
Modifier and TypeMethodDescriptiondefault void
Prints the node and its sub-tree into JSON format.static void
ClassPrinter.toJson
(CompoundElementPREVIEW<?> model, ClassPrinter.VerbosityPREVIEW verbosity, Consumer<String> out) Prints provided model as structured text in JSON format.default void
Prints the node and its sub-tree into XML format.static void
ClassPrinter.toXml
(CompoundElementPREVIEW<?> model, ClassPrinter.VerbosityPREVIEW verbosity, Consumer<String> out) Prints provided model as structured text in XML format.default void
Prints the node and its sub-tree into YAML format.static void
ClassPrinter.toYaml
(CompoundElementPREVIEW<?> model, ClassPrinter.VerbosityPREVIEW verbosity, Consumer<String> out) Prints provided model as structured text in YAML format. -
Uses of Consumer in java.lang.foreign
Modifier and TypeMethodDescriptionMemorySegment.reinterpret
(long newSize, Arena arena, Consumer<MemorySegment> cleanup) Restricted.Returns a new segment with the same address as this segment, but with the provided size and scope.MemorySegment.reinterpret
(Arena arena, Consumer<MemorySegment> cleanup) Restricted.Returns a new memory segment with the same address and size as this segment, but with the provided scope. -
Uses of Consumer in java.net.http
Modifier and TypeMethodDescriptionstatic HttpResponse.BodyHandler
<Void> HttpResponse.BodyHandlers.ofByteArrayConsumer
(Consumer<Optional<byte[]>> consumer) Returns aBodyHandler<Void>
that returns aBodySubscriber
<Void>
obtained fromBodySubscribers.ofByteArrayConsumer(Consumer)
.static HttpResponse.BodySubscriber
<Void> HttpResponse.BodySubscribers.ofByteArrayConsumer
(Consumer<Optional<byte[]>> consumer) Returns aBodySubscriber
which provides the incoming body data to the provided Consumer ofOptional<byte[]>
. -
Uses of Consumer in java.nio.channels
Modifier and TypeMethodDescriptionint
Selector.select
(Consumer<SelectionKey> action) Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.int
Selector.select
(Consumer<SelectionKey> action, long timeout) Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.int
Selector.selectNow
(Consumer<SelectionKey> action) Selects and performs an action on the keys whose corresponding channels are ready for I/O operations. -
Uses of Consumer in java.util
Modifier and TypeMethodDescriptionvoid
void
void
void
default void
Iterator.forEachRemaining
(Consumer<? super E> action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception.default void
PrimitiveIterator.OfDouble.forEachRemaining
(Consumer<? super Double> action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception.default void
PrimitiveIterator.OfInt.forEachRemaining
(Consumer<? super Integer> action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception.default void
PrimitiveIterator.OfLong.forEachRemaining
(Consumer<? super Long> action) Performs the given action for each remaining element until all elements have been processed or the action throws an exception.default void
Spliterator.forEachRemaining
(Consumer<? super T> action) Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.default void
Spliterator.OfDouble.forEachRemaining
(Consumer<? super Double> action) Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.default void
Spliterator.OfInt.forEachRemaining
(Consumer<? super Integer> action) Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.default void
Spliterator.OfLong.forEachRemaining
(Consumer<? super Long> action) Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.void
If a value is present, performs the given action with the value, otherwise does nothing.void
Optional.ifPresentOrElse
(Consumer<? super T> action, Runnable emptyAction) If a value is present, performs the given action with the value, otherwise performs the given empty-based action.default boolean
Spliterator.OfDouble.tryAdvance
(Consumer<? super Double> action) If a remaining element exists: performs the given action on it, returningtrue
; else returnsfalse
.default boolean
Spliterator.OfInt.tryAdvance
(Consumer<? super Integer> action) If a remaining element exists: performs the given action on it, returningtrue
; else returnsfalse
.default boolean
Spliterator.OfLong.tryAdvance
(Consumer<? super Long> action) If a remaining element exists: performs the given action on it, returningtrue
; else returnsfalse
.boolean
Spliterator.tryAdvance
(Consumer<? super T> action) If a remaining element exists: performs the given action on it, returningtrue
; else returnsfalse
. -
Uses of Consumer in java.util.concurrent
Modifier and TypeMethodDescriptionCompletableFuture.acceptEither
(CompletionStage<? extends T> other, Consumer<? super T> action) CompletionStage.acceptEither
(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.CompletableFuture.acceptEitherAsync
(CompletionStage<? extends T> other, Consumer<? super T> action) CompletableFuture.acceptEitherAsync
(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) CompletionStage.acceptEitherAsync
(CompletionStage<? extends T> other, Consumer<? super T> action) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action.CompletionStage.acceptEitherAsync
(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.Processes all published items using the given Consumer function.void
<U> void
ConcurrentHashMap.forEach
(long parallelismThreshold, BiFunction<? super K, ? super V, ? extends U> transformer, Consumer<? super U> action) Performs the given action for each non-null transformation of each (key, value).void
void
void
void
void
void
void
void
void
ConcurrentHashMap.forEachEntry
(long parallelismThreshold, Consumer<? super Map.Entry<K, V>> action) Performs the given action for each entry.<U> void
ConcurrentHashMap.forEachEntry
(long parallelismThreshold, Function<Map.Entry<K, V>, ? extends U> transformer, Consumer<? super U> action) Performs the given action for each non-null transformation of each entry.void
ConcurrentHashMap.forEachKey
(long parallelismThreshold, Consumer<? super K> action) Performs the given action for each key.<U> void
ConcurrentHashMap.forEachKey
(long parallelismThreshold, Function<? super K, ? extends U> transformer, Consumer<? super U> action) Performs the given action for each non-null transformation of each key.void
ConcurrentHashMap.forEachValue
(long parallelismThreshold, Consumer<? super V> action) Performs the given action for each value.<U> void
ConcurrentHashMap.forEachValue
(long parallelismThreshold, Function<? super V, ? extends U> transformer, Consumer<? super U> action) Performs the given action for each non-null transformation of each value.CompletableFuture.thenAccept
(Consumer<? super T> action) CompletionStage.thenAccept
(Consumer<? super T> action) Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.CompletableFuture.thenAcceptAsync
(Consumer<? super T> action) CompletableFuture.thenAcceptAsync
(Consumer<? super T> action, Executor executor) CompletionStage.thenAcceptAsync
(Consumer<? super T> action) Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action.CompletionStage.thenAcceptAsync
(Consumer<? super T> action, Executor executor) Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action. -
Uses of Consumer in java.util.function
Modifier and TypeMethodDescriptionReturns a composedConsumer
that performs, in sequence, this operation followed by theafter
operation. -
Uses of Consumer in java.util.stream
Modifier and TypeInterfaceDescriptionstatic interface
A mutable builder for aStream
.Modifier and TypeMethodDescriptionvoid
Performs an action for each element of this stream.void
Stream.forEachOrdered
(Consumer<? super T> action) Performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.Modifier and TypeMethodDescriptiondefault <R> Stream
<R> Stream.mapMulti
(BiConsumer<? super T, ? super Consumer<R>> mapper) Returns a stream consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements. -
Uses of Consumer in jdk.jfr.consumer
Modifier and TypeMethodDescriptionvoid
Registers an action to perform if an exception occurs.void
void
EventStream.onEvent
(String eventName, Consumer<RecordedEvent> action) Registers an action to perform on all events matching a name.void
EventStream.onEvent
(Consumer<RecordedEvent> action) Registers an action to perform on all events in the stream.void
RecordingStream.onEvent
(String eventName, Consumer<RecordedEvent> action) void
RecordingStream.onEvent
(Consumer<RecordedEvent> action) default void
EventStream.onMetadata
(Consumer<MetadataEvent> action) Registers an action to perform when new metadata arrives in the stream. -
Uses of Consumer in jdk.jshell
Modifier and TypeMethodDescriptionJShell.onShutdown
(Consumer<JShell> listener) Register a callback to be called when this JShell instance terminates.JShell.onSnippetEvent
(Consumer<SnippetEvent> listener) Register a callback to be called when the Status of a snippet changes. -
Uses of Consumer in jdk.jshell.execution
Modifier and TypeMethodDescriptionstatic void
Util.detectJdiExitEvent
(VirtualMachine vm, Consumer<String> unbiddenExitHandler) Monitor the JDI event stream forVMDeathEvent
andVMDisconnectEvent
.Modifier and TypeMethodDescriptionstatic void
Util.forwardExecutionControlAndIO
(ExecutionControl ec, InputStream inStream, OutputStream outStream, Map<String, Consumer<OutputStream>> outputStreamMap, Map<String, Consumer<InputStream>> inputStreamMap) Forward commands from the input to the specifiedExecutionControl
instance, then responses back on the output. -
Uses of Consumer in jdk.management.jfr
Modifier and TypeMethodDescriptionvoid
void
RemoteRecordingStream.onEvent
(String eventName, Consumer<RecordedEvent> action) void
RemoteRecordingStream.onEvent
(Consumer<RecordedEvent> action)