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

com.univocity.parsers.fixed.FixedWidthFormat 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.fixed;

import com.univocity.parsers.common.*;

import java.util.*;

/**
 * The Fixed-Width format configuration. In addition to the default configuration in {@link Format}, the fixed-width format defines:
 *
 * 
    *
  • padding (defaults to ' '): the character used for filling unwritten spaces in a fixed-width record. *

    e.g. if a field has a length of 5 characters, but the value is 'ZZ', the field should contain [ZZ ] (i.e. ZZ followed by 3 unwritten spaces). *
    If the padding is set to '_', then the field will be written as [ZZ___]

  • *
* * @author uniVocity Software Pty Ltd - [email protected] * @see com.univocity.parsers.common.Format */ public class FixedWidthFormat extends Format { private char padding = ' '; private char lookupWildcard = '?'; /** * Returns the padding character used to represent unwritten spaces. Defaults to ' ' * * @return the padding character */ public char getPadding() { return padding; } /** * Defines the padding character used to represent unwritten spaces. Defaults to ' ' * * @param padding the padding character */ public void setPadding(char padding) { this.padding = padding; } /** * Identifies whether or not a given character represents a padding character * * @param padding the character to be verified * * @return true if the given character is the padding character, false otherwise */ public boolean isPadding(char padding) { return this.padding == padding; } @Override protected TreeMap getConfiguration() { TreeMap out = new TreeMap(); out.put("Padding", padding); return out; } @Override public final FixedWidthFormat clone() { return (FixedWidthFormat) super.clone(); } /** * Returns the lookup wildcard character to accept any character in look-ahead or look-behind patterns defined * using {@link FixedWidthParserSettings#addFormatForLookahead(String, FixedWidthFields)} or * {@link FixedWidthParserSettings#addFormatForLookbehind(String, FixedWidthFields)}. * * Defaults to {@code '?'} * * @return the wildcard character to be used in lookahead/behind patterns. */ public char getLookupWildcard() { return lookupWildcard; } /** * Defines the lookup wildcard character to accept any character in look-ahead or look-behind patterns defined * using {@link FixedWidthParserSettings#addFormatForLookahead(String, FixedWidthFields)} or * {@link FixedWidthParserSettings#addFormatForLookbehind(String, FixedWidthFields)}. * * Defaults to {@code '?'} * * @param lookupWildcard the wildcard character to be used in lookahead/behind patterns. */ public void setLookupWildcard(char lookupWildcard) { this.lookupWildcard = lookupWildcard; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy