com.univocity.api.common
Class StringWriterProvider

java.lang.Object
  extended by com.univocity.api.common.WriterProvider
      extended by com.univocity.api.common.StringWriterProvider
All Implemented Interfaces:
ResourceProvider<Writer>

public final class StringWriterProvider
extends WriterProvider

A WriterProvider for Strings. Use this to write data directly to a String. This is just a convenience class that you can use to write test cases without having to deal with files or other persistent resources.

Author:
uniVocity Software Pty Ltd - dev@univocity.com

Constructor Summary
StringWriterProvider()
           
 
Method Summary
 void clearDestination()
          Clears the contents written to the string so far
 Writer getResource()
          Obtains a new StringWriter instance.
 String getString()
          Returns the contents written to the string so far.
 boolean isEmpty()
          Queries whether or not the resource to be written contains records already.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringWriterProvider

public StringWriterProvider()
Method Detail

getResource

public final Writer getResource()
Obtains a new StringWriter instance.

Returns:
a new StringWriter

clearDestination

public final void clearDestination()
Clears the contents written to the string so far

Specified by:
clearDestination in class WriterProvider

getString

public final String getString()
Returns the contents written to the string so far.

Returns:
the contents written to the string so far.

isEmpty

public final boolean isEmpty()
Description copied from class: WriterProvider
Queries whether or not the resource to be written contains records already. This is used only for determining whether or not uniVocity should write a row with headers for each column in case the underlying resource is empty, and the entity is configured to write its headers to the output. Considering the entity is configured to write its headers to the output, the isEmpty() method will be queried and: If WriterProvider.clearDestination() was invoked in the same transaction, uniVocity will know the entity is empty and will then attempt to write the header row. However, as it cannot determine whether the output has data already written in it; Mappings where WriterProvider.clearDestination() is not used might produce outputs without the header row. This is likely to occur in write-only entities with no initial data.

Specified by:
isEmpty in class WriterProvider
Returns:
a flag indicating whether or not the underlying resource contains records.


Copyright © 2015 uniVocity Software Pty Ltd. All rights reserved.