de.esprit.appsuite.nio.ascii

## Class AbstractAsciiParser<C extends ApplicationContext,L extends SimpleAsciiLine>

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<C>
    - - de.esprit.appsuite.task.AbstractAsyncExecutable<C>
      - - de.esprit.appsuite.nio.ascii.AbstractAsciiParser<C,L>

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

      public abstract class AbstractAsciiParser<C extends ApplicationContext,L extends SimpleAsciiLine>
      extends AbstractAsyncExecutable<C>
      implements java.io.Closeable

  This is a high performance parser for reading ascii text files. It uses a single `ByteBuffer` for reading the file line by line. just by setting markers in the buffer. Thus no new objects are created at all unless data is actually fetched for evaluation.
  Author:
    Thomas Stecher, Rainer Buesch

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected L` | `currentLine`
    `static int` | `DEFAULT_BUFF_SIZE`

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

      `childTaskRef, isTestMode, monitorController, resultRef, stateFlag`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `AbstractAsciiParser(C ctx, java.io.File file)`
    `` | `AbstractAsciiParser(C ctx, FileInfo fileInfo, java.io.InputStream stream)`
    `` | `AbstractAsciiParser(C ctx, FileInfo fileInfo, java.io.InputStream stream, int buffSize)`
    `protected` | `AbstractAsciiParser(C ctx, java.io.File file, int buffSize)`
    `` | `AbstractAsciiParser(C ctx, ProgressFileInputStream progressStream)`
    `` | `AbstractAsciiParser(C ctx, ProgressFileInputStream progressStream, int buffSize)`
    `` | `AbstractAsciiParser(C ctx, ProgressInputStream progressStream)`
    `` | `AbstractAsciiParser(C ctx, ProgressInputStream progressStream, int buffSize)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected byte` | `checkedByte(java.lang.Character c)`
    `void` | `close()` Closes the channel
    `protected abstract L` | `createAsciiLine(byte[] data)` Creates the required type of `AsciiLine` for this parser.
    `protected java.io.FileInputStream` | `createFileInputStream(java.io.File file)`
    `void` | `executeAsync()` Contains the code to be executed asynchronously.
    `AsciiWord` | `getCurrentToRestOfLine()` Returns the rest from the beginning of the current word to the end of the line
    `AsciiWord` | `getCurrentWord()`
    `FileInfo` | `getFileInfo()`
    `int` | `getLineNumber()` Returns the number of lines read so far.
    `L` | `getNextLine()` Fetches the next line into buffer
    `AsciiWord` | `getNextWord()` Get next word
    `long` | `getReadByteCount()` Returns the number of bytes read so far.
    `int` | `getReadOperationCount()` Returns the number of IO read operations that have been made so far.
    `AsciiWord` | `getRestOfLine()` Returns the rest from the end of the last word to the end of the line
    `protected boolean` | `isEndOfLineReached()` Tells whether EOL (end-of-line) was reached after a `nextWord()` call.
    `double` | `nextDouble()`
    `int` | `nextInt()`
    `L` | `nextLine()` Fetches the next line into buffer and returns it.
    `long` | `nextLong()`
    `short` | `nextShort()`
    `java.lang.String` | `nextString()`
    `AsciiWord` | `nextWord()` Fetches the next word of the current line.
    `void` | `openFile()` Opens the file channel, if not open yet.
    `protected void` | `performRead()`
    `void` | `setEncoding(java.lang.String encoding)` Defines the character encoding to be used.
    `void` | `setLineCommentChar(java.lang.Character lineCommentChar)` Sets the line comment character.
    `void` | `skipLines(long count)`
    `void` | `skipRestOfLine()`
    `void` | `skipWords(long count)`

    - ### 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`

