Class SpoofedTextContentReader

All Implemented Interfaces:
ContentAccessor, ContentReader

public class SpoofedTextContentReader extends AbstractContentReader
Provides access to text data that is generated when requested.

The URL has the format: spoofed://{locale=en_GB,seed=12345,length=1024,strings=["Alfresco", "Cloud"]}

The lexicon for the given locale is found by taking the language part of the locale (en in en_GB) and finding the resource alfresco/textgen/lexicon-stem-en.txt.

Since:
5.1
Author:
Derek Hulley
See Also:
  • TextGenerator
  • Field Details

  • Constructor Details

    • SpoofedTextContentReader

      public SpoofedTextContentReader(String url)
      Parameters:
      url - a URL describing the type of text to produce (see class comments)
  • Method Details

    • getTextGenerator

      public static org.alfresco.textgen.TextGenerator getTextGenerator(Locale locale)
      Get a text generator for the given locale
      Throws:
      RuntimeException - if the locale has no lexicon exists for the locale
    • createContentUrl

      public static String createContentUrl(Locale locale, long seed, long size, String... words)
      Helper to create a content URL that represents spoofed text
      Parameters:
      locale - the text local (must be supported by an appropriate lexicon config resource)
      seed - numerical seed to ensure repeatable sequences of random text
      size - the size (bytes) of the text to generate
      words - additional words with decreasing frequency
      Returns:
      the content URL
      Throws:
      IllegalArgumentException - if the resulting URL exceeds 255 characters
    • exists

      public boolean exists()
      Returns:
      true always
    • getTextGenerator

      public org.alfresco.textgen.TextGenerator getTextGenerator()
      Returns:
      the text generator that will make the spoofed text
    • getSeed

      public long getSeed()
      Returns:
      the random seed for the spoofed text
    • getWords

      public String[] getWords()
      Returns:
      the words to add to the spoofed text
    • getSize

      public long getSize()
      Returns:
      spoofed text size
    • getLastModified

      public long getLastModified()
      See Also:
    • createReader

      protected ContentReader createReader() throws ContentIOException
      The URL of the write is known from the start and this method contract states that no consideration needs to be taken w.r.t. the stream state.
      Specified by:
      createReader in class AbstractContentReader
      Returns:
      Returns a reader onto the location referenced by this instance. The instance must always be a new instance.
      Throws:
      ContentIOException
    • getDirectReadableChannel

      protected ReadableByteChannel getDirectReadableChannel() throws ContentIOException
      Description copied from class: AbstractContentReader
      Provides low-level access to read content from the repository.

      This is the only of the content reading methods that needs to be implemented by derived classes. All other content access methods make use of this in their underlying implementations.

      Specified by:
      getDirectReadableChannel in class AbstractContentReader
      Returns:
      Returns a channel from which content can be read
      Throws:
      ContentIOException - if the channel could not be opened or the underlying content has disappeared
    • setContentUrl

      protected final void setContentUrl(String contentUrl)
      Description copied from class: AbstractContentAccessor
      Allow derived implementations to set the Content URL. This allows for implementations where the URL is not known when the accessor is first constructed.
      Overrides:
      setContentUrl in class AbstractContentAccessor
      Parameters:
      contentUrl - the new content URL