de.esprit.appsuite.io

## Class DataWriter<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.DataWriter<C>

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

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

  This writer may be run asynchronously within an `AsyncTask`. It provides a safe execution frame which opens and closes the out-stream on each `executeAsync()` and implements the methods of `PrintWriter` for convenience.
  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
    `DataWriter(C ctx, java.io.File outFile)`
    `DataWriter(C ctx, LogChannel logCh, java.io.File outFile)`
    `DataWriter(C ctx, LogChannel logCh, java.io.File outFile, java.lang.String taskName)`
    `DataWriter(C ctx, LogChannel logCh, java.io.OutputStream outStream)`
    `DataWriter(C ctx, LogChannel logCh, java.io.OutputStream outStream, java.lang.String taskName)`
    `DataWriter(C ctx, java.io.OutputStream outStream)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `protected java.io.FileOutputStream` | `createFileOutputStream(java.io.File outputFile)`
    `void` | `executeAsync()` Contains the code to be executed asynchronously.
    `void` | `flush()`
    `java.io.PrintWriter` | `format(java.util.Locale l, java.lang.String format, java.lang.Object... args)`
    `java.io.PrintWriter` | `format(java.lang.String format, java.lang.Object... args)`
    `java.lang.String` | `getEncoding()`
    `java.io.File` | `getOutputFile()`
    `long` | `getWriteDuration()`
    `java.io.PrintWriter` | `getWriter()`
    `protected java.io.PrintWriter` | `openStream()`
    `protected abstract void` | `performWrite()` Needs to be overridden to actually write data.
    `void` | `print(boolean b)`
    `void` | `print(char c)`
    `void` | `print(char[] s)`
    `void` | `print(double d)`
    `void` | `print(float f)`
    `void` | `print(int i)`
    `void` | `print(long l)`
    `void` | `print(java.lang.Object obj)`
    `void` | `print(java.lang.String s)`
    `java.io.PrintWriter` | `printf(java.util.Locale l, java.lang.String format, java.lang.Object... args)`
    `java.io.PrintWriter` | `printf(java.lang.String format, java.lang.Object... args)`
    `void` | `printLine(java.lang.String format, java.lang.Object... args)` print formatted data to writer by using Locale.US and appending a system dependant NewLine
    `void` | `println()`
    `void` | `println(boolean x)`
    `void` | `println(char x)`
    `void` | `println(char[] x)`
    `void` | `println(double x)`
    `void` | `println(float x)`
    `void` | `println(int x)`
    `void` | `println(long x)`
    `void` | `println(java.lang.Object x)`
    `void` | `println(java.lang.String x)`
    `void` | `setCloseStreamWhenFinished(boolean needsToClose)`
    `void` | `setEncoding(java.lang.String encoding)` Sets the encoding used by the underlying writer.
    `void` | `setOutputFile(java.io.File outputFile)`
    `void` | `setOutputStream(java.io.OutputStream outputStream)` Allows for setting a new outputStream for writing data to.
    `void` | `write(char c)`
    `void` | `write(char[] buf)`
    `void` | `write(char[] buf, int off, int len)`
    `void` | `write(java.lang.String str)`
    `void` | `write(java.lang.String str, int off, int len)`

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

    - #### DataWriter

          public DataWriter(C ctx,
                    java.io.File outFile)

    - #### DataWriter

          public DataWriter(C ctx,
                    LogChannel logCh,
                    java.io.File outFile)

    - #### DataWriter

          public DataWriter(C ctx,
                    LogChannel logCh,
                    java.io.File outFile,
                    java.lang.String taskName)

    - #### DataWriter

          public DataWriter(C ctx,
                    java.io.OutputStream outStream)

    - #### DataWriter

          public DataWriter(C ctx,
                    LogChannel logCh,
                    java.io.OutputStream outStream)

    - #### DataWriter

          public DataWriter(C ctx,
                    LogChannel logCh,
                    java.io.OutputStream outStream,
                    java.lang.String taskName)

  - ### Method Detail

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

    - #### getWriteDuration

          public final long getWriteDuration()

    - #### setCloseStreamWhenFinished

          public void setCloseStreamWhenFinished(boolean needsToClose)

    - #### close

          public void close()
                     throws java.io.IOException

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

    - #### openStream

          protected java.io.PrintWriter openStream()
                                            throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### createFileOutputStream

          protected java.io.FileOutputStream createFileOutputStream(java.io.File outputFile)
                                                             throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### setOutputStream

          public void setOutputStream(java.io.OutputStream outputStream)

      Allows for setting a new outputStream for writing data to. Note that this instance can only once be executed per stream.

    - #### setEncoding

          public void setEncoding(java.lang.String encoding)

      Sets the encoding used by the underlying writer. Maybe null for using the default encoding.

    - #### getEncoding

          public java.lang.String getEncoding()

    - #### performWrite

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

      Needs to be overridden to actually write data.
      Throws:
        `java.lang.Exception`

    - #### printLine

          public void printLine(java.lang.String format,
                       java.lang.Object... args)

      print formatted data to writer by using Locale.US and appending a system dependant NewLine

    - #### getOutputFile

          public java.io.File getOutputFile()

    - #### setOutputFile

          public void setOutputFile(java.io.File outputFile)

    - #### getWriter

          public java.io.PrintWriter getWriter()

    - #### write

          public void write(char c)

    - #### write

          public void write(char[] buf)

    - #### write

          public void write(char[] buf,
                   int off,
                   int len)

    - #### write

          public void write(java.lang.String str,
                   int off,
                   int len)

    - #### write

          public void write(java.lang.String str)

    - #### format

          public java.io.PrintWriter format(java.util.Locale l,
                                   java.lang.String format,
                                   java.lang.Object... args)

    - #### format

          public java.io.PrintWriter format(java.lang.String format,
                                   java.lang.Object... args)

    - #### print

          public void print(boolean b)

    - #### print

          public void print(char c)

    - #### print

          public void print(char[] s)

    - #### print

          public void print(double d)

    - #### print

          public void print(float f)

    - #### print

          public void print(int i)

    - #### print

          public void print(long l)

    - #### print

          public void print(java.lang.Object obj)

    - #### print

          public void print(java.lang.String s)

    - #### printf

          public java.io.PrintWriter printf(java.util.Locale l,
                                   java.lang.String format,
                                   java.lang.Object... args)

    - #### printf

          public java.io.PrintWriter printf(java.lang.String format,
                                   java.lang.Object... args)

    - #### println

          public void println()

    - #### println

          public void println(boolean x)

    - #### println

          public void println(char x)

    - #### println

          public void println(char[] x)

    - #### println

          public void println(double x)

    - #### println

          public void println(float x)

    - #### println

          public void println(int x)

    - #### println

          public void println(long x)

    - #### println

          public void println(java.lang.Object x)

    - #### println

          public void println(java.lang.String x)

    - #### flush

          public void flush()

Copyright © 2014 EsprIT-Systems. All Rights Reserved.