1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45:
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61: import ;
62: import ;
63: import ;
64: import ;
65:
66:
77: public class FTPConnection
78: {
79:
80:
83: public static final int FTP_PORT = 21;
84:
85:
88: public static final int FTP_DATA_PORT = 20;
89:
90:
91: protected static final String USER = "USER";
92: protected static final String PASS = "PASS";
93: protected static final String ACCT = "ACCT";
94: protected static final String CWD = "CWD";
95: protected static final String CDUP = "CDUP";
96: protected static final String SMNT = "SMNT";
97: protected static final String REIN = "REIN";
98: protected static final String QUIT = "QUIT";
99:
100: protected static final String PORT = "PORT";
101: protected static final String PASV = "PASV";
102: protected static final String TYPE = "TYPE";
103: protected static final String STRU = "STRU";
104: protected static final String MODE = "MODE";
105:
106: protected static final String RETR = "RETR";
107: protected static final String STOR = "STOR";
108: protected static final String STOU = "STOU";
109: protected static final String APPE = "APPE";
110: protected static final String ALLO = "ALLO";
111: protected static final String REST = "REST";
112: protected static final String RNFR = "RNFR";
113: protected static final String RNTO = "RNTO";
114: protected static final String ABOR = "ABOR";
115: protected static final String DELE = "DELE";
116: protected static final String RMD = "RMD";
117: protected static final String MKD = "MKD";
118: protected static final String PWD = "PWD";
119: protected static final String LIST = "LIST";
120: protected static final String NLST = "NLST";
121: protected static final String SITE = "SITE";
122: protected static final String SYST = "SYST";
123: protected static final String STAT = "STAT";
124: protected static final String HELP = "HELP";
125: protected static final String NOOP = "NOOP";
126:
127: protected static final String AUTH = "AUTH";
128: protected static final String PBSZ = "PBSZ";
129: protected static final String PROT = "PROT";
130: protected static final String CCC = "CCC";
131: protected static final String TLS = "TLS";
132:
133: public static final int TYPE_ASCII = 1;
134: public static final int TYPE_EBCDIC = 2;
135: public static final int TYPE_BINARY = 3;
136:
137: public static final int STRUCTURE_FILE = 1;
138: public static final int STRUCTURE_RECORD = 2;
139: public static final int STRUCTURE_PAGE = 3;
140:
141: public static final int MODE_STREAM = 1;
142: public static final int MODE_BLOCK = 2;
143: public static final int MODE_COMPRESSED = 3;
144:
145:
146: private static final String US_ASCII = "US-ASCII";
147:
148:
151: protected Socket socket;
152:
153:
156: protected LineInputStream in;
157:
158:
161: protected CRLFOutputStream out;
162:
163:
166: protected int connectionTimeout;
167:
168:
171: protected int timeout;
172:
173:
176: protected boolean debug;
177:
178:
181: protected DTP dtp;
182:
183:
186: protected int representationType = TYPE_ASCII;
187:
188:
191: protected int fileStructure = STRUCTURE_FILE;
192:
193:
196: protected int transferMode = MODE_STREAM;
197:
198:
201: protected boolean passive = false;
202:
203:
207: public FTPConnection(String hostname)
208: throws UnknownHostException, IOException
209: {
210: this(hostname, -1, 0, 0, false);
211: }
212:
213:
218: public FTPConnection(String hostname, int port)
219: throws UnknownHostException, IOException
220: {
221: this(hostname, port, 0, 0, false);
222: }
223:
224:
232: public FTPConnection(String hostname, int port,
233: int connectionTimeout, int timeout, boolean debug)
234: throws UnknownHostException, IOException
235: {
236: this.connectionTimeout = connectionTimeout;
237: this.timeout = timeout;
238: this.debug = debug;
239: if (port <= 0)
240: {
241: port = FTP_PORT;
242: }
243:
244:
245: socket = new Socket();
246: InetSocketAddress address = new InetSocketAddress(hostname, port);
247: if (connectionTimeout > 0)
248: {
249: socket.connect(address, connectionTimeout);
250: }
251: else
252: {
253: socket.connect(address);
254: }
255: if (timeout > 0)
256: {
257: socket.setSoTimeout(timeout);
258: }
259:
260: InputStream in = socket.getInputStream();
261: in = new BufferedInputStream(in);
262: in = new CRLFInputStream(in);
263: this.in = new LineInputStream(in);
264: OutputStream out = socket.getOutputStream();
265: out = new BufferedOutputStream(out);
266: this.out = new CRLFOutputStream(out);
267:
268:
269: FTPResponse response = getResponse();
270: switch (response.getCode())
271: {
272: case 220:
273: break;
274: default:
275: throw new FTPException(response);
276: }
277: }
278:
279:
287: public boolean authenticate(String username, String password)
288: throws IOException
289: {
290: String cmd = USER + ' ' + username;
291: send(cmd);
292: FTPResponse response = getResponse();
293: switch (response.getCode())
294: {
295: case 230:
296: return true;
297: case 331:
298: break;
299: case 332:
300: case 530:
301: return false;
302: default:
303: throw new FTPException(response);
304: }
305: cmd = PASS + ' ' + password;
306: send(cmd);
307: response = getResponse();
308: switch (response.getCode())
309: {
310: case 230:
311: case 202:
312: return true;
313: case 332:
314: case 530:
315: return false;
316: default:
317: throw new FTPException(response);
318: }
319: }
320:
321:
327: public boolean starttls(boolean confidential)
328: throws IOException
329: {
330: return starttls(confidential, new EmptyX509TrustManager());
331: }
332:
333:
340: public boolean starttls(boolean confidential, TrustManager tm)
341: throws IOException
342: {
343: try
344: {
345:
346:
347: SSLContext context = SSLContext.getInstance("TLS");
348:
349: TrustManager[] trust = new TrustManager[] { tm };
350: context.init(null, trust, null);
351: SSLSocketFactory factory = context.getSocketFactory();
352:
353: send(AUTH + ' ' + TLS);
354: FTPResponse response = getResponse();
355: switch (response.getCode())
356: {
357: case 500:
358: case 502:
359: case 504:
360: case 534:
361: case 431:
362: return false;
363: case 234:
364: break;
365: default:
366: throw new FTPException(response);
367: }
368:
369: String hostname = socket.getInetAddress().getHostName();
370: int port = socket.getPort();
371: SSLSocket ss =
372: (SSLSocket) factory.createSocket(socket, hostname, port, true);
373: String[] protocols = { "TLSv1", "SSLv3" };
374: ss.setEnabledProtocols(protocols);
375: ss.setUseClientMode(true);
376: ss.startHandshake();
377:
378:
379: send(PBSZ + ' ' + Integer.MAX_VALUE);
380: response = getResponse();
381: switch (response.getCode())
382: {
383: case 501:
384: case 503:
385: return false;
386: case 200:
387: break;
388: default:
389: throw new FTPException(response);
390: }
391: send(PROT + ' ' +(confidential ? 'P' : 'C'));
392: response = getResponse();
393: switch (response.getCode())
394: {
395: case 503:
396: case 504:
397: case 536:
398: return false;
399: case 200:
400: break;
401: default:
402: throw new FTPException(response);
403: }
404:
405: if (confidential)
406: {
407:
408: InputStream in = ss.getInputStream();
409: in = new BufferedInputStream(in);
410: in = new CRLFInputStream(in);
411: this.in = new LineInputStream(in);
412: OutputStream out = ss.getOutputStream();
413: out = new BufferedOutputStream(out);
414: this.out = new CRLFOutputStream(out);
415: }
416: return true;
417: }
418: catch (GeneralSecurityException e)
419: {
420: return false;
421: }
422: }
423:
424:
429: public boolean changeWorkingDirectory(String path)
430: throws IOException
431: {
432:
433: if (path.length() == 0)
434: return true;
435: String cmd = CWD + ' ' + path;
436: send(cmd);
437: FTPResponse response = getResponse();
438: switch (response.getCode())
439: {
440: case 250:
441: return true;
442: case 550:
443: return false;
444: default:
445: throw new FTPException(response);
446: }
447: }
448:
449:
453: public boolean changeToParentDirectory()
454: throws IOException
455: {
456: send(CDUP);
457: FTPResponse response = getResponse();
458: switch (response.getCode())
459: {
460: case 250:
461: return true;
462: case 550:
463: return false;
464: default:
465: throw new FTPException(response);
466: }
467: }
468:
469:
474: public void reinitialize()
475: throws IOException
476: {
477: send(REIN);
478: FTPResponse response = getResponse();
479: switch (response.getCode())
480: {
481: case 220:
482: if (dtp != null)
483: {
484: dtp.complete();
485: dtp = null;
486: }
487: break;
488: default:
489: throw new FTPException(response);
490: }
491: }
492:
493:
498: public void logout()
499: throws IOException
500: {
501: send(QUIT);
502: try
503: {
504: getResponse();
505: }
506: catch (IOException e)
507: {
508: }
509: if (dtp != null)
510: {
511: dtp.complete();
512: dtp = null;
513: }
514: try
515: {
516: socket.close();
517: }
518: catch (IOException e)
519: {
520: }
521: }
522:
523:
526: protected void initialiseDTP()
527: throws IOException
528: {
529: if (dtp != null)
530: {
531: dtp.complete();
532: dtp = null;
533: }
534:
535: InetAddress localhost = socket.getLocalAddress();
536: if (passive)
537: {
538: send(PASV);
539: FTPResponse response = getResponse();
540: switch (response.getCode())
541: {
542: case 227:
543: String message = response.getMessage();
544: try
545: {
546: int start = message.indexOf(',');
547: char c = message.charAt(start - 1);
548: while (c >= 0x30 && c <= 0x39)
549: {
550: c = message.charAt((--start) - 1);
551: }
552: int mid1 = start;
553: for (int i = 0; i < 4; i++)
554: {
555: mid1 = message.indexOf(',', mid1 + 1);
556: }
557: int mid2 = message.indexOf(',', mid1 + 1);
558: if (mid1 == -1 || mid2 < mid1)
559: {
560: throw new ProtocolException("Malformed 227: " +
561: message);
562: }
563: int end = mid2;
564: c = message.charAt(end + 1);
565: while (c >= 0x30 && c <= 0x39)
566: {
567: c = message.charAt((++end) + 1);
568: }
569:
570: String address =
571: message.substring(start, mid1).replace(',', '.');
572: int port_hi =
573: Integer.parseInt(message.substring(mid1 + 1, mid2));
574: int port_lo =
575: Integer.parseInt(message.substring(mid2 + 1, end + 1));
576: int port = (port_hi << 8) | port_lo;
577:
578:
580: dtp = new PassiveModeDTP(address, port, localhost,
581: connectionTimeout, timeout);
582: break;
583: }
584: catch (ArrayIndexOutOfBoundsException e)
585: {
586: throw new ProtocolException(e.getMessage() + ": " +
587: message);
588: }
589: catch (NumberFormatException e)
590: {
591: throw new ProtocolException(e.getMessage() + ": " +
592: message);
593: }
594: default:
595: throw new FTPException(response);
596: }
597: }
598: else
599: {
600:
601: int port = socket.getLocalPort() + 1;
602: int tries = 0;
603:
604: while (dtp == null)
605: {
606: try
607: {
608: dtp = new ActiveModeDTP(localhost, port,
609: connectionTimeout, timeout);
610:
611: }
612: catch (BindException e)
613: {
614: port++;
615: tries++;
616: if (tries > 9)
617: {
618: throw e;
619: }
620: }
621: }
622:
623:
624: StringBuffer buf = new StringBuffer(PORT);
625: buf.append(' ');
626:
627: byte[] address = localhost.getAddress();
628: for (int i = 0; i < address.length; i++)
629: {
630: int a =(int) address[i];
631: if (a < 0)
632: {
633: a += 0x100;
634: }
635: buf.append(a);
636: buf.append(',');
637: }
638: int port_hi =(port & 0xff00) >> 8;
639: int port_lo =(port & 0x00ff);
640: buf.append(port_hi);
641: buf.append(',');
642: buf.append(port_lo);
643: send(buf.toString());
644:
645: FTPResponse response = getResponse();
646: switch (response.getCode())
647: {
648: case 200:
649: break;
650: default:
651: dtp.abort();
652: dtp = null;
653: throw new FTPException(response);
654: }
655: }
656: dtp.setTransferMode(transferMode);
657: }
658:
659:
663: public void setPassive(boolean flag)
664: throws IOException
665: {
666: if (passive != flag)
667: {
668: passive = flag;
669: initialiseDTP();
670: }
671: }
672:
673:
677: public int getRepresentationType()
678: {
679: return representationType;
680: }
681:
682:
686: public void setRepresentationType(int type)
687: throws IOException
688: {
689: StringBuffer buf = new StringBuffer(TYPE);
690: buf.append(' ');
691: switch (type)
692: {
693: case TYPE_ASCII:
694: buf.append('A');
695: break;
696: case TYPE_EBCDIC:
697: buf.append('E');
698: break;
699: case TYPE_BINARY:
700: buf.append('I');
701: break;
702: default:
703: throw new IllegalArgumentException(Integer.toString(type));
704: }
705:
706:
707: send(buf.toString());
708: FTPResponse response = getResponse();
709: switch (response.getCode())
710: {
711: case 200:
712: representationType = type;
713: break;
714: default:
715: throw new FTPException(response);
716: }
717: }
718:
719:
723: public int getFileStructure()
724: {
725: return fileStructure;
726: }
727:
728:
732: public void setFileStructure(int structure)
733: throws IOException
734: {
735: StringBuffer buf = new StringBuffer(STRU);
736: buf.append(' ');
737: switch (structure)
738: {
739: case STRUCTURE_FILE:
740: buf.append('F');
741: break;
742: case STRUCTURE_RECORD:
743: buf.append('R');
744: break;
745: case STRUCTURE_PAGE:
746: buf.append('P');
747: break;
748: default:
749: throw new IllegalArgumentException(Integer.toString(structure));
750: }
751: send(buf.toString());
752: FTPResponse response = getResponse();
753: switch (response.getCode())
754: {
755: case 200:
756: fileStructure = structure;
757: break;
758: default:
759: throw new FTPException(response);
760: }
761: }
762:
763:
767: public int getTransferMode()
768: {
769: return transferMode;
770: }
771:
772:
776: public void setTransferMode(int mode)
777: throws IOException
778: {
779: StringBuffer buf = new StringBuffer(MODE);
780: buf.append(' ');
781: switch (mode)
782: {
783: case MODE_STREAM:
784: buf.append('S');
785: break;
786: case MODE_BLOCK:
787: buf.append('B');
788: break;
789: case MODE_COMPRESSED:
790: buf.append('C');
791: break;
792: default:
793: throw new IllegalArgumentException(Integer.toString(mode));
794: }
795: send(buf.toString());
796: FTPResponse response = getResponse();
797: switch (response.getCode())
798: {
799: case 200:
800: transferMode = mode;
801: if (dtp != null)
802: {
803: dtp.setTransferMode(mode);
804: }
805: break;
806: default:
807: throw new FTPException(response);
808: }
809: }
810:
811:
816: public InputStream retrieve(String filename)
817: throws IOException
818: {
819: if (dtp == null || transferMode == MODE_STREAM)
820: {
821: initialiseDTP();
822: }
823:
838: String cmd = RETR + ' ' + filename;
839: send(cmd);
840: FTPResponse response = getResponse();
841: switch (response.getCode())
842: {
843: case 125:
844: case 150:
845: return dtp.getInputStream();
846: default:
847: throw new FTPException(response);
848: }
849: }
850:
851:
858: public OutputStream store(String filename)
859: throws IOException
860: {
861: if (dtp == null || transferMode == MODE_STREAM)
862: {
863: initialiseDTP();
864: }
865: String cmd = STOR + ' ' + filename;
866: send(cmd);
867: FTPResponse response = getResponse();
868: switch (response.getCode())
869: {
870: case 125:
871: case 150:
872: return dtp.getOutputStream();
873: default:
874: throw new FTPException(response);
875: }
876: }
877:
878:
885: public OutputStream append(String filename)
886: throws IOException
887: {
888: if (dtp == null || transferMode == MODE_STREAM)
889: {
890: initialiseDTP();
891: }
892: String cmd = APPE + ' ' + filename;
893: send(cmd);
894: FTPResponse response = getResponse();
895: switch (response.getCode())
896: {
897: case 125:
898: case 150:
899: return dtp.getOutputStream();
900: default:
901: throw new FTPException(response);
902: }
903: }
904:
905:
912: public void allocate(long size)
913: throws IOException
914: {
915: String cmd = ALLO + ' ' + size;
916: send(cmd);
917: FTPResponse response = getResponse();
918: switch (response.getCode())
919: {
920: case 200:
921: case 202:
922: break;
923: default:
924: throw new FTPException(response);
925: }
926: }
927:
928:
934: public boolean rename(String oldName, String newName)
935: throws IOException
936: {
937: String cmd = RNFR + ' ' + oldName;
938: send(cmd);
939: FTPResponse response = getResponse();
940: switch (response.getCode())
941: {
942: case 450:
943: case 550:
944: return false;
945: case 350:
946: break;
947: default:
948: throw new FTPException(response);
949: }
950: cmd = RNTO + ' ' + newName;
951: send(cmd);
952: response = getResponse();
953: switch (response.getCode())
954: {
955: case 250:
956: return true;
957: case 450:
958: case 550:
959: return false;
960: default:
961: throw new FTPException(response);
962: }
963: }
964:
965:
969: public boolean abort()
970: throws IOException
971: {
972: send(ABOR);
973: FTPResponse response = getResponse();
974:
975: if (dtp != null)
976: {
977: dtp.abort();
978: }
979: switch (response.getCode())
980: {
981: case 226:
982: return false;
983: case 426:
984: response = getResponse();
985: if (response.getCode() == 226)
986: {
987: return true;
988: }
989:
990: default:
991: throw new FTPException(response);
992: }
993: }
994:
995:
999: public boolean delete(String filename)
1000: throws IOException
1001: {
1002: String cmd = DELE + ' ' + filename;
1003: send(cmd);
1004: FTPResponse response = getResponse();
1005: switch (response.getCode())
1006: {
1007: case 250:
1008: return true;
1009: case 450:
1010: case 550:
1011: return false;
1012: default:
1013: throw new FTPException(response);
1014: }
1015: }
1016:
1017:
1022: public boolean removeDirectory(String pathname)
1023: throws IOException
1024: {
1025: String cmd = RMD + ' ' + pathname;
1026: send(cmd);
1027: FTPResponse response = getResponse();
1028: switch (response.getCode())
1029: {
1030: case 250:
1031: return true;
1032: case 550:
1033: return false;
1034: default:
1035: throw new FTPException(response);
1036: }
1037: }
1038:
1039:
1044: public boolean makeDirectory(String pathname)
1045: throws IOException
1046: {
1047: String cmd = MKD + ' ' + pathname;
1048: send(cmd);
1049: FTPResponse response = getResponse();
1050: switch (response.getCode())
1051: {
1052: case 257:
1053: return true;
1054: case 550:
1055: return false;
1056: default:
1057: throw new FTPException(response);
1058: }
1059: }
1060:
1061:
1064: public String getWorkingDirectory()
1065: throws IOException
1066: {
1067: send(PWD);
1068: FTPResponse response = getResponse();
1069: switch (response.getCode())
1070: {
1071: case 257:
1072: String message = response.getMessage();
1073: if (message.charAt(0) == '"')
1074: {
1075: int end = message.indexOf('"', 1);
1076: if (end == -1)
1077: {
1078: throw new ProtocolException(message);
1079: }
1080: return message.substring(1, end);
1081: }
1082: else
1083: {
1084: int end = message.indexOf(' ');
1085: if (end == -1)
1086: {
1087: return message;
1088: }
1089: else
1090: {
1091: return message.substring(0, end);
1092: }
1093: }
1094: default:
1095: throw new FTPException(response);
1096: }
1097: }
1098:
1099:
1108: public InputStream list(String pathname)
1109: throws IOException
1110: {
1111: if (dtp == null || transferMode == MODE_STREAM)
1112: {
1113: initialiseDTP();
1114: }
1115: if (pathname == null)
1116: {
1117: send(LIST);
1118: }
1119: else
1120: {
1121: String cmd = LIST + ' ' + pathname;
1122: send(cmd);
1123: }
1124: FTPResponse response = getResponse();
1125: switch (response.getCode())
1126: {
1127: case 125:
1128: case 150:
1129: return dtp.getInputStream();
1130: default:
1131: throw new FTPException(response);
1132: }
1133: }
1134:
1135:
1142: public List nameList(String pathname)
1143: throws IOException
1144: {
1145: if (dtp == null || transferMode == MODE_STREAM)
1146: {
1147: initialiseDTP();
1148: }
1149: if (pathname == null)
1150: {
1151: send(NLST);
1152: }
1153: else
1154: {
1155: String cmd = NLST + ' ' + pathname;
1156: send(cmd);
1157: }
1158: FTPResponse response = getResponse();
1159: switch (response.getCode())
1160: {
1161: case 125:
1162: case 150:
1163: InputStream in = dtp.getInputStream();
1164: in = new BufferedInputStream(in);
1165: in = new CRLFInputStream(in);
1166: LineInputStream li = new LineInputStream(in);
1167: List ret = new ArrayList();
1168: for (String line = li.readLine();
1169: line != null;
1170: line = li.readLine())
1171: {
1172: ret.add(line);
1173: }
1174: li.close();
1175: return ret;
1176: default:
1177: throw new FTPException(response);
1178: }
1179: }
1180:
1181:
1184: public String system()
1185: throws IOException
1186: {
1187: send(SYST);
1188: FTPResponse response = getResponse();
1189: switch (response.getCode())
1190: {
1191: case 215:
1192: String message = response.getMessage();
1193: int end = message.indexOf(' ');
1194: if (end == -1)
1195: {
1196: return message;
1197: }
1198: else
1199: {
1200: return message.substring(0, end);
1201: }
1202: default:
1203: throw new FTPException(response);
1204: }
1205: }
1206:
1207:
1212: public void noop()
1213: throws IOException
1214: {
1215: send(NOOP);
1216: FTPResponse response = getResponse();
1217: switch (response.getCode())
1218: {
1219: case 200:
1220: break;
1221: default:
1222: throw new FTPException(response);
1223: }
1224: }
1225:
1226:
1227:
1228:
1233: protected void send(String cmd)
1234: throws IOException
1235: {
1236: byte[] data = cmd.getBytes(US_ASCII);
1237: out.write(data);
1238: out.writeln();
1239: out.flush();
1240: }
1241:
1242:
1247: protected FTPResponse getResponse()
1248: throws IOException
1249: {
1250: FTPResponse response = readResponse();
1251: if (response.getCode() == 226)
1252: {
1253: if (dtp != null)
1254: {
1255: dtp.transferComplete();
1256: }
1257: response = readResponse();
1258: }
1259: return response;
1260: }
1261:
1262:
1265: protected FTPResponse readResponse()
1266: throws IOException
1267: {
1268: String line = in.readLine();
1269: if (line == null)
1270: {
1271: throw new ProtocolException( "EOF");
1272: }
1273: if (line.length() < 4)
1274: {
1275: throw new ProtocolException(line);
1276: }
1277: int code = parseCode(line);
1278: if (code == -1)
1279: {
1280: throw new ProtocolException(line);
1281: }
1282: char c = line.charAt(3);
1283: if (c == ' ')
1284: {
1285: return new FTPResponse(code, line.substring(4));
1286: }
1287: else if (c == '-')
1288: {
1289: StringBuffer buf = new StringBuffer(line.substring(4));
1290: buf.append('\n');
1291: while(true)
1292: {
1293: line = in.readLine();
1294: if (line == null)
1295: {
1296: throw new ProtocolException("EOF");
1297: }
1298: if (line.length() >= 4 &&
1299: line.charAt(3) == ' ' &&
1300: parseCode(line) == code)
1301: {
1302: return new FTPResponse(code, line.substring(4),
1303: buf.toString());
1304: }
1305: else
1306: {
1307: buf.append(line);
1308: buf.append('\n');
1309: }
1310: }
1311: }
1312: else
1313: {
1314: throw new ProtocolException(line);
1315: }
1316: }
1317:
1318:
1322: static final int parseCode(String line)
1323: {
1324: char[] c = { line.charAt(0), line.charAt(1), line.charAt(2) };
1325: int ret = 0;
1326: for (int i = 0; i < 3; i++)
1327: {
1328: int digit =((int) c[i]) - 0x30;
1329: if (digit < 0 || digit > 9)
1330: {
1331: return -1;
1332: }
1333:
1334: switch (i)
1335: {
1336: case 0:
1337: ret +=(100 * digit);
1338: break;
1339: case 1:
1340: ret +=(10 * digit);
1341: break;
1342: case 2:
1343: ret += digit;
1344: break;
1345: }
1346: }
1347: return ret;
1348: }
1349:
1350: }