de.esprit.appsuite.io.parser

## Class DataParser<C extends ApplicationContext>

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<C>
    - - de.esprit.appsuite.task.AbstractAsyncExecutable<C>
      - - de.esprit.appsuite.io.parser.DataParser<C>

- All Implemented Interfaces:
    ApplicationObject<C>, AsyncExecutable<C>, CancellableTask, TaskMonitorSupport, SimpleLogSupport, Dumpable, Executable, java.io.Closeable, java.lang.AutoCloseable

      public abstract class DataParser<C extends ApplicationContext>
      extends AbstractAsyncExecutable<C>
      implements java.io.Closeable

  This is a generic file parser that allows for fast iteration through a file content looking for keywords and data. As the parser is `AsyncExecutable` it may run asynchronously within an `AsyncTask`. In async mode it fires 100 progress events per file read.
  Author:
    Rainer Buesch

- - ### Field Summary

    - ### Fields inherited from class de.esprit.appsuite.task.AbstractAsyncExecutable

      `childTaskRef, isTestMode, monitorController, resultRef, stateFlag`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataParser(C ctx, java.io.File file)`
    `DataParser(C ctx, FileInfo fileInfo)`
    `DataParser(C ctx, java.io.File file, int buffSize)`
    `DataParser(C ctx, java.io.InputStream inStream, FileInfo fileInfo)`
    `DataParser(C ctx, LogChannel logCh, java.io.File file)`
    `DataParser(C ctx, LogChannel logCh, FileInfo fileInfo)`
    `DataParser(C ctx, LogChannel logCh, FileInfo fileInfo, int buffSize)`
    `DataParser(C ctx, LogChannel logCh, java.io.File file, int buffSize)`
    `DataParser(C ctx, LogChannel logCh, java.io.InputStream inStream, FileInfo fileInfo)`
    `DataParser(C ctx, LogChannel logCh, ProgressReader reader)`
    `DataParser(C ctx, LogChannel logCh, ResourceInfo resourceInfo)`
    `DataParser(C ctx, LogChannel logCh, ResourceInfo resourceInfo, int buffSize)`
    `DataParser(C ctx, ProgressReader reader)`
    `DataParser(C ctx, ResourceInfo resourceInfo)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `protected FastStringIterator` | `createWordIterator()`
    `protected void` | `doOnFileClosed(FileInfo fileInfo)` Is called after the file has been closed
    `protected void` | `doOnFileOpening(FileInfo fileInfo)` Is called when the file is being opened
    `void` | `executeAsync()` Contains the code to be executed asynchronously.
    `double` | `getAndSkipDouble()`
    `int` | `getAndSkipInt()`
    `java.lang.String` | `getAndSkipToken()`
    `char` | `getBlockCommentChar()`
    `double` | `getCurrentDouble()`
    `int` | `getCurrentInt()`
    `java.lang.String` | `getCurrentKeyword(java.lang.String... keywords)` Returns the current keyword and throws an Exception if it is not one of the given keywords.
    `java.lang.String` | `getCurrentLine()`
    `int` | `getCurrentLineIndex()`
    `long` | `getCurrentLong()`
    `java.lang.String` | `getCurrentToken()`
    `java.lang.String` | `getCurrentToRestOfLine()`
    `FileInfo` | `getFileInfo()` May be null if we are reading a system resource
    `long` | `getFileSize()`
    `char` | `getLineCommentChar()`
    `int` | `getLineNumber()`
    `double` | `getNextDouble()`
    `int` | `getNextInt()`
    `java.lang.String` | `getNextKeyword(java.lang.String... keywords)` Searches for the next keyword which must be one in the given keywords.
    `long` | `getNextLong()`
    `java.lang.String` | `getNextToken()`
    `java.lang.String` | `getNextToRestOfLine()`
    `int` | `getReadPercentage()`
    `int` | `getReadTokenCount()`
    `java.lang.String` | `getRestOfLine()`
    `boolean` | `hasNext()`
    `protected ProgressReader` | `openStream()`
    `protected abstract void` | `performRead()`
    `java.lang.String` | `readLine()`
    `void` | `setBlockCommentChar(char blockCommentChar)`
    `void` | `setLineCommentChar(char lineCommentChar)`
    `void` | `setSkipCommentBlocks(boolean isSkipCommentBlocks)`
    `void` | `setSkipCommentLines(boolean isSkip)`
    `void` | `setSkipEmptyLines(boolean isSkip)`
    `void` | `skipAll()` Stops any further parsing of input data.
    `void` | `skipCheckedMatchingCurrentToken(java.lang.String token)` Forwards to the next token if the current token matches the given token.
    `void` | `skipLine()` Moves one line forward
    `void` | `skipLines(long numLines)` Moves numLines forward
    `boolean` | `skipMatchingCurrentToken(java.lang.String token)` Forwards to the next token if the current token matches the given token.
    `void` | `skipRestOfLine()` Moves to the end of line and resets the currentToken to null.
    `void` | `skipToken()`
    `void` | `skipTokens(long wordCnt)`
    `void` | `skipToKeyword(java.lang.String keyword)` Moves to the next word that matches the given keyword.

    - ### Methods inherited from class de.esprit.appsuite.task.AbstractAsyncExecutable

      `addMonitor, checkCancelled, checkForErrorAndRethrow, clearMonitors, createRunStateFlag, doOnCancel, doOnFailure, execute, executeSubTask, getError, getMaxProgressSteps, getMonitorCount, getMonitors, getName, getProgressStepCount, getResult, getRunStateFlag, getTaskId, getType, handleCancellation, handleFailure, handleFinish, handleStart, handleSuccess, hasError, hasMonitor, isCancellable, notifyProceeded, registerTaskStateChange, removeMonitor, resetProgress, setCancellable, setLogLevel, setMaxProgressSteps, setMonitor, setName, setName, setResult, setRunStateFlag, setTaskId, setType, shouldFireMonitor, sleepChecked, wasCancelled`

    - ### Methods inherited from class de.esprit.appsuite.launch.AbstractApplicationObject

      `getApplicationContext, getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toDumpString, toString, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface de.esprit.appsuite.launch.ApplicationObject

      `getApplicationContext`

    - ### Methods inherited from interface de.esprit.common.log.SimpleLogSupport

      `getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

