public void setData(byte[] data) throws IOException, ParserException { CalendarBuilder builder = new CalendarBuilder(); calendar = builder.build(new ByteArrayInputStream(data)); this.data = data.clone(); }
/** * Builds an iCalendar model from the specified input stream. * @param in an input stream to read calendar data from * @return a calendar parsed from the specified input stream * @throws IOException where an error occurs reading data from the specified stream * @throws ParserException where an error occurs parsing data from the stream */ public Calendar build(final InputStream in) throws IOException, ParserException { return build(new InputStreamReader(in, DEFAULT_CHARSET)); }
/** * @throws IOException * @throws ParserException */ public void testTzIdCompatibility() throws IOException, ParserException { CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(getClass().getResourceAsStream("/samples/valid/tmeher.ics")); // ensure the calendar is loaded properly.. assertNotNull(calendar); TimeZoneRegistry registry = builder.getRegistry(); calendar.getComponents().forEach(calendarComponent -> { calendarComponent.getProperties().forEach(property -> { TzId tzId = property.getParameter(Parameter.TZID); if (tzId != null) { assertNotNull(registry.getTimeZone(tzId.getValue())); } }); }); } }
public Object initialValue() { return new CalendarBuilder(); }
/** * Build an iCalendar model by parsing data from the specified reader. * * @param uin an unfolding reader to read data from * @return a calendar parsed from the specified reader * @throws IOException where an error occurs reading data from the specified reader * @throws ParserException where an error occurs parsing data from the reader */ public Calendar build(final UnfoldingReader uin) throws IOException, ParserException { // re-initialise.. calendar = null; components.clear(); property = null; datesMissingTimezones = new ArrayList<Property>(); parser.parse(uin, contentHandler); if (datesMissingTimezones.size() > 0 && tzRegistry != null) { resolveTimezones(); } return calendar; }
private static void clearTZRegistry(CalendarBuilder cb) { // clear timezone registry if present TimeZoneRegistry tzr = cb.getRegistry(); if(tzr!=null) { tzr.clear(); } } }
/** * Builds an iCalendar model from the specified input stream. * * @param in an input stream to read calendar data from * @return a calendar parsed from the specified input stream * @throws IOException where an error occurs reading data from the specified stream * @throws ParserException where an error occurs parsing data from the stream */ public Calendar build(final InputStream in) throws IOException, ParserException { return build(new InputStreamReader(in, DEFAULT_CHARSET)); }
public Object initialValue() { return new CalendarBuilder(); }
/** * Build an iCalendar model by parsing data from the specified reader. * @param uin an unfolding reader to read data from * @return a calendar parsed from the specified reader * @throws IOException where an error occurs reading data from the specified reader * @throws ParserException where an error occurs parsing data from the reader */ public Calendar build(final UnfoldingReader uin) throws IOException, ParserException { // re-initialise.. calendar = null; component = null; subComponent = null; property = null; datesMissingTimezones = new ArrayList(); parser.parse(uin, contentHandler); if (datesMissingTimezones.size() > 0 && tzRegistry != null) { resolveTimezones(); } return calendar; }
private static void clearTZRegistry(CalendarBuilder cb) { // clear timezone registry if present TimeZoneRegistry tzr = cb.getRegistry(); if(tzr!=null) { tzr.clear(); } } }
/** * Loads a calendar from the specified URL. * @param url the URL from which to load calendar data * @return returns a new calendar instance initialised from the specified URL * @throws IOException occurs when there is an error reading from the specified URL * @throws ParserException occurs when the data in the specified URL is invalid */ public static Calendar load(final URL url) throws IOException, ParserException { final CalendarBuilder builder = new CalendarBuilder(); return builder.build(url.openStream()); }
/** * Builds an iCalendar model from the specified input stream. * * @param in an input stream to read calendar data from * @return a calendar parsed from the specified input stream * @throws IOException where an error occurs reading data from the specified stream * @throws ParserException where an error occurs parsing data from the stream */ public Calendar build(final InputStream in) throws IOException, ParserException { return build(new InputStreamReader(in, DEFAULT_CHARSET)); }
/** * Return the CalendarBuilder instance. * @return CalendarBuilder */ private CalendarBuilder getCalendarBuilderInstance(){ CalendarBuilder builder = calendarBuilderThreadLocal.get(); if (builder == null){ builder = new CalendarBuilder(); calendarBuilderThreadLocal.set(builder); } return builder; }
/** * Build an iCalendar model by parsing data from the specified reader. * * @param uin an unfolding reader to read data from * @return a calendar parsed from the specified reader * @throws IOException where an error occurs reading data from the specified reader * @throws ParserException where an error occurs parsing data from the reader */ public Calendar build(final UnfoldingReader uin) throws IOException, ParserException { // re-initialise.. calendar = null; component = null; subComponent = null; property = null; datesMissingTimezones = new ArrayList<Property>(); parser.parse(uin, contentHandler); if (datesMissingTimezones.size() > 0 && tzRegistry != null) { resolveTimezones(); } return calendar; }
/** * Loads a calendar from the specified URL. * @param url the URL from which to load calendar data * @return returns a new calendar instance initialised from the specified URL * @throws IOException occurs when there is an error reading from the specified URL * @throws ParserException occurs when the data in the specified URL is invalid */ public static Calendar load(final URL url) throws IOException, ParserException { final CalendarBuilder builder = new CalendarBuilder(); return builder.build(url.openStream()); }
/** * Builds an iCalendar model from the specified input stream. * * @param in an input stream to read calendar data from * @return a calendar parsed from the specified input stream * @throws IOException where an error occurs reading data from the specified stream * @throws ParserException where an error occurs parsing data from the stream */ public Calendar build(final InputStream in) throws IOException, ParserException { return build(new InputStreamReader(in, DEFAULT_CHARSET)); }
/** * Constructor. * * @param method name of method to run in test case * @param file an iCalendar filename * @throws FileNotFoundException */ public CalendarBuilderTest(String testMethod, final String file) throws FileNotFoundException { super(testMethod); this.filename = file; this.fin = new FileInputStream(filename); builder = new CalendarBuilder(); }
/** * Loads a calendar from the specified URL. * @param url the URL from which to load calendar data * @return returns a new calendar instance initialised from the specified URL * @throws IOException occurs when there is an error reading from the specified URL * @throws ParserException occurs when the data in the specified URL is invalid */ public static Calendar load(final URL url) throws IOException, ParserException { final CalendarBuilder builder = new CalendarBuilder(); return builder.build(url.openStream()); }
/** * Builds an iCalendar model from the specified input stream. * * @param in an input stream to read calendar data from * @return a calendar parsed from the specified input stream * @throws IOException where an error occurs reading data from the specified stream * @throws ParserException where an error occurs parsing data from the stream */ public Calendar build(final InputStream in) throws IOException, ParserException { return build(new InputStreamReader(in, DEFAULT_CHARSET)); }
public void testConcurrency() throws Exception { final AtomicLong size = new AtomicLong(); ExecutorService executorService = Executors.newFixedThreadPool(100); for (int i = 0; i < 100; i++) { executorService.execute(new Runnable() { @Override public void run() { try(FileInputStream fis = new FileInputStream("src/test/resources/samples/valid/lotr.ics");) { Calendar calendar = new CalendarBuilder().build(fis); Calendar cal = new Calendar(calendar); size.addAndGet(cal.getComponents().size()); } catch (IOException | ParserException | URISyntaxException | ParseException e) { e.printStackTrace(); } } }); } executorService.shutdown(); executorService.awaitTermination(10, TimeUnit.MINUTES); assertEquals(3700, size.longValue()); }