Class AwkSink
- Direct Known Subclasses:
AppendableAwkSink,OutputStreamAwkSink
print and printf statements.
Implementations decide how to represent AWK output, whether as text written to a stream, appended characters, or structured values collected by the embedding application. Numeric rendering uses the sink's immutable construction-time locale.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Flushes any buffered output held by this sink.static StringformatOutputValue(Object value, String ofmt, Locale locale) Formats one already-normalized AWK output value.static AwkSinkfrom(OutputStream outputStream) Creates a sink backed by anOutputStream.static AwkSinkfrom(OutputStream outputStream, Locale locale) Creates a sink backed by anOutputStream.static AwkSinkfrom(PrintStream printStream) Creates a sink backed by aPrintStream.static AwkSinkfrom(PrintStream printStream, Locale locale) Creates a sink backed by aPrintStream.static AwkSinkfrom(Appendable appendable) Creates a sink backed by anAppendable.static AwkSinkfrom(Appendable appendable, Locale locale) Creates a sink backed by anAppendable.final LocaleReturns the locale used by this sink when it renders numeric values.Returns aPrintStreamview that receives raw process output written by spawned commands such assystem("...").abstract voidWrites one AWKprintoperation.abstract voidWrites one AWKprintfoperation.Formats a string in the same way as AWK'ssprintf()built-in.
-
Field Details
-
NOP_SINK
A shared no-op sink that silently discards all output.This singleton is safe to share across all JRT/AVM instances because its
print(String, String, String, Object...),printf(String, String, String, String, Object...), andflush()operations are all no-ops.
-
-
Method Details
-
getLocale
Returns the locale used by this sink when it renders numeric values.- Returns:
- sink locale
-
print
public abstract void print(String ofs, String ors, String ofmt, Object... values) throws IOException Writes one AWKprintoperation.- Parameters:
ofs- output field separatorors- output record separatorofmt- numeric output format used by plainprintvalues- values supplied toprint- Throws:
IOException- if the sink cannot write the output
-
printf
public abstract void printf(String ofs, String ors, String ofmt, String format, Object... values) throws IOException Writes one AWKprintfoperation.- Parameters:
ofs- output field separatorors- output record separatorofmt- numeric output format available to the sinkformat- format string passed toprintfvalues- arguments supplied after the format string- Throws:
IOException- if the sink cannot write the output
-
flush
Flushes any buffered output held by this sink.- Throws:
IOException- if the sink cannot be flushed
-
getPrintStream
Returns aPrintStreamview that receives raw process output written by spawned commands such assystem("...").The default implementation returns a stream that silently discards all output. Override this method in sinks that need to capture process output.
- Returns:
- print stream that should receive raw process output
-
from
Creates a sink backed by anOutputStream.- Parameters:
outputStream- stream that should receive AWK output- Returns:
- sink writing to
outputStream
-
from
Creates a sink backed by anOutputStream.- Parameters:
outputStream- stream that should receive AWK outputlocale- locale to use for numeric formatting- Returns:
- sink writing to
outputStream
-
from
Creates a sink backed by aPrintStream.- Parameters:
printStream- stream that should receive AWK output- Returns:
- sink writing to
printStream
-
from
Creates a sink backed by aPrintStream.- Parameters:
printStream- stream that should receive AWK outputlocale- locale to use for numeric formatting- Returns:
- sink writing to
printStream
-
from
Creates a sink backed by anAppendable.- Parameters:
appendable- appendable that should receive AWK output- Returns:
- sink writing to
appendable
-
from
Creates a sink backed by anAppendable.- Parameters:
appendable- appendable that should receive AWK outputlocale- locale to use for numeric formatting- Returns:
- sink writing to
appendable
-
sprintf
Formats a string in the same way as AWK'ssprintf()built-in.Subclasses may override this method to customize formatting. The default implementation delegates to
Printf4J.sprintf(Locale, String, Object...). Becauseprintf(String, String, String, String, Object...)uses this method internally, overriding it ensures that bothprintfandsprintfproduce consistent output.- Parameters:
format- format stringvalues- arguments supplied after the format string- Returns:
- formatted text
-
formatOutputValue
Formats one already-normalized AWK output value.- Parameters:
value- value to formatofmt- numeric output formatlocale- locale used for numeric formatting- Returns:
- textual output for
value
-