1 36 package org.columba.ristretto.imap.parser; 37 38 import java.util.regex.Matcher ; 39 import java.util.regex.Pattern ; 40 41 import org.columba.ristretto.imap.IMAPResponse; 42 import org.columba.ristretto.imap.QuotaInfo; 43 import org.columba.ristretto.parser.ParserException; 44 45 49 public class QuotaInfoParser 50 { 51 private static final Pattern quotaPattern = Pattern.compile("(\\d+)\\s(\\d+)"); 52 53 60 public static QuotaInfo parse(IMAPResponse in) throws ParserException 61 { 62 return parse(in, null); 63 } 64 65 74 public static QuotaInfo parse(IMAPResponse in, QuotaInfo quotaInfo) throws ParserException 75 { 76 QuotaInfo result = (quotaInfo != null) ? quotaInfo : new QuotaInfo(); 77 78 Matcher quotaMatcher = quotaPattern.matcher(in.getResponseMessage()); 79 if (quotaMatcher.find()) { 80 81 try { 82 result.setSize(Long.parseLong(quotaMatcher.group(1))); 83 } 84 catch (NumberFormatException e) { 85 throw new ParserException(e); 86 } 87 88 try { 89 result.setMaxSize(Long.parseLong(quotaMatcher.group(2))); 90 } 91 catch (NumberFormatException e) { 92 throw new ParserException(e); 93 } 94 } 95 96 return result; 97 } 98 } 99 | Popular Tags |