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.packager; 020 021import org.jpos.iso.ISOBitMapPackager; 022import org.jpos.iso.ISOComponent; 023import org.jpos.iso.ISOException; 024import org.jpos.iso.ISOUtil; 025 026import java.util.BitSet; 027 028/** 029 * ISOFieldPackager Binary Bitmap 030 * 031 * @author <a href="mailto:eoin.flood@orbiscom.com">Eoin Flood</a> 032 * @version $Id$ 033 * @see ISOComponent 034 * @see ISOBitMapPackager 035 */ 036public class Base1_BITMAP126 extends ISOBitMapPackager 037{ 038 public Base1_BITMAP126() 039 { 040 super(); 041 } 042 /** 043 * @param len - field len 044 * @param description symbolic descrption 045 */ 046 public Base1_BITMAP126(int len, String description) 047 { 048 super(len, description); 049 } 050 /** 051 * @param c - a component 052 * @return packed component 053 * @exception ISOException 054 */ 055 public byte[] pack (ISOComponent c) throws ISOException 056 { 057 return ISOUtil.bitSet2byte ((BitSet) c.getValue()); 058 } 059 /** 060 * @param c - the Component to unpack 061 * @param b - binary image 062 * @param offset - starting offset within the binary image 063 * @return consumed bytes 064 * @exception ISOException 065 */ 066 public int unpack (ISOComponent c, byte[] b, int offset) throws ISOException 067 { 068 int len; 069 // 070 // For this type of Bitmap bit0 does not mean 071 // that there is a secondary bitmap to follow 072 // It simply means that field 1 is present 073 // The standard IFB_BITMAP class assumes that 074 // bit0 always means extended bitmap 075 // 076 BitSet bmap = ISOUtil.byte2BitSet (b, offset, false); // False => no extended bitmap 077 078 c.setValue(bmap); 079 len = (len=bmap.size()) > 128 ? 128 : len; 080 return len >> 3; 081 } 082 public int getMaxPackedLength() 083 { 084 return getLength() >> 3; 085 } 086}