- java.lang.Object
-
- com.pervasive.datarush.operators.AbstractLogicalOperator
-
- com.pervasive.datarush.operators.CompositeOperator
-
- com.pervasive.datarush.operators.io.AbstractWriter
-
- com.pervasive.datarush.operators.io.textfile.AbstractTextWriter
-
- com.pervasive.datarush.operators.io.textfile.WriteFixedText
-
- All Implemented Interfaces:
LogicalOperator
,RecordSinkOperator
,SinkOperator<RecordPort>
public class WriteFixedText extends AbstractTextWriter
Writes a record dataflow as a text file of fixed-width records. The writer requires aFixedWidthTextRecord
to determine how field values are formatted. Fields are mapped by name; all fields defined in the schema must be present in the input (and vice-versa), although they need not be in the same order. The order of fields in the formatted record is determined by the order in the supplied schema. Records in the file are separated by a non-empty, user-defined character sequence.The record schema can be manually constructed via the API provided, although though this metadata is often persisted externally. Support for Pervasive DataIntegrator structured schema descriptors (.schema files) is provided with
StructuredSchemaReader
.
-
-
Field Summary
-
Fields inherited from class com.pervasive.datarush.operators.io.textfile.AbstractTextWriter
encodingProps
-
Fields inherited from class com.pervasive.datarush.operators.io.AbstractWriter
input, options
-
-
Constructor Summary
Constructors Constructor Description WriteFixedText()
Writes fixed text to an empty target with default settings.WriteFixedText(Path path, WriteMode mode)
Writes fixed text to the specified path in the given mode, using default settings.WriteFixedText(ByteSink target, WriteMode mode)
Writes text to the specified target sink in the given mode.WriteFixedText(String path, WriteMode mode)
Writes fixed text to the specified path in the given mode, using default settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DataFormat
computeFormat(CompositionContext ctx)
Determines the data format for the target.String
getRecordSeparator()
Get the record separator.FixedWidthTextRecord
getSchema()
Get the configured schema.void
setRecordSeparator(String separator)
Set the record separator.void
setSchema(FixedWidthTextRecord schema)
Set the schema to use for formatting output records.-
Methods inherited from class com.pervasive.datarush.operators.io.textfile.AbstractTextWriter
getCharset, getCharsetName, getEncodeBuffer, getEncoding, getErrorAction, getReplacement, setCharset, setCharsetName, setEncodeBuffer, setEncoding, setErrorAction, setReplacement
-
Methods inherited from class com.pervasive.datarush.operators.io.AbstractWriter
compose, getFormatOptions, getInput, getMode, getSaveMetadata, getTarget, getWriteBuffer, getWriteOnClient, getWriteSingleSink, isIgnoreSortOrder, setFormatOptions, setIgnoreSortOrder, setMode, setSaveMetadata, setTarget, setTarget, setTarget, setWriteBuffer, setWriteOnClient, setWriteSingleSink
-
Methods inherited from class com.pervasive.datarush.operators.AbstractLogicalOperator
disableParallelism, getInputPorts, getOutputPorts, newInput, newInput, newOutput, newRecordInput, newRecordInput, newRecordOutput, notifyError
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.pervasive.datarush.operators.LogicalOperator
disableParallelism, getInputPorts, getOutputPorts
-
-
-
-
Constructor Detail
-
WriteFixedText
public WriteFixedText()
Writes fixed text to an empty target with default settings. Note the target and schema must be set before execution or an error will be raised.
-
WriteFixedText
public WriteFixedText(String path, WriteMode mode)
Writes fixed text to the specified path in the given mode, using default settings.If the writer is parallelized, this is interpreted as a directory in which each partition will write a fragment of the entire input stream. Otherwise, it is interpreted as the file to write.
The schema must be set before execution or an error will be raised.
- Parameters:
path
- the path to writemode
- how to handle existing files- See Also:
setSchema(FixedWidthTextRecord)
-
WriteFixedText
public WriteFixedText(Path path, WriteMode mode)
Writes fixed text to the specified path in the given mode, using default settings.If the writer is parallelized, this is interpreted as a directory in which each partition will write a fragment of the entire input stream. Otherwise, it is interpreted as the file to write.
The schema must be set before execution or an error will be raised.
- Parameters:
path
- the path to writemode
- how to handle existing files- See Also:
setSchema(FixedWidthTextRecord)
-
WriteFixedText
public WriteFixedText(ByteSink target, WriteMode mode)
Writes text to the specified target sink in the given mode.The writer can only be parallelized if the sink is fragmentable. In this case, each partition will be written as an independent sink. Otherwise, the writer will run non-parallel.
The schema must be set before execution or an error will be raised.
- Parameters:
target
- the data sink to which to writemode
- how to handle an existing sink- See Also:
setSchema(FixedWidthTextRecord)
-
-
Method Detail
-
setRecordSeparator
public void setRecordSeparator(String separator)
Set the record separator. This string will be output at the end of each record written. The default value is the system dependent record separator.- Parameters:
separator
- text separating records
-
getRecordSeparator
public String getRecordSeparator()
Get the record separator.- Returns:
- record separator
-
setSchema
public void setSchema(FixedWidthTextRecord schema)
Set the schema to use for formatting output records. The schema is required. The schema defines the field names, types, positions, sizes and formatting specifications.- Parameters:
schema
- format of output records
-
getSchema
public FixedWidthTextRecord getSchema()
Get the configured schema.- Returns:
- schema
-
computeFormat
protected DataFormat computeFormat(CompositionContext ctx)
Description copied from class:AbstractWriter
Determines the data format for the target. The returned format is used during composition to construct aWriteSink
operator. If an implementation supports schema discovery, it must be performed in this method.- Specified by:
computeFormat
in classAbstractWriter
- Parameters:
ctx
- the composition context for the current invocation ofAbstractWriter.compose(CompositionContext)
- Returns:
- the target format to use
-
-