@Override @SuppressWarnings("unchecked") public ByteArrayOutputStream toEntity() throws IOException { net.fortuna.ical4j.model.Calendar ical = new net.fortuna.ical4j.model.Calendar(); ical.getProperties().add(Version.VERSION_2_0); ical.getProperties() .add(new ProdId("-//bitfire web engineering//DAVdroid " + Constants.APP_VERSION + "//EN")); VEvent event = new VEvent(); PropertyList props = event.getProperties(); if (uid != null) props.add(new Uid(uid)); props.add(dtStart); if (dtEnd != null) props.add(dtEnd); if (duration != null) props.add(duration); if (rrule != null) props.add(rrule); if (rdate != null) props.add(rdate); if (exrule != null) props.add(exrule); if (exdate != null) props.add(exdate); if (summary != null && !summary.isEmpty()) props.add(new Summary(summary)); if (location != null && !location.isEmpty()) props.add(new Location(location)); if (description != null && !description.isEmpty()) props.add(new Description(description)); if (status != null) props.add(status); if (!opaque) props.add(Transp.TRANSPARENT); if (organizer != null) props.add(organizer); props.addAll(attendees); if (forPublic != null) event.getProperties().add(forPublic ? Clazz.PUBLIC : Clazz.PRIVATE); event.getAlarms().addAll(alarms); props.add(new LastModified()); ical.getComponents().add(event); // add VTIMEZONE components net.fortuna.ical4j.model.TimeZone tzStart = (dtStart == null ? null : dtStart.getTimeZone()), tzEnd = (dtEnd == null ? null : dtEnd.getTimeZone()); if (tzStart != null) ical.getComponents().add(tzStart.getVTimeZone()); if (tzEnd != null && tzEnd != tzStart) ical.getComponents().add(tzEnd.getVTimeZone()); CalendarOutputter output = new CalendarOutputter(false); ByteArrayOutputStream os = new ByteArrayOutputStream(); try { output.output(ical, os); } catch (ValidationException e) { Log.e(TAG, "Generated invalid iCalendar"); } return os; }