Class FileUtils

java.lang.Object
org.apache.jena.util.FileUtils

public class FileUtils extends Object
  • Field Details

  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • asUTF8

      public static Reader asUTF8(InputStream in)
      Create a reader that uses UTF-8 encoding
    • asBufferedUTF8

      public static BufferedReader asBufferedUTF8(InputStream in)
      Create a buffered reader that uses UTF-8 encoding
    • asUTF8

      public static Writer asUTF8(OutputStream out)
      Create a writer that uses UTF-8 encoding
    • asPrintWriterUTF8

      public static PrintWriter asPrintWriterUTF8(OutputStream out)
      Create a print writer that uses UTF-8 encoding
    • guessLang

      public static String guessLang(String name, String otherwise)
      Guess the language/type of model data.
      • If the URI ends ".rdf", it is assumed to be RDF/XML
      • If the URI ends ".nt", it is assumed to be N-Triples
      • If the URI ends ".ttl", it is assumed to be Turtle
      • If the URI ends ".owl", it is assumed to be RDF/XML
      Parameters:
      name - URL to base the guess on
      otherwise - Default guess
      Returns:
      String Guessed syntax - or the default supplied
    • guessLang

      public static String guessLang(String urlStr)
      Guess the language/type of model data
      • If the URI ends ".rdf", it is assumed to be RDF/XML
      • If the URI ends ".nt", it is assumed to be N-Triples
      • If the URI ends ".ttl", it is assumed to be Turtle
      • If the URI ends ".owl", it is assumed to be RDF/XML
      Parameters:
      urlStr - URL to base the guess on
      Returns:
      String Guessed syntax - default is RDF/XML
    • toFilename

      @Deprecated public static String toFilename(String filenameOrURI)
      Deprecated.
      Use IRILib.IRIToFilename.
      Turn a file: URL or file name into a plain file name
    • decodeFileName

      public static String decodeFileName(String s)
    • isFile

      public static boolean isFile(String name)
      Check whether 'name' is possibly a file reference
      Parameters:
      name -
      Returns:
      boolean False if clearly not a filename.
    • isURI

      public static boolean isURI(String name)
      Check whether a name is an absolute URI (has a scheme name)
      Parameters:
      name -
      Returns:
      boolean True if there is a scheme name
    • getScheme

      @Deprecated public static String getScheme(String uri)
      Get the URI scheme at the start of the string. This is the substring up to, and excluding, the first ":" if it conforms to the syntax requirements. Return null if it does not look like a scheme.

      The RFC 3986 URI grammar defines scheme as:

       URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
       scheme      = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
       ...
       
    • getDirname

      public static String getDirname(String filename)
      Get the directory part of a filename
      Parameters:
      filename -
      Returns:
      Directory name
    • getFilenameExt

      public static String getFilenameExt(String filename)
      Get the suffix part of a file name or a URL in file-like format.
    • tempFileName

      public static File tempFileName(String prefix, String suffix)
      create a temporary file that will be deleted on exit, and do something sensible with any IO exceptions - namely, throw them up wrapped in a JenaException.
      Parameters:
      prefix - the prefix for File.createTempFile
      suffix - the suffix for File.createTempFile
      Returns:
      the temporary File
    • getScratchDirectory

      public static File getScratchDirectory(String prefix)
      Answer a File naming a freshly-created directory in the temporary directory. This directory should be deleted on exit. TODO handle threading issues, mkdir failure, and better cleanup
      Parameters:
      prefix - the prefix for the directory name
      Returns:
      a File naming the new directory
    • getTempDirectory

      public static String getTempDirectory()
    • openResourceFile

      public static BufferedReader openResourceFile(String filename)
      Answer a BufferedReader than reads from the named resource file as UTF-8, possibly throwing WrappedIOExceptions.
    • openResourceFileAsStream

      public static InputStream openResourceFileAsStream(String filename) throws FileNotFoundException
      Open an resource file for reading.
      Throws:
      FileNotFoundException
    • readerFromURL

      public static BufferedReader readerFromURL(String urlStr)
    • readWholeFileAsUTF8

      public static String readWholeFileAsUTF8(String filename) throws IOException
      Read a whole file as UTF-8
      Parameters:
      filename -
      Returns:
      String
      Throws:
      IOException
    • readWholeFileAsUTF8

      public static String readWholeFileAsUTF8(InputStream in) throws IOException
      Read a whole stream as UTF-8
      Parameters:
      in - InputStream to be read
      Returns:
      String
      Throws:
      IOException