我曾尝试从InputStreamReader
返回带有自定义事件的Calendar来解析读取器,但是由于我的icalendar
文件内容而导致URISyntaxException。但是我无法修改它,因为我的目的是仅获取iCalendar数据(在线file.ics)并将其解析为带有iCal4j库的日历:https://github.com/ical4j/ical4j。
所以我的问题是如何解决或绕过这个问题?
我的代码:
public class AccesHTTP extends AsyncTask<String, String, String> {
private Controle controle;
private String urlServ = null;
public AsyncResponse delegate = null;
public AccesHTTP(String servaddr) {
controle = Controle.getInstance(null);
urlServ = servaddr;
}
@Override
protected String doInBackground(String... strings) {
// Create a TimeZone
System.setProperty("net.fortuna.ical4j.timezone.cache.impl", MapTimeZoneCache.class.getName());
URL url = null;
try {
url = new URL(urlServ);
Reader r = null;
r = new InputStreamReader(url.openStream(), "ISO-8859-15");
CalendarBuilder builder = new CalendarBuilder();
Calendar thisCalendar = builder.build(r);
controle.refreshEdt(thisCalendar);
} catch (IOException | ParserException e) {
e.printStackTrace();
}
return "Completed";
}
@Override
protected void onPostExecute(String s){
Log.d("Return","************ " + s + " ************");
if(s!=null){
delegate.processFinish(s);
};
}
}
我的icalendar内容格式:
BEGIN:VCALENDAR
BEGIN:VEVENT
ATTENDEE;ROLE=CHAIR:CN=LASTNAME Forename :MAILTO:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT:CN=S5A-01_ANG :MAILTO:[email protected]
SUMMARY:- ang
DESCRIPTION:Professeur:LASTNAME Forename \nGroupe:S5A-01_ANG
DTSTART;TZID=Europe/Paris:20191211T080500
DTEND;TZID=Europe/Paris:20191211T093500
DTSTAMP:20200527T104154
LOCATION:B213
STATUS:CONFIRMED
UID:47468078
END:VEVENT
BEGIN:VEVENT
ATTENDEE;ROLE=CHAIR:CN=LASTNAME Forename :MAILTO:[email protected]
ATTENDEE;ROLE=REQ-PARTICIPANT:CN=S5A-01_ANG :MAILTO:[email protected]
...
END:VEVENT
END:VCALENDAR
错误代码:
java.net.URISyntaxException: Illegal character in scheme name at index 2: CN=LASTNAME Forename :MAILTO:[email protected]
at java.net.URI$Parser.fail(URI.java:2875)
at java.net.URI$Parser.checkChars(URI.java:3048)
at java.net.URI$Parser.parse(URI.java:3075)
at java.net.URI.<init>(URI.java:583)
at net.fortuna.ical4j.util.Uris.create(Uris.java:121)
at net.fortuna.ical4j.model.property.Attendee.setValue(Attendee.java:109)
at net.fortuna.ical4j.model.property.Attendee.<init>(Attendee.java:85)
at net.fortuna.ical4j.model.property.Attendee$Factory.createProperty(Attendee.java:175)
at net.fortuna.ical4j.model.PropertyBuilder.build(PropertyBuilder.java:48)
at net.fortuna.ical4j.data.DefaultContentHandler.endProperty(DefaultContentHandler.java:123)
at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.parse(CalendarParserImpl.java:292)
at net.fortuna.ical4j.data.CalendarParserImpl$PropertyParser.access$1100(CalendarParserImpl.java:224)
at net.fortuna.ical4j.data.CalendarParserImpl$PropertyListParser.parse(CalendarParserImpl.java:211)
at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.parse(CalendarParserImpl.java:427)
at net.fortuna.ical4j.data.CalendarParserImpl$ComponentParser.access$900(CalendarParserImpl.java:404)
at net.fortuna.ical4j.data.CalendarParserImpl$PropertyListParser.parse(CalendarParserImpl.java:209)
at net.fortuna.ical4j.data.CalendarParserImpl.parseCalendar(CalendarParserImpl.java:115)
at net.fortuna.ical4j.data.CalendarParserImpl.parseCalendarList(CalendarParserImpl.java:180)
at net.fortuna.ical4j.data.CalendarParserImpl.parse(CalendarParserImpl.java:149)
... 10 more
最佳答案
您的iCalendar数据中存在语法错误。
分号必须位于ROLE参数之后,而不是冒号。例如:
不正确:ATTENDEE;ROLE=CHAIR:CN=LASTNAME Forename :MAILTO:[email protected]
正确:ATTENDEE;ROLE=CHAIR;CN=LASTNAME Forename :MAILTO:[email protected]