- - ### Constructor Detail

    - #### DataParser

          public DataParser(C ctx,
                    java.io.File file)

    - #### DataParser

          public DataParser(C ctx,
                    java.io.File file,
                    int buffSize)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    java.io.File file)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    java.io.File file,
                    int buffSize)

    - #### DataParser

          public DataParser(C ctx,
                    FileInfo fileInfo)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    FileInfo fileInfo)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    FileInfo fileInfo,
                    int buffSize)

    - #### DataParser

          public DataParser(C ctx,
                    java.io.InputStream inStream,
                    FileInfo fileInfo)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    java.io.InputStream inStream,
                    FileInfo fileInfo)

    - #### DataParser

          public DataParser(C ctx,
                    ProgressReader reader)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    ProgressReader reader)

    - #### DataParser

          public DataParser(C ctx,
                    ResourceInfo resourceInfo)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    ResourceInfo resourceInfo)

    - #### DataParser

          public DataParser(C ctx,
                    LogChannel logCh,
                    ResourceInfo resourceInfo,
                    int buffSize)

  - ### Method Detail

    - #### getLineNumber

          public int getLineNumber()

    - #### openStream

          protected ProgressReader openStream()
                                       throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### executeAsync

          public final void executeAsync()
                                  throws java.lang.Exception

      Description copied from interface: `AsyncExecutable`
      Contains the code to be executed asynchronously. WARNING: This method should never be called directly by the programmer. It rather must be called by `Runnable.run()` for async execution.
      Specified by:
        `executeAsync` in interface `AsyncExecutable<C extends ApplicationContext>`
      Specified by:
        `executeAsync` in class `AbstractAsyncExecutable<C extends ApplicationContext>`
      Throws:
        `java.lang.Exception`
      See Also:
        `for synchronous execution`

    - #### close

          public void close()

      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`

    - #### doOnFileClosed

          protected void doOnFileClosed(FileInfo fileInfo)

      Is called after the file has been closed

    - #### doOnFileOpening

          protected void doOnFileOpening(FileInfo fileInfo)

      Is called when the file is being opened

    - #### performRead

          protected abstract void performRead()
                                       throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### createWordIterator

          protected FastStringIterator createWordIterator()

    - #### setSkipCommentBlocks

          public void setSkipCommentBlocks(boolean isSkipCommentBlocks)

    - #### getBlockCommentChar

          public char getBlockCommentChar()

    - #### setBlockCommentChar

          public void setBlockCommentChar(char blockCommentChar)

    - #### getLineCommentChar

          public char getLineCommentChar()

    - #### setLineCommentChar

          public void setLineCommentChar(char lineCommentChar)

    - #### getFileSize

          public long getFileSize()

    - #### getFileInfo

          public FileInfo getFileInfo()

      May be null if we are reading a system resource

    - #### skipAll

          public void skipAll()

      Stops any further parsing of input data. Use this method if you got what you were looking for and you want to stop reading immediately.

    - #### skipMatchingCurrentToken

          public boolean skipMatchingCurrentToken(java.lang.String token)
                                           throws java.lang.Exception

      Forwards to the next token if the current token matches the given token.
      Returns:
        true if the given token matched the current and a `getNextToken()` call has been done.
      Throws:
        `java.lang.Exception`

    - #### skipCheckedMatchingCurrentToken

          public void skipCheckedMatchingCurrentToken(java.lang.String token)
                                               throws java.lang.Exception

      Forwards to the next token if the current token matches the given token.
      Throws:
        `java.lang.Exception` - if the current token did not match the given token

    - #### skipRestOfLine

          public void skipRestOfLine()

      Moves to the end of line and resets the currentToken to null.

    - #### skipLine

          public void skipLine()
                        throws java.lang.Exception

      Moves one line forward
      Throws:
        `java.lang.Exception`

    - #### skipLines

          public void skipLines(long numLines)
                         throws java.lang.Exception

      Moves numLines forward
      Throws:
        `java.lang.Exception`

    - #### skipToken

          public void skipToken()
                         throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### skipTokens

          public void skipTokens(long wordCnt)
                          throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### skipToKeyword

          public void skipToKeyword(java.lang.String keyword)
                             throws java.lang.Exception

      Moves to the next word that matches the given keyword.
      Throws:
        `java.lang.Exception`

    - #### readLine

          public final java.lang.String readLine()
                                          throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### getCurrentLineIndex

          public int getCurrentLineIndex()

    - #### setSkipCommentLines

          public void setSkipCommentLines(boolean isSkip)

    - #### setSkipEmptyLines

          public void setSkipEmptyLines(boolean isSkip)

    - #### getNextKeyword

          public java.lang.String getNextKeyword(java.lang.String... keywords)
                                          throws java.lang.Exception

      Searches for the next keyword which must be one in the given keywords.
      Throws:
        `UnexpectedKeywordException` - if the next word is not one of the expected keywords
        `java.lang.Exception`

    - #### getCurrentKeyword

          public java.lang.String getCurrentKeyword(java.lang.String... keywords)
                                             throws java.lang.Exception

      Returns the current keyword and throws an Exception if it is not one of the given keywords.
      Throws:
        `UnexpectedKeywordException` - if the next word is not one of the expected keywords
        `java.lang.Exception`

    - #### getCurrentLine

          public java.lang.String getCurrentLine()

    - #### getCurrentToken

          public java.lang.String getCurrentToken()
                                           throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getAndSkipToken

          public java.lang.String getAndSkipToken()
                                           throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getNextToken

          public java.lang.String getNextToken()
                                        throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getReadTokenCount

          public int getReadTokenCount()

    - #### getReadPercentage

          public int getReadPercentage()

    - #### getCurrentInt

          public int getCurrentInt()
                            throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getCurrentLong

          public long getCurrentLong()
                              throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getAndSkipInt

          public int getAndSkipInt()
                            throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getNextInt

          public int getNextInt()
                         throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getNextLong

          public long getNextLong()
                           throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getCurrentDouble

          public double getCurrentDouble()
                                  throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getAndSkipDouble

          public double getAndSkipDouble()
                                  throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getNextDouble

          public double getNextDouble()
                               throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### hasNext

          public boolean hasNext()
                          throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getRestOfLine

          public java.lang.String getRestOfLine()
                                         throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getNextToRestOfLine

          public java.lang.String getNextToRestOfLine()
                                               throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### getCurrentToRestOfLine

          public java.lang.String getCurrentToRestOfLine()
                                                  throws java.lang.Exception

      Throws:
        `java.lang.Exception`

Copyright © 2014 EsprIT-Systems. All Rights Reserved.