import java.io.BufferedReader; import java.io.InputStreamReader; import java.security.MessageDigest; import java.net.URL; public class ICSParser { public static void parse ( final String url, final Group group, final boolean lazy, final boolean uid_override ) throws Exception { final BufferedReader reader; final StringBuilder sb; boolean should_record, has_id, ignore_line; String line; String class_name; String hash_seed; int length; sb = new StringBuilder(); reader = new BufferedReader(new InputStreamReader((new URL(url)).openStream())); class_name = "unknown"; should_record = false; ignore_line = false; hash_seed = ""; has_id = false; while ((line = reader.readLine()) != null) { if (line.startsWith("END:VEVENT")) { if (!has_id) { sb.append("UID:noid_"); sb.append(hash_seed.hashCode()); sb.append("\r\n"); } sb.append(line); sb.append("\r\n"); should_record = false; group.add_ICS_fragment(sb.toString(), class_name, lazy); sb.setLength(0); } else if (line.startsWith("BEGIN:VEVENT")) { should_record = true; has_id = false; hash_seed = ""; } else if (line.startsWith("DTSTART:")) { hash_seed += line; } else if (line.startsWith("SUMMARY:")) { class_name = line.substring(8, line.length()); hash_seed += line; } else if (line.startsWith("UID")) { if (uid_override) { ignore_line = true; } else { has_id = true; } } if (line.matches("\\w+:.*") && should_record) { if (!ignore_line) { sb.append(line); sb.append("\r\n"); } ignore_line = false; } } reader.close(); } }