- 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
FieldsModifier 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) booleancanSkipValidation(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 voidclose()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 MediaTypeGets the input type.Gets the output type.final booleanbooleanisValidatingMediaInputType(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, writeSuffixMethods inherited from class java.io.FilterWriter
flushMethods 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:
getEncoderin classEncoderWriter
-
isNoClose
public final boolean isNoClose()- Specified by:
isNoClosein interfaceNoClose- Overrides:
isNoClosein classEncoderWriter
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceNoClose- Overrides:
closein 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:
getValidMediaInputTypein interfaceValidMediaInput
-
isValidatingMediaInputType
Description copied from interface:ValidMediaInputChecks 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:
isValidatingMediaInputTypein interfaceValidMediaInput- Returns:
truewhen this validator will throw exceptions on all invalid characters from the giveninputType- See Also:
-
canSkipValidation
Description copied from interface:ValidMediaInputChecks 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:
canSkipValidationin interfaceValidMediaInput- Returns:
truewhen all valid characters of the givenoutputTypeare also valid on this validator- See Also:
-
getValidMediaOutputType
Description copied from interface:ValidMediaOutputGets the output type.- Specified by:
getValidMediaOutputTypein interfaceValidMediaOutput
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classEncoderWriter- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classEncoderWriter- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classEncoderWriter- Throws:
IOException
-
encode
Description copied from interface:EncodeEncodes the given nested type with proper encoding.- Specified by:
encodein interfaceEncode- Returns:
thiswriter- Throws:
IOException
-
encode
Description copied from interface:EncodeEncodes the given nested type with proper encoding.- Specified by:
encodein interfaceEncode- Returns:
thiswriter- Throws:
IOException
-
encode
public MediaWriter encode(MediaType contentType, char[] cbuf, int offset, int len) throws IOException Description copied from interface:EncodeEncodes the given nested type with proper encoding.- Specified by:
encodein interfaceEncode- Returns:
thiswriter- Throws:
IOException
-
encode
Description copied from interface:EncodeEncodes 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:
encodein interfaceEncode- Returns:
thiswriter- Throws:
IOException
-
encode
public MediaWriter encode(MediaType contentType, CharSequence csq, int start, int end) throws IOException Description copied from interface:EncodeEncodes 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:
encodein interfaceEncode- Returns:
thiswriter- Throws:
IOException
-
encode
Description copied from interface:EncodeEncodes 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:
encodein interfaceEncode- Returns:
thiswriter- Throws:
IOException
-
encode
public <Ex extends Throwable> MediaWriter encode(MediaType contentType, IOSupplierE<?, Ex> content) throws IOException, ExDescription copied from interface:EncodeEncodes 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:
encodein interfaceEncode- Type Parameters:
Ex- An arbitrary exception type that may be thrown- Returns:
thiswriter- Throws:
IOExceptionEx
-
encode
public <Ex extends Throwable> MediaWriter encode(MediaType contentType, MediaWritable<Ex> content) throws IOException, Ex Description copied from interface:EncodeEncodes the given nested type with proper encoding.Adds prefixes and suffixes by media type, such as
"…".Does not perform any translation markups.
- Specified by:
encodein interfaceEncode- Type Parameters:
Ex- An arbitrary exception type that may be thrown- Returns:
thiswriter- Throws:
IOExceptionEx
-
encode
Description copied from interface:EncodeEncodes 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:
encodein 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
MediaWritermatchingcontentType(seeMediaType.getMediaWriterClass(). This meansgetValidMediaInputType()will becontentType. - Throws:
IOException
-
