All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.univocity.parsers.common.processor.ObjectRowWriterProcessor Maven / Gradle / Ivy

Go to download

univocity's open source parsers for processing different text formats using a consistent API

There is a newer version: 2.9.1
Show newest version
/*******************************************************************************
 * Copyright 2014 uniVocity Software Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.univocity.parsers.common.processor;

import com.univocity.parsers.common.*;
import com.univocity.parsers.conversions.*;

/**
 *
 * A {@link RowWriterProcessor} implementation for executing conversion sequences in object arrays before for writing them using any implementation of {@link AbstractWriter}.
 *
 * @see AbstractWriter
 * @see RowWriterProcessor
 *
 * @author uniVocity Software Pty Ltd - [email protected]
 *
 */
public class ObjectRowWriterProcessor extends ConversionProcessor implements RowWriterProcessor {

	/**
	 * Executes the sequences of conversions defined using {@link ConversionProcessor#convertFields(Conversion...)}, {@link ConversionProcessor#convertIndexes(Conversion...)} and {@link ConversionProcessor#convertAll(Conversion...)}, for every field in the given row.
	 *
	 * 

Each field will be transformed using the {@link Conversion#execute(Object)} method. *

In general the conversions will process a String and convert it to some object value (such as booleans, dates, etc). * * @param input the object array that represents a record with its individual fields. * @param headers All field names used to produce records in a given destination. May be null if no headers have been defined in {@link CommonSettings#getHeaders()} * @param indexesToWrite The indexes of the headers that are actually being written. May be null if no fields have been selected using {@link CommonSettings#selectFields(String...)} or {@link CommonSettings#selectIndexes(Integer...)} * @return an row of Object instances containing the values obtained after the execution of all conversions. *

Fields that do not have any conversion defined will just be copied to the object array into their original positions. */ @Override public Object[] write(Object[] input, String[] headers, int[] indexesToWrite) { if (input == null) { return null; } Object[] output = new Object[input.length]; System.arraycopy(input, 0, output, 0, input.length); reverseConversions(false, output, headers, indexesToWrite); return output; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy