Package org.drools.io

Class FileSystemResource

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable, InternalResource, org.kie.api.io.Resource

    public class FileSystemResource
    extends BaseResource
    implements InternalResource, java.io.Externalizable
    Borrowed gratuitously from Spring under ASL2.0.
    See Also:
    Serialized Form
    • Constructor Detail

      • FileSystemResource

        public FileSystemResource()
      • FileSystemResource

        public FileSystemResource​(java.io.File file)
        Create a new FileSystemResource from a File handle.

        Note: When building relative resources via #createRelative, the relative path will apply at the same directory level: e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"! If you prefer to have relative paths built underneath the given root directory, use the constructor with a file path to append a trailing slash to the root path: "C:/dir1/", which indicates this directory as root for all relative paths.

        Parameters:
        file - a File handle
      • FileSystemResource

        public FileSystemResource​(java.io.File file,
                                  java.lang.String encoding)
      • FileSystemResource

        public FileSystemResource​(java.lang.String path)
        Create a new FileSystemResource from a file path.

        Note: When building relative resources via #createRelative, it makes a difference whether the specified resource base path here ends with a slash or not. In the case of "C:/dir1/", relative paths will be built underneath that root: e.g. relative path "dir2" -> "C:/dir1/dir2". In the case of "C:/dir1", relative paths will apply at the same directory level: relative path "dir2" -> "C:/dir2".

        Parameters:
        path - a file path
      • FileSystemResource

        public FileSystemResource​(java.lang.String path,
                                  java.lang.String encoding)
    • Method Detail

      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class BaseResource
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class BaseResource
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        This implementation opens a FileInputStream for the underlying file.
        Specified by:
        getInputStream in interface org.kie.api.io.Resource
        Throws:
        java.io.IOException
        See Also:
        FileInputStream
      • getReader

        public java.io.Reader getReader()
                                 throws java.io.IOException
        Specified by:
        getReader in interface org.kie.api.io.Resource
        Throws:
        java.io.IOException
      • getFile

        public java.io.File getFile()
      • listResources

        public java.util.Collection<org.kie.api.io.Resource> listResources()
        Specified by:
        listResources in interface InternalResource
      • getURL

        public java.net.URL getURL()
                            throws java.io.IOException
        This implementation returns a URL for the underlying file.
        Specified by:
        getURL in interface InternalResource
        Throws:
        java.io.IOException
        See Also:
        File.toURI()
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class BaseResource