- - ### Field Detail

    - #### DEFAULT_BUFF_SIZE

          public static final int DEFAULT_BUFF_SIZE

      See Also:
        Constant Field Values

    - #### currentLine

          protected final L extends SimpleAsciiLine currentLine

  - ### Constructor Detail

    - #### AbstractAsciiParser

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

    - #### AbstractAsciiParser

          protected AbstractAsciiParser(C ctx,
                             java.io.File file,
                             int buffSize)

    - #### AbstractAsciiParser

          public AbstractAsciiParser(C ctx,
                             ProgressInputStream progressStream)

    - #### AbstractAsciiParser

          public AbstractAsciiParser(C ctx,
                             ProgressInputStream progressStream,
                             int buffSize)

    - #### AbstractAsciiParser

          public AbstractAsciiParser(C ctx,
                             FileInfo fileInfo,
                             java.io.InputStream stream)

    - #### AbstractAsciiParser

          public AbstractAsciiParser(C ctx,
                             ProgressFileInputStream progressStream)

    - #### AbstractAsciiParser

          public AbstractAsciiParser(C ctx,
                             ProgressFileInputStream progressStream,
                             int buffSize)

    - #### AbstractAsciiParser

          public AbstractAsciiParser(C ctx,
                             FileInfo fileInfo,
                             java.io.InputStream stream,
                             int buffSize)

  - ### Method Detail

    - #### createAsciiLine

          protected abstract L createAsciiLine(byte[] data)

      Creates the required type of `AsciiLine` for this parser.

    - #### setEncoding

          public void setEncoding(java.lang.String encoding)

      Defines the character encoding to be used. If not set, then the default platform encoding is used.

    - #### openFile

          public final void openFile()
                              throws java.io.FileNotFoundException

      Opens the file channel, if not open yet. Needs to be called once before processing file data.
      Throws:
        `java.io.FileNotFoundException`

    - #### checkedByte

          protected final byte checkedByte(java.lang.Character c)

    - #### setLineCommentChar

          public final void setLineCommentChar(java.lang.Character lineCommentChar)

      Sets the line comment character. If set to null, then line comments are disabled.
      The default line comment character is '#'.

    - #### getFileInfo

          public final FileInfo getFileInfo()

    - #### getLineNumber

          public final int getLineNumber()

      Returns the number of lines read so far.

    - #### getReadByteCount

          public final long getReadByteCount()

      Returns the number of bytes read so far. Note that this number depends on the actual read buffer size in use.

    - #### getReadOperationCount

          public final int getReadOperationCount()

      Returns the number of IO read operations that have been made so far. Note that the bigger the read buffer the less the number of read operations.

    - #### performRead

          protected void performRead()
                              throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### createFileInputStream

          protected java.io.FileInputStream createFileInputStream(java.io.File file)
                                                           throws java.io.FileNotFoundException

      Throws:
        `java.io.FileNotFoundException`

    - #### 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`

    - #### nextString

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

      Throws:
        `java.io.IOException`

    - #### nextShort

          public final short nextShort()
                                throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### nextInt

          public final int nextInt()
                            throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### nextLong

          public final long nextLong()
                              throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### nextDouble

          public final double nextDouble()
                                  throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### getCurrentWord

          public final AsciiWord getCurrentWord()

    - #### getNextWord

          public final AsciiWord getNextWord()
                                      throws java.io.IOException

      Get next word
      Returns:
        null if EOF is reached
      Throws:
        `java.io.IOException`

    - #### nextWord

          public AsciiWord nextWord()
                             throws java.io.IOException

      Fetches the next word of the current line. If line end is reached, the next line is fetched into the buffer.
      Throws:
        `java.io.IOException` - if EOF is reached

    - #### getRestOfLine

          public final AsciiWord getRestOfLine()

      Returns the rest from the end of the last word to the end of the line

    - #### getCurrentToRestOfLine

          public final AsciiWord getCurrentToRestOfLine()

      Returns the rest from the beginning of the current word to the end of the line

    - #### skipRestOfLine

          public final void skipRestOfLine()

    - #### skipLines

          public final void skipLines(long count)
                               throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### skipWords

          public final void skipWords(long count)
                               throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### nextLine

          public L nextLine()
                                             throws java.io.IOException

      Fetches the next line into buffer and returns it.
      Throws:
        `java.io.EOFException` - if EOF is reached
        `java.io.IOException`

    - #### getNextLine

          public L getNextLine()
                                                throws java.io.IOException

      Fetches the next line into buffer
      Returns:
        null if EOF is reached
      Throws:
        `java.io.IOException`

    - #### close

          public final void close()

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

    - #### isEndOfLineReached

          protected final boolean isEndOfLineReached()

      Tells whether EOL (end-of-line) was reached after a `nextWord()` call. The flag is resetted with the next call to `nextWord()`;

Copyright © 2014 EsprIT-Systems. All Rights Reserved.