- All Implemented Interfaces:
Encode
,ValidMediaFilter
,ValidMediaInput
,ValidMediaOutput
,NoClose
,Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
UrlWriter
,WhitespaceWriter
Note: The specialized subclasses implement per-type interfaces precisely matching the supported encoders.
- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final IOConsumer
<? super MediaWriter> Thecloser(MediaWriter)
implementation used for methods where not specified, such asMediaType.newMediaWriter(com.aoapps.encoding.EncodingContext, com.aoapps.encoding.MediaEncoder, java.io.Writer)
.static final Predicate
<? super MediaWriter> TheisNoClose(MediaWriter)
implementation used for methods where not specified, such asMediaType.newMediaWriter(com.aoapps.encoding.EncodingContext, com.aoapps.encoding.MediaEncoder, java.io.Writer)
.Fields inherited from class java.io.FilterWriter
out
-
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) append
(CharSequence csq) append
(CharSequence csq, int start, int end) boolean
canSkipValidation
(MediaType outputType) Checks if validation may be skipped when the characters being written to this validator is already known to be valid with the given media type.final void
close()
Encodes the given nested type with proper encoding.Encodes the given nested type with proper encoding.Encodes the given nested type with proper encoding.Encodes the given nested type with proper encoding.<Ex extends Throwable>
MediaWriterencode
(MediaType contentType, MediaWritable<Ex> content) Encodes the given nested type with proper encoding.<Ex extends Throwable>
MediaWriterencode
(MediaType contentType, IOSupplierE<?, Ex> content) Encodes the given nested type with proper encoding.encode
(MediaType contentType, CharSequence csq) Encodes the given nested type with proper encoding.encode
(MediaType contentType, CharSequence csq, int start, int end) Encodes the given nested type with proper encoding.Encodes the given nested type with proper encoding.abstract MediaType
Gets the input type.Gets the output type.final boolean
boolean
isValidatingMediaInputType
(MediaType inputType) Checks if this is validating the provided type, which allows one validator to be substituted in place of another.Methods inherited from class com.aoapps.lang.io.EncoderWriter
getOut, write, write, write, write, write, writePrefix, writeSuffix, writeSuffix
Methods inherited from class java.io.FilterWriter
flush
Methods inherited from class java.io.Writer
nullWriter
-
Field Details
-
DEFAULT_IS_NO_CLOSE
TheisNoClose(MediaWriter)
implementation used for methods where not specified, such asMediaType.newMediaWriter(com.aoapps.encoding.EncodingContext, com.aoapps.encoding.MediaEncoder, java.io.Writer)
.Defaults to
(out instanceof NoClose) && ((NoClose)out).isNoClose()
-
DEFAULT_CLOSER
Thecloser(MediaWriter)
implementation used for methods where not specified, such asMediaType.newMediaWriter(com.aoapps.encoding.EncodingContext, com.aoapps.encoding.MediaEncoder, java.io.Writer)
.Defaults to
mediaWriter.out.close()
-
-
Method Details
-
getEncodingContext
-
getEncoder
- Overrides:
getEncoder
in classEncoderWriter
-
isNoClose
public final boolean isNoClose()- Specified by:
isNoClose
in interfaceNoClose
- Overrides:
isNoClose
in classEncoderWriter
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceNoClose
- Overrides:
close
in classFilterWriter
- Throws:
IOException
-
getValidMediaInputType
Gets the input type.Gets the media type this specific type of media writer represents. This is a one-to-one relationship: every media type has a specific writer.
- Specified by:
getValidMediaInputType
in interfaceValidMediaInput
-
isValidatingMediaInputType
Description copied from interface:ValidMediaInput
Checks if this is validating the provided type, which allows one validator to be substituted in place of another. This is acceptable when this validator is equal to, or more strict, than the giveninputType
.Please note that this validator only needs to block invalid characters for
inputType
. This validator does not need to let through all characters, just block the invalid. This is a one-way optimization.This is almost the inverse operation of
ValidMediaInput.isValidatingMediaInputType(com.aoapps.encoding.MediaType)
, with the exception of characters only invalid due to nested encodings.- Specified by:
isValidatingMediaInputType
in interfaceValidMediaInput
- Returns:
true
when this validator will throw exceptions on all invalid characters from the giveninputType
- See Also:
-
canSkipValidation
Description copied from interface:ValidMediaInput
Checks if validation may be skipped when the characters being written to this validator is already known to be valid with the given media type. This may be done when every valid character for the given media type is also valid within this validator.This is almost the inverse operation of
ValidMediaInput.isValidatingMediaInputType(com.aoapps.encoding.MediaType)
, with the exception of characters only invalid due to nested encodings.- Specified by:
canSkipValidation
in interfaceValidMediaInput
- Returns:
true
when all valid characters of the givenoutputType
are also valid on this validator- See Also:
-
getValidMediaOutputType
Description copied from interface:ValidMediaOutput
Gets the output type.- Specified by:
getValidMediaOutputType
in interfaceValidMediaOutput
-
append
- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classEncoderWriter
- Throws:
IOException
-
append
- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classEncoderWriter
- Throws:
IOException
-
append
- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classEncoderWriter
- Throws:
IOException
-
encode
Description copied from interface:Encode
Encodes the given nested type with proper encoding.- Specified by:
encode
in interfaceEncode
- Returns:
this
writer- Throws:
IOException
-
encode
Description copied from interface:Encode
Encodes the given nested type with proper encoding.- Specified by:
encode
in interfaceEncode
- Returns:
this
writer- Throws:
IOException
-
encode
public MediaWriter encode(MediaType contentType, char[] cbuf, int offset, int len) throws IOException Description copied from interface:Encode
Encodes the given nested type with proper encoding.- Specified by:
encode
in interfaceEncode
- Returns:
this
writer- Throws:
IOException
-
encode
Description copied from interface:Encode
Encodes the given nested type with proper encoding.Adds prefixes and suffixes by media type, such as
"…"
.If the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.
- Specified by:
encode
in interfaceEncode
- Returns:
this
writer- Throws:
IOException
-
encode
public MediaWriter encode(MediaType contentType, CharSequence csq, int start, int end) throws IOException Description copied from interface:Encode
Encodes the given nested type with proper encoding.Adds prefixes and suffixes by media type, such as
"…"
.If the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.
- Specified by:
encode
in interfaceEncode
- Returns:
this
writer- Throws:
IOException
-
encode
Description copied from interface:Encode
Encodes the given nested type with proper encoding.Adds prefixes and suffixes by media type, such as
"…"
.If the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.
- Specified by:
encode
in interfaceEncode
- Returns:
this
writer- Throws:
IOException
-
encode
public <Ex extends Throwable> MediaWriter encode(MediaType contentType, IOSupplierE<?, Ex> content) throws IOException, ExDescription copied from interface:Encode
Encodes the given nested type with proper encoding.Adds prefixes and suffixes by media type, such as
"…"
.If the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.
- Specified by:
encode
in interfaceEncode
- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Returns:
this
writer- Throws:
IOException
Ex
-
encode
public <Ex extends Throwable> MediaWriter encode(MediaType contentType, MediaWritable<Ex> content) throws IOException, Ex Description copied from interface:Encode
Encodes the given nested type with proper encoding.Adds prefixes and suffixes by media type, such as
"…"
.Does not perform any translation markups.
- Specified by:
encode
in interfaceEncode
- Type Parameters:
Ex
- An arbitrary exception type that may be thrown- Returns:
this
writer- Throws:
IOException
Ex
-
encode
Description copied from interface:Encode
Encodes the given nested type with proper encoding. This is well suited for use in a try-with-resources block.Adds prefixes and suffixes by media type, such as
"…"
.Does not perform any translation markups.
- Specified by:
encode
in interfaceEncode
- Returns:
- A new writer that may be used for the given content type.
This writer must be closed for completed calls to
MediaEncoder.writeSuffixTo(java.lang.Appendable, boolean)
.The returned writer will be of the specific subclass of
MediaWriter
matchingcontentType
(seeMediaType.getMediaWriterClass()
. This meansgetValidMediaInputType()
will becontentType
. - Throws:
IOException
-