Class IOUtils


  • public class IOUtils
    extends Object
    IO utils (similar to apache commons).
    • Field Detail

      • URL_PROTOCOL_FILE

        public static final String URL_PROTOCOL_FILE
        URL protocol for a file in the file system: "file"
        See Also:
        Constant Field Values
      • URL_PROTOCOL_VFS

        public static final String URL_PROTOCOL_VFS
        URL protocol for a JBoss VFS resource: "vfs"
        See Also:
        Constant Field Values
    • Constructor Detail

      • IOUtils

        public IOUtils()
    • Method Detail

      • toByteArray

        public static byte[] toByteArray​(URI uri)
        Download URI to byte array. Wait for the file to exists up to 5 seconds - it may be recreated while IDE recompilation, automatic retry will avoid false errors.
        Parameters:
        uri - uri to process
        Returns:
        byte array
        Throws:
        IllegalArgumentException - for download problems
      • streamToString

        public static String streamToString​(InputStream is)
        Convert input stream to a string.
        Parameters:
        is - stream
        Returns:
        string (at least empty string for empty stream)
      • isFileURL

        public static boolean isFileURL​(URL url)
        Determine whether the given URL points to a resource in the file system, that is, has protocol "file" or "vfs".
        Parameters:
        url - the URL to check
        Returns:
        whether the URL has been identified as a file system URL
      • isDirectoryURL

        public static boolean isDirectoryURL​(URL url)
        Determine whether the given URL points to a directory in the file system
        Parameters:
        url - the URL to check
        Returns:
        whether the URL has been identified as a file system URL
      • urlToClassName

        public static String urlToClassName​(URI uri)
                                     throws IOException
        Return fully qualified class name of class file on a URI.
        Parameters:
        uri - uri of class file
        Returns:
        name
        Throws:
        IOException - any exception on class instantiation
      • extractFileNameFromInputStream

        public static String extractFileNameFromInputStream​(InputStream is)
        Extract file name from input stream.
        Parameters:
        is - the is
        Returns:
        the string
      • extractFileNameFromReader

        public static String extractFileNameFromReader​(Reader reader)
        Extract file name from reader.
        Parameters:
        reader - the reader
        Returns:
        the string
      • extractFileNameFromInputSource

        public static String extractFileNameFromInputSource​(InputSource inputSource)
        Extract file name from input source.
        Parameters:
        inputSource - the input source
        Returns:
        the string