private byte[] calendarAsByteArray(net.fortuna.ical4j.model.Calendar calendar) throws FileNotFoundException { byte[] bytes; try { ByteArrayOutputStream output = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); outputter.output(calendar, output); bytes = output.toByteArray(); FileOutputStream fos = new FileOutputStream("test.ics"); fos.write(bytes); fos.close() } catch (Exception e) { throw new IllegalStateException("can't convert calendar to bytes: "+e); } return bytes; }
/** * Writes an iCalendar string representing the calendar items * contained within the given calendar collection to the given * output stream. * * Since the calendar content stored with each calendar items * is parsed and validated when the item is created, these * errors should not reoccur when the calendar is being * outputted. * * @param collection the <code>CollectionItem</code> to format * * @throws IllegalArgumentException if the collection is not * stamped as a calendar collection * @throws IOException */ public static void output(Calendar calendar, OutputStream out) throws IOException { CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); try { outputter.output(calendar, out); } catch (ValidationException e) { throw new IllegalStateException("unable to validate collection calendar", e); } } }
/** * Writes an iCalendar string representing the calendar items * contained within the given calendar collection to the given * output stream. * * Since the calendar content stored with each calendar items * is parsed and validated when the item is created, these * errors should not reoccur when the calendar is being * outputted. * * @param collection the <code>CollectionItem</code> to format * * @throws IllegalArgumentException if the collection is not * stamped as a calendar collection * @throws IOException */ public static void output(Calendar calendar, OutputStream out) throws IOException { CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); try { outputter.output(calendar, out); } catch (ValidationException e) { throw new IllegalStateException("unable to validate collection calendar", e); } } }
outputter.setValidating(false); outputter.output(calendar, out);