/* * Created on Mar 30, 2005 * * MNP [project testopiv] * Copyright (c) 2005 * * @author Giovanni Amici * @version 1.0 */ package test; /** * @author Giovanni * * Window - Preferences - Java - Code Style - Code Templates */ import java.io.RandomAccessFile; public class Sender { public static final String xml = "" + "TIMG" + "2005-06-25" + "14:30:00" + "OPIV" + "00001" + "" + "1TIMGOPIV0000000000000000018832800000010000000000000000001SRTMCC75C52A345QPRPD2100-01-01ANTONELLAAMICIPAAQ5633392Z000000000000001" + ""; public Sender() { } public static void main(String args[]) { try { System.out.println("Inizio test invio..nuovo"); if (args.length > 0) { sendFile(args[0]); } else { simpleSend(); } System.out.println("Test invio completato con successo!!"); } catch (Exception e) { System.out.println("Errore test invio:"); e.printStackTrace(); } } public static void simpleSend() throws Exception { test.XMLSender.sendXML(xml, "1", "TIMG20050330122748OPIV00001", "OPIV"); } public static void sendFile(String fileName) throws Exception { RandomAccessFile in = null; try { in = new RandomAccessFile(fileName, "r"); long len = in.length(); byte[] arr = new byte[(int) len]; in.readFully(arr); String xml = new String(arr).trim(); System.out.println("I:" + fileName.lastIndexOf('/') + " F:" + fileName.lastIndexOf('.')); String name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.')); String cod_olo = name.substring(18, 22); System.out.println("***********************************"); System.out.println("Sending:"); System.out.println("XML: <" + xml + ">"); System.out.println("TYPE: <1>"); System.out.println("NAME: <" + name + ">"); System.out.println("OLO: <" + cod_olo + ">"); test.XMLSender.sendXML(xml, "1", name, cod_olo); System.out.println("Sending.. END"); System.out.println("***********************************"); } catch (Exception ex) { System.out.println("Exception:"); ex.printStackTrace(); throw ex; } finally { try { if (in != null) in.close(); } catch (Exception ex) { ex.printStackTrace(); } } } }