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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Flushes any buffered output held by this sink.protected final StringformatPrintArgument(Object value, String ofmt) Formats one operand of a plain AWKprintstatement.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, converting numeric%soperands with the suppliedCONVFMTvalue.
-
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, String, Object...), andflush()operations are all no-ops.
-
-
Constructor Details
-
AwkSink
protected AwkSink()Creates a sink using the defaultLocale.USformatting rules. -
AwkSink
Creates a sink using the supplied locale for numeric formatting.- Parameters:
localeParam- locale to use for numeric formatting
-
-
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 convfmt, String format, Object... values) throws IOException Writes one AWKprintfoperation.- Parameters:
ofs- output field separatorors- output record separatorofmt- numeric output format available to the sinkconvfmt- number-to-string conversion format (CONVFMT), used by%sto convert numeric values the way AWK doesformat- 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
-
formatPrintArgument
Formats one operand of a plain AWKprintstatement.Numeric values are rendered with
OFMT(or as integers when they hold an integral value). String values — including numeric strings that originate from input — are printed verbatim, as required by POSIX.- Parameters:
value- operand to formatofmt- numeric output format- Returns:
- the textual representation AWK would print for this operand
-
sprintf
Formats a string in the same way as AWK'ssprintf()built-in, converting numeric%soperands with the suppliedCONVFMTvalue.Subclasses may override this method to customize formatting. The default implementation delegates to
AwkPrintf.sprintf(Locale, String, String, Object...). The built-in sinks renderprintfoutput through this method, so overriding it keepsprintfandsprintfconsistent.- Parameters:
convfmt- number-to-string conversion format (CONVFMT)format- format stringvalues- arguments supplied after the format string- Returns:
- formatted text
-