Example usage for com.liferay.portal.kernel.util FileUtil delete

List of usage examples for com.liferay.portal.kernel.util FileUtil delete

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util FileUtil delete.

Prototype

public static boolean delete(String file) 

Source Link

Usage

From source file:com.liferay.sync.internal.servlet.SyncDownloadServlet.java

License:Open Source License

protected DownloadServletInputStream getPatchDownloadServletInputStream(long userId, long groupId, String uuid,
        long sourceVersionId, long targetVersionId) throws Exception {

    FileEntry fileEntry = _dlAppService.getFileEntryByUuidAndGroupId(uuid, groupId);

    if (fileEntry.isInTrash()) {
        throw new NoSuchFileEntryException();
    }/*  ww w  .  j a v a2  s.  com*/

    if (!SyncServiceConfigurationValues.SYNC_FILE_DIFF_CACHE_ENABLED) {
        File deltaFile = null;

        try {
            deltaFile = getDeltaFile(userId, fileEntry.getFileEntryId(), sourceVersionId, targetVersionId);

            return new DownloadServletInputStream(new FileInputStream(deltaFile), deltaFile.length());
        } finally {
            FileUtil.delete(deltaFile);
        }
    }

    SyncDLFileVersionDiff syncDLFileVersionDiff = SyncDLFileVersionDiffLocalServiceUtil
            .fetchSyncDLFileVersionDiff(fileEntry.getFileEntryId(), sourceVersionId, targetVersionId);

    if (syncDLFileVersionDiff != null) {
        SyncDLFileVersionDiffLocalServiceUtil
                .refreshExpirationDate(syncDLFileVersionDiff.getSyncDLFileVersionDiffId());

        FileEntry dataFileEntry = PortletFileRepositoryUtil
                .getPortletFileEntry(syncDLFileVersionDiff.getDataFileEntryId());

        return new DownloadServletInputStream(dataFileEntry.getContentStream(), dataFileEntry.getSize());
    } else {
        File deltaFile = null;

        try {
            deltaFile = getDeltaFile(userId, fileEntry.getFileEntryId(), sourceVersionId, targetVersionId);

            try {
                SyncDLFileVersionDiffLocalServiceUtil.addSyncDLFileVersionDiff(fileEntry.getFileEntryId(),
                        sourceVersionId, targetVersionId, deltaFile);
            } catch (DuplicateFileException dfe) {

                // LPS-52675

                if (_log.isDebugEnabled()) {
                    _log.debug(dfe, dfe);
                }
            }

            return new DownloadServletInputStream(new FileInputStream(deltaFile), deltaFile.length());
        } finally {
            FileUtil.delete(deltaFile);
        }
    }
}

From source file:com.liferay.sync.service.impl.SyncDLObjectServiceImpl.java

License:Open Source License

@Override
public SyncDLObject patchFileEntry(long fileEntryId, String sourceVersion, String sourceFileName,
        String mimeType, String title, String description, String changeLog, boolean majorVersion,
        File deltaFile, String checksum, ServiceContext serviceContext) throws PortalException {

    File patchedFile = null;//from ww w.j av a2 s  .com

    try {
        File sourceFile = dlFileEntryLocalService.getFile(getUserId(), fileEntryId, sourceVersion, false);

        patchedFile = FileUtil.createTempFile();

        SyncUtil.patchFile(sourceFile, deltaFile, patchedFile);

        SyncDLObject syncDLObject = updateFileEntry(fileEntryId, sourceFileName, mimeType, title, description,
                changeLog, majorVersion, patchedFile, checksum, serviceContext);

        if (PortletPropsValues.SYNC_FILE_DIFF_CACHE_ENABLED) {
            DLFileVersion sourceDLFileVersion = dlFileVersionLocalService.getFileVersion(fileEntryId,
                    sourceVersion);
            DLFileVersion targetDLFileVersion = dlFileVersionLocalService.getFileVersion(fileEntryId,
                    syncDLObject.getVersion());

            syncDLFileVersionDiffLocalService.addSyncDLFileVersionDiff(fileEntryId,
                    sourceDLFileVersion.getFileVersionId(), targetDLFileVersion.getFileVersionId(), deltaFile);
        }

        return syncDLObject;
    } catch (PortalException pe) {
        throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    } finally {
        FileUtil.delete(patchedFile);
    }
}

From source file:com.liferay.sync.util.SyncUtil.java

License:Open Source License

