Class MediaUtil


  • public class MediaUtil
    extends java.lang.Object
    Tools for medias
    • Field Detail

      • URL_IS_EMPTY

        public static final java.lang.String URL_IS_EMPTY
        If the URL contains this string, the URL is empty. Use empty string or null. This string is put into URL, when the data is removed. BEWARE: Oracle converts empty strings to null.
    • Constructor Detail

      • MediaUtil

        public MediaUtil()
    • Method Detail

      • isCurrentRequestSSLModeEnabled

        public static boolean isCurrentRequestSSLModeEnabled()
      • setCurrentRequestSSLModeEnabled

        public static void setCurrentRequestSSLModeEnabled​(boolean enabled)
      • unsetCurrentRequestSSLModeEnabled

        public static void unsetCurrentRequestSSLModeEnabled()
      • unsetCurrentSecureMediaURLRenderer

        public static void unsetCurrentSecureMediaURLRenderer()
      • unsetCurrentPublicMediaURLRenderer

        public static void unsetCurrentPublicMediaURLRenderer()
      • isZipRelatedMime

        @Deprecated(since="ages",
                    forRemoval=true)
        public static boolean isZipRelatedMime​(java.lang.String mime)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since ages - useMimeService.isZipRelatedMime(String) instead.
        Checks whether provided mime string is zip archive related.
      • assembleSecureMediaURL

        @Nullable
        public static java.lang.String assembleSecureMediaURL​(MediaSource media)
      • assemblePublicMediaURL

        @Nullable
        public static java.lang.String assemblePublicMediaURL​(java.lang.String rawUrl)
      • getMediaReadDir

        public static final java.io.File getMediaReadDir()
        Returns the media read directory. If not set in the configuration, a temporary directory will be returned.
        Returns:
        media read directory
        See Also:
        getTenantMediaReadDir()
      • getTenantMediaReadDir

        public static final java.io.File getTenantMediaReadDir()
        Same as getMediaReadDir() but including the current tenant subdirectory.
        Returns:
        media read directory including tenant subdirectory
        See Also:
        getMediaReadDir()
      • getLocalStorageReplicationDirs

        public static java.util.List<java.io.File> getLocalStorageReplicationDirs()
        Reads directories defined in media.replication.dirs. This method is called from getDataDirs when FILE mode is set
      • getLocalStorageDataDir

        public static java.io.File getLocalStorageDataDir()
      • composeOrGetParent

        public static java.io.File composeOrGetParent​(java.io.File parent,
                                                      java.lang.String child)
        Builds the file from parent file and child pathname which can be directory or file. If child is blank or null simply parent is returned.
      • getSystemDir

        public static java.lang.String getSystemDir()
      • copy

        public static long copy​(java.io.InputStream is,
                                java.io.OutputStream os)
                         throws java.io.IOException
        Copy the data from the Inputstream to the Outputstream. The Outputstream will always be closed after. Not the Inputstream
        Parameters:
        is - the Inputstream
        os - the Outputstream
        Returns:
        how many bytes where copied
        Throws:
        java.io.IOException - when an error in the inputstream occurs; an error in the outputstream will be catched and printed to the commandline
      • copy

        public static long copy​(java.io.InputStream is,
                                java.io.OutputStream os,
                                boolean closeOutputStream)
                         throws java.io.IOException
        Copy the data from the Inputstream to the Outputstream.
        Parameters:
        is - the Inputstream
        os - the Outputstream
        closeOutputStream - set to false if the Outputstream should not be closed afterwards.
        Returns:
        how many bytes where copied
        Throws:
        java.io.IOException - when an error in the inputstream occurs; an error in the outputstream will be catched and printed to the commandline
      • copy

        public static long copy​(java.io.InputStream is,
                                java.util.Collection<java.io.OutputStream> os)
                         throws java.io.IOException
        Copy the data from the Inputstream to a Collection of Outputstreams. The Outputstreams will always be closed after. Not the Inputstream
        Parameters:
        is - the Inputstream
        os - a Collection of Outputstreams
        Returns:
        how many bytes where copied
        Throws:
        java.io.IOException - when an error in the inputstream occurs; an error in the outputstreams will be catched and printed to the commandline
      • copy

        public static long copy​(java.io.InputStream is,
                                java.util.Collection<java.io.OutputStream> outStreams,
                                boolean closeOutputStreams)
                         throws java.io.IOException
        Copy the data from the InputStream to a Collection of OutputStreams. The OutputStreams will only be closed after if closeOutputStream is set to true. Not the InputStream
        Parameters:
        is - the InputStream
        outStreams - a Collection of OutputStreams
        closeOutputStreams - set to false if the OutputStream should not be closed afterwards.
        Returns:
        how many bytes where copied
        Throws:
        java.io.IOException - when an error in the input stream occurs; an error in the output streams will be caught and printed to the command line
      • getLocalMediaWebRootUrl

        public static java.lang.String getLocalMediaWebRootUrl()
        Returns local media web URL root URL. By default: /medias.
      • appendFileNameToDirName

        public static java.lang.String appendFileNameToDirName​(java.lang.String dirname,
                                                               java.lang.String filename)
      • getFileExtension

        public static final java.lang.String getFileExtension​(java.lang.String filename)
        Returns the file name extension (lowercase) or, if no '.' is found, the whole file name (without case change).
        Parameters:
        filename - the file name to get extension from
      • normalizeRealFileName

        public static java.lang.String normalizeRealFileName​(java.lang.String realFileName)
      • isFileNamePrettyURLCompatible

        public static boolean isFileNamePrettyURLCompatible​(java.lang.String realFileName)
      • concatDirectoryWithFolder

        public static java.io.File concatDirectoryWithFolder​(java.io.File dir,
                                                             MediaFolder subFolder)
        Concatenates given directory with given folder. Extracts the relative path from folder and adds it to the directory.
        Parameters:
        dir - directory
        subFolder - folder whose path will be added to directory
        Returns:
        new concatenated directory
        Since:
        3.1-u4
      • addTrailingFileSepIfNeeded

        public static java.lang.String addTrailingFileSepIfNeeded​(java.lang.String path)
        Adds the trailing file separator to the path if it doesn't contain one already.
        Parameters:
        path - the path
        Returns:
        modified path or empty string if path is null or empty
      • removeTrailingFileSepIfNeeded

        public static java.lang.String removeTrailingFileSepIfNeeded​(java.lang.String path)
        Removes trailing separator from the path if it exists.
        Parameters:
        path - the path
        Returns:
        modified path
      • removeLeadingFileSepIfNeeded

        public static java.lang.String removeLeadingFileSepIfNeeded​(java.lang.String path)
        Removes leading separator from the path if exists.
        Parameters:
        path - the path
        Returns:
        modified path
      • addLeadingFileSepIfNeeded

        public static java.lang.String addLeadingFileSepIfNeeded​(java.lang.String path)
        Adds the leading file separator to the path if it doesn't contain one already.
        Parameters:
        path - the path
        Returns:
        modified path or empty string if path is null or empty
      • removeFileExtension

        public static java.lang.String removeFileExtension​(java.lang.String fileName)