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 021import java.io.IOException; 022import java.io.InputStream; 023 024/** 025 * Core interface for ISO-8583 packagers; responsible for packing and unpacking {@link org.jpos.iso.ISOMsg} instances. 026 * @author apr 027 * @version $Id$ 028 * @see ISOComponent 029 */ 030public interface ISOPackager { 031 /** 032 * Packs an ISO-8583 message into a byte array. 033 * @param m the Component to pack 034 * @return Message image 035 * @exception ISOException on packing error 036 */ 037 byte[] pack(ISOComponent m) throws ISOException; 038 039 /** 040 * Unpacks an ISO-8583 byte array into the given message container. 041 * @param m the Container of this message 042 * @param b ISO message image 043 * @return consumed bytes 044 * @exception ISOException on unpacking error 045 */ 046 int unpack(ISOComponent m, byte[] b) throws ISOException; 047 048 /** 049 * Unpacks an ISO-8583 message from an input stream into the given container. 050 * @param m the container 051 * @param in the input stream 052 * @throws IOException on I/O failure 053 * @throws ISOException on unpacking error 054 */ 055 void unpack(ISOComponent m, InputStream in) throws IOException, ISOException; 056 057 /** 058 * Returns a human-readable description of this packager. 059 * @return Packager's Description 060 */ 061 String getDescription(); 062 063 /** 064 * Emits a description of the field identified by {@code fldno} in the given message to the log event. 065 * @param m the Container (i.e. an ISOMsg) 066 * @param fldNumber the Field Number 067 * @return Field Description 068 */ 069 String getFieldDescription(ISOComponent m, int fldNumber); 070 071 /** 072 * Creates and returns a new ISOMsg instance appropriate for this packager. 073 * @return a new ISOMsg 074 */ 075 ISOMsg createISOMsg(); 076} 077