private static char encodeASCIIDigits(char c, char c1) { if (HighLevelEncoder.isDigit(c) && HighLevelEncoder.isDigit(c1)) { return (char) ((c - 48) * 10 + (c1 - 48) + 130); } else { throw new IllegalArgumentException( (new StringBuilder("not digits: ")).append(c).append(c1).toString()); } }
public final void encode(EncoderContext encodercontext) { if (HighLevelEncoder.determineConsecutiveDigitCount( encodercontext.getMessage(), encodercontext.pos) >= 2) { encodercontext.writeCodeword( encodeASCIIDigits( encodercontext.getMessage().charAt(encodercontext.pos), encodercontext.getMessage().charAt(encodercontext.pos + 1))); encodercontext.pos = encodercontext.pos + 2; return; } char c = encodercontext.getCurrentChar(); int i = HighLevelEncoder.lookAheadTest( encodercontext.getMessage(), encodercontext.pos, getEncodingMode()); if (i != getEncodingMode()) { switch (i) { default: throw new IllegalStateException( (new StringBuilder("Illegal mode: ")).append(i).toString()); case 5: // '\005' encodercontext.writeCodeword('\347'); encodercontext.signalEncoderChange(5); return; case 1: // '\001' encodercontext.writeCodeword('\346'); encodercontext.signalEncoderChange(1); return; case 3: // '\003' encodercontext.writeCodeword('\356'); encodercontext.signalEncoderChange(3); return; case 2: // '\002' encodercontext.writeCodeword('\357'); encodercontext.signalEncoderChange(2); return; case 4: // '\004' encodercontext.writeCodeword('\360'); encodercontext.signalEncoderChange(4); return; } } if (HighLevelEncoder.isExtendedASCII(c)) { encodercontext.writeCodeword('\353'); encodercontext.writeCodeword((char) ((c - 128) + 1)); encodercontext.pos = encodercontext.pos + 1; return; } else { encodercontext.writeCodeword((char) (c + 1)); encodercontext.pos = encodercontext.pos + 1; return; } }
@Override int encodeChar(char c, StringBuilder sb) { switch (c) { case '\r': sb.append('\0'); break; case '*': sb.append('\1'); break; case '>': sb.append('\2'); break; case ' ': sb.append('\3'); break; default: if (c >= '0' && c <= '9') { sb.append((char) (c - 48 + 4)); } else if (c >= 'A' && c <= 'Z') { sb.append((char) (c - 65 + 14)); } else { HighLevelEncoder.illegalCharacter(c); } break; } return 1; }
@Override int encodeChar(char c, StringBuilder sb) { if (c == '\r') { sb.append('\0'); } else if (c == '*') { sb.append('\1'); } else if (c == '>') { sb.append('\2'); } else if (c == ' ') { sb.append('\3'); } else if (c >= '0' && c <= '9') { sb.append((char) (c - 48 + 4)); } else if (c >= 'A' && c <= 'Z') { sb.append((char) (c - 65 + 14)); } else { HighLevelEncoder.illegalCharacter(c); } return 1; }
@Override public void encode(EncoderContext context) { // step C StringBuilder buffer = new StringBuilder(); while (context.hasMoreCharacters()) { char c = context.getCurrentChar(); context.pos++; encodeChar(c, buffer); int count = buffer.length(); if ((count % 3) == 0) { writeNextTriplet(context, buffer); int newMode = HighLevelEncoder.lookAheadTest(context.getMessage(), context.pos, getEncodingMode()); if (newMode != getEncodingMode()) { context.signalEncoderChange(newMode); break; } } } handleEOD(context, buffer); }