Example usage for com.liferay.portal.kernel.io.unsync UnsyncBufferedOutputStream UnsyncBufferedOutputStream

List of usage examples for com.liferay.portal.kernel.io.unsync UnsyncBufferedOutputStream UnsyncBufferedOutputStream

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.io.unsync UnsyncBufferedOutputStream UnsyncBufferedOutputStream.

Prototype

public UnsyncBufferedOutputStream(OutputStream outputStream) 

Source Link

Usage

From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java

License:Open Source License

protected File exportICal4j(net.fortuna.ical4j.model.Calendar cal, String fileName) throws SystemException {

    OutputStream os = null;//  www . j  a v  a 2 s  .  c  o  m

    try {
        String extension = ".ics";

        if (Validator.isNull(fileName)) {
            fileName = "liferay.";
        } else {
            int pos = fileName.lastIndexOf(CharPool.PERIOD);

            if (pos != -1) {
                extension = fileName.substring(pos);
                fileName = fileName.substring(0, pos);
            }
        }

        fileName = FileUtil.getShortFileName(fileName);

        File file = File.createTempFile(fileName, extension);

        os = new UnsyncBufferedOutputStream(new FileOutputStream(file.getPath()));

        CalendarOutputter calOutput = new CalendarOutputter();

        if (cal.getComponents().isEmpty()) {
            calOutput.setValidating(false);
        }

        calOutput.output(cal, os);

        return file;
    } catch (Exception e) {
        _log.error(e, e);

        throw new SystemException(e);
    } finally {
        StreamUtil.cleanUp(os);
    }
}