java.lang.Object
java.io.Writer
java.io.FilterWriter
com.aoapps.encoding.MediaValidator
- All Implemented Interfaces:
ValidMediaFilter
,ValidMediaInput
,ValidMediaOutput
,NoClose
,Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
BufferedValidator
,JavaScriptValidator
,MysqlValidator
,NoCloseMediaValidator
,PsqlValidator
,ShValidator
,StyleValidator
,TextValidator
,XhtmlAttributeValidator
,XhtmlValidator
@ThreadSafe
public abstract class MediaValidator
extends FilterWriter
implements ValidMediaFilter, NoClose
Verifies all characters going through this filter are valid for the given media type.
- Author:
- AO Industries, Inc.
-
Field Summary
Fields inherited from class java.io.FilterWriter
out
-
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) The default implementation of this append method in Writer calls the write(int) method for backward-compatibility.append
(CharSequence csq) The default implementation of this append method in Writer converts to a String for backward-compatibility.append
(CharSequence csq, int start, int end) The default implementation of this append method in Writer converts to a String for backward-compatibility.static MediaValidator
getMediaValidator
(MediaType contentType, Writer out) Gets the media validator for the given type.getOut()
Gets the wrapped writer, which has been optimized: First, passed throughCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder)
(withencoder = null
).final MediaType
The output type must be the same as the input type.boolean
Is this validator buffered?boolean
void
validate
(boolean trim) Performs final validation and resets the validator for reuse.Methods inherited from class java.io.Writer
nullWriter, write, write
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.aoapps.encoding.ValidMediaInput
canSkipValidation, getValidMediaInputType, isValidatingMediaInputType
-
Method Details
-
getMediaValidator
Gets the media validator for the given type. If the given writer is already validator for the requested type, will return the provided writer.Please note, the returned validator may be more strict than the requested media type. It is guaranteed to forbid at least all the invalid characters of
contentType
, but may also forbid more.When the returned
validator != out
,validate(boolean)
must be called to finalize the validation. When the returnedvalidator == out
,validate(boolean)
should not be called, since the provided writer will finalize the validation within its proper scope.- Parameters:
out
- First, when is already validating the content type, is returned directly. Second, will be optimized viaCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder)
(withencoder = null
). Third, then passed throughNoCloseMediaValidator.wrap(java.io.Writer)
whenout
isNoClose
andNoClose.isNoClose()
.- Returns:
- A new validator or
out
when the given writer is already a validator for the requested type.
-
getValidMediaOutputType
The output type must be the same as the input type.- Specified by:
getValidMediaOutputType
in interfaceValidMediaOutput
- Returns:
- The result of
ValidMediaInput.getValidMediaInputType()
-
isNoClose
public boolean isNoClose() -
isBuffered
public boolean isBuffered()Is this validator buffered? A buffered validator may delay validation untilvalidate(boolean)
. Furthermore, a buffered validator should not be bypassed before any buffered data has been written viavalidate(boolean)
. An example of encoder bypassing is performing direct output on the writer fromEncoderWriter.getOut()
.- Returns:
false
by default- See Also:
-
getOut
Gets the wrapped writer, which has been optimized: First, passed throughCoercion.optimize(java.io.Writer, com.aoapps.lang.io.Encoder)
(withencoder = null
). Second, passed throughNoCloseMediaValidator.wrap(java.io.Writer)
whenout
isNoClose
andNoClose.isNoClose()
. -
append
The default implementation of this append method in Writer converts to a String for backward-compatibility. This passes the append directly to the wrapped Writer.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Throws:
IOException
-
append
The default implementation of this append method in Writer converts to a String for backward-compatibility. This passes the append directly to the wrapped Writer.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Throws:
IOException
-
append
The default implementation of this append method in Writer calls the write(int) method for backward-compatibility. This passes the append directly to the wrapped Writer.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Throws:
IOException
-
validate
Performs final validation and resets the validator for reuse.- Parameters:
trim
- Requests that the buffer be trimmed, if buffered and trim supported.- Throws:
IOException
-