Class ContentCharsetFinder


  • public class ContentCharsetFinder
    extends Object
    Utility bean to guess the charset given a stream and a mimetype.
    Since:
    2.1
    Author:
    Derek Hulley
    • Constructor Detail

      • ContentCharsetFinder

        public ContentCharsetFinder()
    • Method Detail

      • setDefaultCharset

        public void setDefaultCharset​(String defaultCharset)
        Override the system default charset. Where the characterset cannot be determined for a mimetype and input stream, this mimetype will be used. The default is 'UTF-8'.
        Parameters:
        defaultCharset - the default characterset
      • setMimetypeService

        public void setMimetypeService​(MimetypeService mimetypeService)
        Set the mimetype service that will help determine if a particular mimetype can be treated as encoded text or not.
      • setCharactersetFinders

        public void setCharactersetFinders​(List<org.alfresco.encoding.CharactersetFinder> charactersetFinders)
        Set the list of characterset finder to execute, in order, for text based content.
        Parameters:
        charactersetFinders - a list of finders
      • getCharset

        public Charset getCharset​(InputStream is,
                                  String mimetype)
        Gets the characterset from the stream, if the mimetype is text and the text has enough information to give the encoding away. Otherwise, the default is returned.
        Parameters:
        is - a stream that will not be affected by the call, but must support marking
        mimetype - the mimetype of the stream data - null if not known
        Returns:
        returns a characterset and never null