/** * Outputs an iCalender string to the specified output stream. * @param calendar calendar to write to ouput stream * @param out an output stream * @throws IOException thrown when unable to write to output stream * @throws ValidationException where calendar validation fails */ public final void output(final Calendar calendar, final OutputStream out) throws IOException, ValidationException { output(calendar, new OutputStreamWriter(out, DEFAULT_CHARSET)); }
/** * Outputs an iCalender string to the specified output stream. * @param calendar calendar to write to ouput stream * @param out an output stream * @throws IOException thrown when unable to write to output stream * @throws ValidationException where calendar validation fails */ public final void output(final Calendar calendar, final OutputStream out) throws IOException, ValidationException { output(calendar, new OutputStreamWriter(out, DEFAULT_CHARSET)); }
/** * Outputs an iCalender string to the specified output stream. * @param calendar calendar to write to ouput stream * @param out an output stream * @throws IOException thrown when unable to write to output stream * @throws ValidationException where calendar validation fails */ public final void output(final Calendar calendar, final OutputStream out) throws IOException, ValidationException { output(calendar, new OutputStreamWriter(out, DEFAULT_CHARSET)); }
/** * Outputs an iCalender string to the specified output stream. * @param calendar calendar to write to ouput stream * @param out an output stream * @throws IOException thrown when unable to write to output stream * @throws ValidationException where calendar validation fails */ public final void output(final Calendar calendar, final OutputStream out) throws IOException, ValidationException { output(calendar, new OutputStreamWriter(out, DEFAULT_CHARSET)); }
/** * Outputs an iCalender string to the specified output stream. * @param calendar calendar to write to ouput stream * @param out an output stream * @throws IOException thrown when unable to write to output stream * @throws ValidationException where calendar validation fails */ public final void output(final Calendar calendar, final OutputStream out) throws IOException, ValidationException { output(calendar, new OutputStreamWriter(out, DEFAULT_CHARSET)); }
/** * Get IcalBody as ByteArray * * @return - calendar in ICS format as byte[] * @throws Exception * - in case of error during writing to byte array */ public byte[] getIcalAsByteArray() throws Exception { ByteArrayOutputStream bout = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(icsCalendar, bout); return bout.toByteArray(); }
public ByteArrayOutputStream getCalendarAsByteStream() { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(this.calendar, stream); return stream; } catch (IOException e) { log.error("Error while exporting calendar " + e.getMessage()); return null; } }
public void writeCalendarToOutputStream(final OutputStream stream) { try { CalendarOutputter outputter = new CalendarOutputter(); outputter.output(this.calendar, stream); } catch (IOException e) { log.error("Error while exporting calendar " + e.getMessage()); } }
/** * Write iCal to File * * @param _filerPath * - path to '*.ics' file * @throws Exception * - in case of error during writing to the file */ public void writeDataToFile(String _filerPath) throws Exception { String filerPath = _filerPath.endsWith(".ics") ? _filerPath : String.format("%s.ics", _filerPath); try (FileOutputStream fout = new FileOutputStream(filerPath)) { CalendarOutputter outputter = new CalendarOutputter(); outputter.output(icsCalendar, fout); } }
/** * Convert Calendar object to String * @param calendar * @return string representation of calendar * @throws ValidationException - if something is wrong this exception is thrown. * @throws IOException - if something is wrong this exception is thrown. */ public static String outputCalendar(Calendar calendar) throws ValidationException, IOException { if (calendar == null) { return null; } CalendarOutputter outputter = new CalendarOutputter(); StringWriter sw = new StringWriter(); outputter.output(calendar, sw); return sw.toString(); }
/** * Convert Calendar object to String * @param calendar * @return string representation of calendar * @throws ValidationException - if something is wrong this exception is thrown. * @throws IOException - if something is wrong this exception is thrown. */ public static String outputCalendar(Calendar calendar) throws ValidationException, IOException { if (calendar == null) { return null; } CalendarOutputter outputter = new CalendarOutputter(); StringWriter sw = new StringWriter(); outputter.output(calendar, sw); return sw.toString(); }
private static String writeCalendar(Calendar calendar) throws CosmoDavException { try { StringWriter out = new StringWriter(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(calendar, out); String output = out.toString(); out.close(); // NB ical4j's outputter generates \r\n line ends but we // need only \n, so remove all \r's from the string output = output.replaceAll("\r", ""); return output; } catch (IOException | ValidationException e) { throw new CosmoDavException(e); } }
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; }
private static String writeCalendar(Calendar calendar) throws CosmoDavException { try { StringWriter out = new StringWriter(); CalendarOutputter outputter = new CalendarOutputter(); outputter.output(calendar, out); String output = out.toString(); out.close(); // NB ical4j's outputter generates \r\n line ends but we // need only \n, so remove all \r's from the string output = output.replaceAll("\r", ""); return output; } catch (IOException | ValidationException e) { throw new CosmoDavException(e); } }
/** * Generates the calendar request body, and sets the entity. * @param calendarRequest Object representing the marshalled properties * of the request * @param calendarOutputter Outputter object to generate the calendar string output */ protected void generateRequestBody(CalendarRequest calendarRequest, CalendarOutputter calendarOutputter) { Calendar calendar = calendarRequest.getCalendar(); if ( calendar != null){ StringWriter writer = new StringWriter(); try{ calendarOutputter.output(calendar, writer); ContentType ct = ContentType.create(CalDAVConstants.CONTENT_TYPE_CALENDAR, calendarRequest.getCharset()); setEntity(new StringEntity(writer.toString(), ct)); } catch (UnsupportedCharsetException e) { log.error("Unsupported encoding in event" + writer.toString()); throw new RuntimeException("Problem generating calendar. ", e); } catch (Exception e){ log.error("Problem generating calendar: ", e); throw new RuntimeException("Problem generating calendar. ", e); } } }
/** * Generates the calendar request body, and sets the entity. * @param calendarRequest Object representing the marshalled properties * of the request * @param calendarOutputter Outputter object to generate the calendar string output */ protected void generateRequestBody(CalendarRequest calendarRequest, CalendarOutputter calendarOutputter) { Calendar calendar = calendarRequest.getCalendar(); if ( calendar != null){ StringWriter writer = new StringWriter(); try{ calendarOutputter.output(calendar, writer); ContentType ct = ContentType.create(CalDAVConstants.CONTENT_TYPE_CALENDAR, calendarRequest.getCharset()); setEntity(new StringEntity(writer.toString(), ct)); } catch (UnsupportedCharsetException e) { log.error("Unsupported encoding in event" + writer.toString()); throw new RuntimeException("Problem generating calendar. ", e); } catch (Exception e){ log.error("Problem generating calendar: ", e); throw new RuntimeException("Problem generating calendar. ", e); } } }
/** Write a Calendar * * @param cal Calendar to convert * @param wtr Writer for output * @throws CalFacadeException */ public static void writeCalendar(final Calendar cal, final Writer wtr) throws CalFacadeException { CalendarOutputter co = new CalendarOutputter(false, 74); try { co.output(cal, wtr); } catch (Throwable t) { throw new CalFacadeException(t); } }
/** Create a Calendar object from the named timezone and convert to * a String representation * * @param tzid String timezone id * @return String * @throws CalFacadeException */ public String toStringTzCalendar(final String tzid) throws CalFacadeException { Calendar ical = getTzCalendar(tzid); CalendarOutputter calOut = new CalendarOutputter(true); StringWriter sw = new StringWriter(); try { calOut.output(ical, sw); return sw.toString(); } catch (Throwable t) { throw new CalFacadeException(t); } }
/** * 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); } } }
/** * Test escaping of commas in categories. */ public void testCommaEscaping() throws ValidationException, IOException, ParserException { Categories cat1 = new Categories("test1"); Categories cat2 = new Categories("test2"); Categories cat3 = new Categories("test1,test2,test 1\\,2\\,3"); VEvent event = new VEvent(); event.getProperties().add(cat1); event.getProperties().add(cat2); event.getProperties().add(cat3); Calendar calendar = new Calendar(); calendar.getComponents().add(event); StringWriter tempOut = new StringWriter(); CalendarOutputter cout = new CalendarOutputter(false); cout.output(calendar, tempOut); CalendarBuilder builder = new CalendarBuilder(); calendar = builder.build(new StringReader(tempOut.getBuffer() .toString())); List<Categories> categories = calendar.getComponent(Component.VEVENT) .getProperties(Property.CATEGORIES); assertEquals(cat1, categories.get(0)); assertEquals(cat2, categories.get(1)); assertEquals(cat3, categories.get(2)); assertEquals(3, cat3.getCategories().size()); }