public String getCurrencyCodeAsString() throws ISOException { return ISOUtil.zeropad(Integer.toString(currencyCode),3); } public String getAmountAsLegacyString() throws ISOException {
public void dump (PrintStream p, String indent) { p.println (indent +"<"+XMLPackager.ISOFIELD_TAG + " " +XMLPackager.ID_ATTR +"=\"" +fieldNumber +"\" " +"currency=\"" +ISOUtil.zeropad (currencyCode, 3)+"\" " +XMLPackager.TYPE_ATTR +"=\"amount\" " +XMLPackager.VALUE_ATTR+"=\"" + amount.toString() +"\"/>" ); } public void writeExternal (ObjectOutput out) throws IOException {
public String getAmountAsLegacyString() throws ISOException { return ISOUtil.zeropad (amount.unscaledValue().toString(), 12); } public String getAmountAsString() throws ISOException {
public String getAmountAsString() throws ISOException { StringBuilder sb = new StringBuilder(16); sb.append (ISOUtil.zeropad (Integer.toString (currencyCode),3)); sb.append (Integer.toString(amount.scale() % 10)); sb.append (ISOUtil.zeropad (amount.unscaledValue().toString(), 12)); return sb.toString(); } public byte[] pack() throws ISOException {
/** * @param len the packed Message len * @exception IOException */ protected void sendMessageLength(int len) throws IOException { int maxLen= ten.pow(lengthDigits).intValue() - 1; // 10^lengthDigits - 1 if (len > maxLen) throw new IOException ("len exceeded ("+len+" > "+maxLen+")"); else if (len < 0) throw new IOException ("invalid negative length ("+len+")"); serverOut.write(ISOUtil.zeropad(len, lengthDigits).getBytes()); } /**
private static String hexOffset (int i) { i = i>>4 << 4; int w = i > 0xFFFF ? 8 : 4; try { return zeropad (Integer.toString (i, 16), w); } catch (ISOException e) { // should not happen return e.getMessage(); } }
public static Currency getCurrency(int code) throws ISOException { final String isoCode = ISOUtil.zeropad(Integer.toString(code), 3); return findCurrency(isoCode); }
public static Currency getCurrency(String code) throws ISOException { final String isoCode = ISOUtil.zeropad(code, 3); return findCurrency(isoCode); }
public String formatAmountForISOMsg(double amount) { try { double m = Math.pow(10, getDecimals()) * amount; return ISOUtil.zeropad(String.valueOf(Math.round(m)), 12); } catch (ISOException e) { throw new IllegalArgumentException("Failed to convert amount",e); } }
public static String toISO87String (BigDecimal amount, String currency) { try { Currency c = findCurrency(currency); return ISOUtil.zeropad(amount.movePointRight(c.getDecimals()).setScale(0).toPlainString(), 12); } catch (ISOException e) { throw new IllegalArgumentException("Failed to convert amount",e); } } public static BigDecimal parseFromISO87String (String isoamount, String currency) {
public static String getIsoCodeFromAlphaCode(String alphacode) throws IllegalArgumentException { try { Currency c = findCurrency(alphacode); return ISOUtil.zeropad(Integer.toString(c.getIsoCode()), 3); } catch (ISOException e) { throw new IllegalArgumentException("Failed getIsoCodeFromAlphaCode/ zeropad failed?", e); } }
/** * construct key to match request with responses * @param m request/response * @return key (default terminal(41) + tracenumber(11)) */ protected String getKey(ISOMsg m) throws ISOException { return (m.hasField(41)?ISOUtil.zeropad((String)m.getValue(41),16) : "") + (m.hasField (traceNumberField) ? ISOUtil.zeropad((String) m.getValue(traceNumberField),6) : Long.toString (System.currentTimeMillis())); }
protected String getKey (ISOMsg m) throws ISOException { return getFrom () + "." + (m.hasField(41)?ISOUtil.zeropad((String)m.getValue(41),16) : "") + (m.hasField (11) ? ISOUtil.zeropad((String) m.getValue(11),6) : Long.toString (System.currentTimeMillis())); } public void notify (Object k, Object value) {
protected void sendMessageLength(int len) throws IOException { try { serverOut.write ( ISOUtil.str2bcd ( ISOUtil.zeropad (Integer.toString (len), 4), true ) ); } catch (ISOException e) { Logger.log (new LogEvent (this, "send-message-length", e)); } } protected int getMessageLength() throws IOException, ISOException {
@Test(expected = NullPointerException.class) public void testZeropadThrowsNullPointerException() throws Throwable { ISOUtil.zeropad(null, 100); }
@Override public RC convert(IRC irc) { String s = cfg != null ? cfg.get(Long.toString(irc.irc()), null) : null; if (s != null) { return buildRC(s); } else if (rcs.containsKey(irc.irc())) return rcs.get(irc.irc()); s = irc.irc() > 9999 ? Long.toString(irc.irc()) : ISOUtil.zeropad(irc.irc(),4); return new SimpleRC(s, (irc instanceof CMF ? ((CMF)irc).name().replace("_", " ") : null)); }
public void run() { ISOUtil.sleep (250L); int active = server.getActiveConnections(); meter.setConnected(active > 0); try { meter.setPositiveCounter( ISOUtil.zeropad(Integer.toString(active), 6) ); } catch (ISOException e) { } meter.repaint(); } };
@Test public void testZeropad() throws Throwable { String result = ISOUtil.zeropad("testISOUtils", 100); assertEquals("result", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000testISOUtils", result); }
private ISOMsg createDummyRequest() { ISOMsg m = new ISOMsg("0800"); m.set(7, ISODate.getANSIDate(new Date())); m.set(11, ISOUtil.zeropad(++stan, 6)); m.set(70, "301"); return m; } }
@Test public void testZeropadThrowsISOException() throws Throwable { try { ISOUtil.zeropad("testISOUtils", 0); fail("Expected ISOException to be thrown"); } catch (ISOException ex) { assertEquals("ex.getMessage()", "invalid len 12/0", ex.getMessage()); assertNull("ex.nested", ex.nested); } }