public static File getFileDelta(File sourceFile, File targetFile) throws PortalException {

    File deltaFile = null;/*from   w  w w . ja v a2s. c  o  m*/

    FileInputStream sourceFileInputStream = null;
    FileChannel sourceFileChannel = null;
    File checksumsFile = FileUtil.createTempFile();
    OutputStream checksumsOutputStream = null;
    WritableByteChannel checksumsWritableByteChannel = null;

    try {
        sourceFileInputStream = new FileInputStream(sourceFile);

        sourceFileChannel = sourceFileInputStream.getChannel();

        checksumsOutputStream = new FileOutputStream(checksumsFile);

        checksumsWritableByteChannel = Channels.newChannel(checksumsOutputStream);

        ByteChannelWriter checksumsByteChannelWriter = new ByteChannelWriter(checksumsWritableByteChannel);

        DeltaUtil.checksums(sourceFileChannel, checksumsByteChannelWriter);

        checksumsByteChannelWriter.finish();
    } catch (Exception e) {
        throw new PortalException(e);
    } finally {
        StreamUtil.cleanUp(sourceFileInputStream);
        StreamUtil.cleanUp(sourceFileChannel);
        StreamUtil.cleanUp(checksumsOutputStream);
        StreamUtil.cleanUp(checksumsWritableByteChannel);
    }

    FileInputStream targetFileInputStream = null;
    ReadableByteChannel targetReadableByteChannel = null;
    InputStream checksumsInputStream = null;
    ReadableByteChannel checksumsReadableByteChannel = null;
    OutputStream deltaOutputStream = null;
    WritableByteChannel deltaOutputStreamWritableByteChannel = null;

    try {
        targetFileInputStream = new FileInputStream(targetFile);

        targetReadableByteChannel = targetFileInputStream.getChannel();

        checksumsInputStream = new FileInputStream(checksumsFile);

        checksumsReadableByteChannel = Channels.newChannel(checksumsInputStream);

        ByteChannelReader checksumsByteChannelReader = new ByteChannelReader(checksumsReadableByteChannel);

        deltaFile = FileUtil.createTempFile();

        deltaOutputStream = new FileOutputStream(deltaFile);

        deltaOutputStreamWritableByteChannel = Channels.newChannel(deltaOutputStream);

        ByteChannelWriter deltaByteChannelWriter = new ByteChannelWriter(deltaOutputStreamWritableByteChannel);

        DeltaUtil.delta(targetReadableByteChannel, checksumsByteChannelReader, deltaByteChannelWriter);

        deltaByteChannelWriter.finish();
    } catch (Exception e) {
        throw new PortalException(e);
    } finally {
        StreamUtil.cleanUp(targetFileInputStream);
        StreamUtil.cleanUp(targetReadableByteChannel);
        StreamUtil.cleanUp(checksumsInputStream);
        StreamUtil.cleanUp(checksumsReadableByteChannel);
        StreamUtil.cleanUp(deltaOutputStream);
        StreamUtil.cleanUp(deltaOutputStreamWritableByteChannel);

        FileUtil.delete(checksumsFile);
    }

    return deltaFile;
}

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

@Override
public List<FileEntry> addPageAttachments(long userId, long nodeId, String title,
        List<ObjectValuePair<String, InputStream>> inputStreamOVPs) throws PortalException {

    List<FileEntry> fileEntries = new ArrayList<>();

    if (inputStreamOVPs.isEmpty()) {
        return Collections.emptyList();
    }/*from w  ww .j  a  v  a2  s. co  m*/

    for (int i = 0; i < inputStreamOVPs.size(); i++) {
        ObjectValuePair<String, InputStream> inputStreamOVP = inputStreamOVPs.get(i);

        String fileName = inputStreamOVP.getKey();
        InputStream inputStream = inputStreamOVP.getValue();

        File file = null;

        try {
            file = FileUtil.createTempFile(inputStream);

            String mimeType = MimeTypesUtil.getContentType(file, fileName);

            FileEntry fileEntry = addPageAttachment(userId, nodeId, title, fileName, file, mimeType);

            fileEntries.add(fileEntry);
        } catch (IOException ioe) {
            throw new SystemException("Unable to write temporary file", ioe);
        } finally {
            FileUtil.delete(file);
        }
    }

    return fileEntries;
}

From source file:eu.ibacz.extlet.deploy.hot.ExtletHotDeployer.java

License:Open Source License

/**
 * Removes all extlet's jars specified by {@link ExtletHotDeployer#EXTLET_SERVICE_JAR_NAME_KEY} from the directory where the portal-kernel.jar resides.
 *//* www  . j a va 2 s  . c om*/
private void removeExtletServiceJar() throws HotDeployException {
    if (_log.isDebugEnabled()) {
        _log.debug("About to remove exlet service.");
    }

    for (File extletServiceJar : getExtletServiceJars()) {
        File portalServiceJar = getPortalServiceJar(extletServiceJar);
        if (_log.isDebugEnabled()) {
            _log.info("Removing extlet service " + portalServiceJar.getName() + ".");
        }

        FileUtil.delete(portalServiceJar);

        if (_log.isDebugEnabled()) {
            _log.info("Extlet service " + portalServiceJar.getName() + " undeployed successfully.");
        }
    }
}

From source file:eu.ibacz.extlet.deploy.hot.ExtletHotDeployer.java

License:Open Source License

/**
 * Removes all extlet's jars specified by {@link ExtletHotDeployer#EXTLET_IMPL_JAR_NAME_KEY} from the portal's WEB-INF/lib directory.
 *///from  w ww  .  ja  v  a  2 s  .co m
protected void removeExtletImplJar() throws HotDeployException {
    if (_log.isDebugEnabled()) {
        _log.debug("About to remove extlet impl.");
    }

    for (File getExtletImplJar : getExtletImplJars()) {
        File portalImplJar = getPortalImplJar(getExtletImplJar);
        if (_log.isDebugEnabled()) {
            _log.info("Removing extlet impl [" + portalImplJar.getAbsolutePath() + "]");
        }

        FileUtil.delete(portalImplJar);

        if (_log.isDebugEnabled()) {
            _log.info("Extlet impl jar " + portalImplJar.getName() + " undeployed successfully.");
        }
    }
}