Class FileResource

  • All Implemented Interfaces:
    Resource, java.io.Closeable, java.lang.AutoCloseable

    public class FileResource
    extends java.lang.Object
    implements Resource
    Resource for a file. This class implementation assumes the file does not change underneath this object.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer buffer  
      private static java.nio.ByteBuffer CLOSED  
      private boolean deleteOnClose  
      private java.lang.String extra  
      private java.nio.file.Path file  
      private long lastModified  
      private long size  
      private static int THRESHOLD  
    • Constructor Summary

      Constructors 
      Constructor Description
      FileResource​(Resource r)
      Turn a resource into a file so that anything in the conversion is properly caught
      FileResource​(java.io.File file)  
      FileResource​(java.nio.file.Path path)  
      FileResource​(java.nio.file.Path path, java.nio.file.attribute.BasicFileAttributes attrs)  
    • Field Detail

      • CLOSED

        private static final java.nio.ByteBuffer CLOSED
      • buffer

        private java.nio.ByteBuffer buffer
      • file

        private final java.nio.file.Path file
      • extra

        private java.lang.String extra
      • deleteOnClose

        private boolean deleteOnClose
      • lastModified

        private final long lastModified
      • size

        private final long size
    • Constructor Detail

      • FileResource

        public FileResource​(java.io.File file)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • FileResource

        public FileResource​(java.nio.file.Path path)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • FileResource

        FileResource​(java.nio.file.Path path,
                     java.nio.file.attribute.BasicFileAttributes attrs)
              throws java.io.IOException
        Throws:
        java.io.IOException
      • FileResource

        public FileResource​(Resource r)
                     throws java.lang.Exception
        Turn a resource into a file so that anything in the conversion is properly caught
        Parameters:
        r -
        Throws:
        java.lang.Exception
    • Method Detail

      • buffer

        public java.nio.ByteBuffer buffer()
                                   throws java.lang.Exception
        Specified by:
        buffer in interface Resource
        Throws:
        java.lang.Exception
      • openInputStream

        public java.io.InputStream openInputStream()
                                            throws java.lang.Exception
        Specified by:
        openInputStream in interface Resource
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • write

        public void write​(java.io.OutputStream out)
                   throws java.lang.Exception
        Specified by:
        write in interface Resource
        Throws:
        java.lang.Exception
      • write

        public void write​(java.io.File file)
                   throws java.lang.Exception
        Specified by:
        write in interface Resource
        Throws:
        java.lang.Exception
      • write

        public void write​(java.nio.file.Path path)
                   throws java.lang.Exception
        Specified by:
        write in interface Resource
        Throws:
        java.lang.Exception
      • getExtra

        public java.lang.String getExtra()
        Description copied from interface: Resource
        Use Resource.decodeExtra(String) to properly decode the ZIP extra field structured binary data from the returned String.
        Specified by:
        getExtra in interface Resource
        Returns:
        A String encoding the ZIP extra field.
      • setExtra

        public void setExtra​(java.lang.String extra)
        Description copied from interface: Resource
        Use Resource.encodeExtra(byte[]) to properly encode the ZIP extra field structured binary data into the specified String.
        Specified by:
        setExtra in interface Resource
        Parameters:
        extra - A String encoding the ZIP extra field.
      • size

        public long size()
        Specified by:
        size in interface Resource
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • deleteOnClose

        public void deleteOnClose​(boolean b)
      • getFile

        public java.io.File getFile()