@Test public void testPadLengthTooShort() throws Exception { try { padder.pad("123", 2); fail("Padding a bigger string into a smaller buffer should throw an exception"); } catch (Exception asIExpected) { } }
public String pad(String data, int maxLength) throws ISOException { int len = data.length(); if (len < maxLength) { StringBuilder padded = new StringBuilder(maxLength); padded.append(data); for (; len < maxLength; len++) { padded.append(pad); } data = padded.toString(); } else if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } return data; }
RightPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { int len = data.length(); if (len < maxLength) { StringBuilder padded = new StringBuilder(maxLength); padded.append(data); for (; len < maxLength; len++) { padded.append(pad); } data = padded.toString(); } else if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } return data; } }
RightPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { int len = data.length(); if (len < maxLength) { StringBuilder padded = new StringBuilder(maxLength); padded.append(data); for (; len < maxLength; len++) { padded.append(pad); } data = padded.toString(); } else if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } return data; } RightPadder(char pad); }
RightPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { int len = data.length(); if (len < maxLength) { StringBuilder padded = new StringBuilder(maxLength); padded.append(data); for (; len < maxLength; len++) { padded.append(pad); } data = padded.toString(); } else if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } return data; } RightPadder(char pad); String pad(String data, int maxLength); String unpad(String paddedData); }
RightPadder implements Padder { public String pad(String data, int maxLength) throws ISOException { int len = data.length(); if (len < maxLength) { StringBuilder padded = new StringBuilder(maxLength); padded.append(data); for (; len < maxLength; len++) { padded.append(pad); } data = padded.toString(); } else if (len > maxLength) { throw new ISOException("Data is too long. Max = " + maxLength); } return data; } RightPadder(char pad); String pad(String data, int maxLength); String unpad(String paddedData); static final RightPadder SPACE_PADDER; }