001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso; 020 021/** 022 * Implements the Padder interface for padding strings and byte arrays on the 023 * Right. The difference between this and RightPadder is that this truncates the data 024 * during packing, instead of throwing an exception. 025 * 026 * @author jonathan.oconnor@xcom.de 027 * @version $Revision$ $Date$ 028 */ 029public class RightTPadder extends RightPadder 030{ 031 /** 032 * A padder for padding spaces on the right. This is very common in 033 * alphabetic fields. 034 */ 035 public static final RightTPadder SPACE_PADDER = new RightTPadder(' '); 036 037 /** 038 * Creates a Right Truncating Padder with a specific pad character. 039 * 040 * @param pad 041 * The padding character. For binary padders, the pad character 042 * is truncated to lower order byte. 043 */ 044 public RightTPadder(char pad) 045 { 046 super(pad); 047 } 048 049 /** 050 * @see org.jpos.iso.Padder#pad(java.lang.String, int) 051 */ 052 public String pad(String data, int maxLength) throws ISOException 053 { 054 if (data.length() > maxLength) 055 { 056 return super.pad(data.substring(0,maxLength), maxLength); 057 } else 058 { 059 return super.pad(data, maxLength); 060 } 061 } 062}