Class GridFilesystem


  • public class GridFilesystem
    extends java.lang.Object
    Entry point for GridFile and GridInputStream / GridOutputStream
    Author:
    Bela Ban, Marko Luksa
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.io.File getFile​(java.io.File parent, java.lang.String child)  
      java.io.File getFile​(java.io.File parent, java.lang.String child, int chunkSize)  
      java.io.File getFile​(java.lang.String pathname)
      Returns the file denoted by pathname.
      java.io.File getFile​(java.lang.String pathname, int chunkSize)
      Returns the file denoted by pathname.
      java.io.File getFile​(java.lang.String parent, java.lang.String child)  
      java.io.File getFile​(java.lang.String parent, java.lang.String child, int chunkSize)  
      java.io.InputStream getInput​(java.io.File file)
      Opens an InputStream for reading from the given file.
      java.io.InputStream getInput​(java.lang.String pathname)
      Opens an InputStream for reading from the file denoted by pathname.
      java.io.OutputStream getOutput​(java.lang.String pathname)
      Opens an OutputStream for writing to the file denoted by pathname.
      java.io.OutputStream getOutput​(java.lang.String pathname, boolean append)
      Opens an OutputStream for writing to the file denoted by pathname.
      java.io.OutputStream getOutput​(java.lang.String pathname, boolean append, int chunkSize)
      Opens an OutputStream for writing to the file denoted by pathname.
      java.io.OutputStream getOutput​(GridFile file)
      Opens an OutputStream for writing to the given file.
      ReadableGridFileChannel getReadableChannel​(java.lang.String pathname)
      Opens a ReadableGridFileChannel for reading from the file denoted by the given file path.
      WritableGridFileChannel getWritableChannel​(java.lang.String pathname)
      Opens a WritableGridFileChannel for writing to the file denoted by pathname.
      WritableGridFileChannel getWritableChannel​(java.lang.String pathname, boolean append)
      Opens a WritableGridFileChannel for writing to the file denoted by pathname.
      WritableGridFileChannel getWritableChannel​(java.lang.String pathname, boolean append, int chunkSize)
      Opens a WritableGridFileChannel for writing to the file denoted by pathname.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • data

        protected final Cache<java.lang.String,​byte[]> data
      • defaultChunkSize

        protected final int defaultChunkSize
    • Constructor Detail

      • GridFilesystem

        public GridFilesystem​(Cache<java.lang.String,​byte[]> data,
                              Cache<java.lang.String,​GridFile.Metadata> metadata,
                              int defaultChunkSize)
        Creates an instance. The data and metadata caches should already have been setup and started
        Parameters:
        data - the cache where the actual file contents are stored
        metadata - the cache where file meta-data is stored
        defaultChunkSize - the default size of the file chunks
      • GridFilesystem

        public GridFilesystem​(Cache<java.lang.String,​byte[]> data,
                              Cache<java.lang.String,​GridFile.Metadata> metadata)
    • Method Detail

      • getFile

        public java.io.File getFile​(java.lang.String pathname)
        Returns the file denoted by pathname.
        Parameters:
        pathname - the full path of the requested file
        Returns:
        the File stored at pathname
      • getFile

        public java.io.File getFile​(java.lang.String pathname,
                                    int chunkSize)
        Returns the file denoted by pathname. If the file does not yet exist, it is initialized with the given chunkSize. However, if the file at pathname already exists, the chunkSize parameter is ignored and the file's actual chunkSize is used.
        Parameters:
        pathname - the full path of the requested file
        chunkSize - the size of the file's chunks. This parameter is only used for non-existing files.
        Returns:
        the File stored at pathname
      • getFile

        public java.io.File getFile​(java.lang.String parent,
                                    java.lang.String child)
      • getFile

        public java.io.File getFile​(java.lang.String parent,
                                    java.lang.String child,
                                    int chunkSize)
      • getFile

        public java.io.File getFile​(java.io.File parent,
                                    java.lang.String child)
      • getFile

        public java.io.File getFile​(java.io.File parent,
                                    java.lang.String child,
                                    int chunkSize)
      • getOutput

        public java.io.OutputStream getOutput​(java.lang.String pathname)
                                       throws java.io.IOException
        Opens an OutputStream for writing to the file denoted by pathname. If a file at pathname already exists, writing to the returned OutputStream will overwrite the contents of the file.
        Parameters:
        pathname - the path to write to
        Returns:
        an OutputStream for writing to the file at pathname
        Throws:
        java.io.IOException - if an error occurs
      • getOutput

        public java.io.OutputStream getOutput​(java.lang.String pathname,
                                              boolean append)
                                       throws java.io.IOException
        Opens an OutputStream for writing to the file denoted by pathname. The OutputStream can either overwrite the existing file or append to it.
        Parameters:
        pathname - the path to write to
        append - if true, the bytes written to the OutputStream will be appended to the end of the file. If false, the bytes will overwrite the original contents.
        Returns:
        an OutputStream for writing to the file at pathname
        Throws:
        java.io.IOException - if an error occurs
      • getOutput

        public java.io.OutputStream getOutput​(java.lang.String pathname,
                                              boolean append,
                                              int chunkSize)
                                       throws java.io.IOException
        Opens an OutputStream for writing to the file denoted by pathname.
        Parameters:
        pathname - the file to write to
        append - if true, the bytes written to the OutputStream will be appended to the end of the file
        chunkSize - the size of the file's chunks. This parameter is honored only when the file at pathname does not yet exist. If the file already exists, the file's own chunkSize has precedence.
        Returns:
        the OutputStream for writing to the file
        Throws:
        java.io.IOException - if the file is a directory, cannot be created or some other error occurs
      • getOutput

        public java.io.OutputStream getOutput​(GridFile file)
                                       throws java.io.IOException
        Opens an OutputStream for writing to the given file.
        Parameters:
        file - the file to write to
        Returns:
        an OutputStream for writing to the file
        Throws:
        java.io.IOException - if an error occurs
      • getInput

        public java.io.InputStream getInput​(java.lang.String pathname)
                                     throws java.io.FileNotFoundException
        Opens an InputStream for reading from the file denoted by pathname.
        Parameters:
        pathname - the full path of the file to read from
        Returns:
        an InputStream for reading from the file
        Throws:
        java.io.FileNotFoundException - if the file does not exist or is a directory
      • getInput

        public java.io.InputStream getInput​(java.io.File file)
                                     throws java.io.FileNotFoundException
        Opens an InputStream for reading from the given file.
        Parameters:
        file - the file to open for reading
        Returns:
        an InputStream for reading from the file
        Throws:
        java.io.FileNotFoundException - if the file does not exist or is a directory
      • getReadableChannel

        public ReadableGridFileChannel getReadableChannel​(java.lang.String pathname)
                                                   throws java.io.FileNotFoundException
        Opens a ReadableGridFileChannel for reading from the file denoted by the given file path. One of the benefits of using a channel over an InputStream is the possibility to randomly seek to any position in the file (see #ReadableGridChannel.position()).
        Parameters:
        pathname - path of the file to open for reading
        Returns:
        a ReadableGridFileChannel for reading from the file
        Throws:
        java.io.FileNotFoundException - if the file does not exist or is a directory
      • getWritableChannel

        public WritableGridFileChannel getWritableChannel​(java.lang.String pathname)
                                                   throws java.io.IOException
        Opens a WritableGridFileChannel for writing to the file denoted by pathname. If a file at pathname already exists, writing to the returned channel will overwrite the contents of the file.
        Parameters:
        pathname - the path to write to
        Returns:
        a WritableGridFileChannel for writing to the file at pathname
        Throws:
        java.io.IOException - if an error occurs
      • getWritableChannel

        public WritableGridFileChannel getWritableChannel​(java.lang.String pathname,
                                                          boolean append)
                                                   throws java.io.IOException
        Opens a WritableGridFileChannel for writing to the file denoted by pathname. The channel can either overwrite the existing file or append to it.
        Parameters:
        pathname - the path to write to
        append - if true, the bytes written to the WritableGridFileChannel will be appended to the end of the file. If false, the bytes will overwrite the original contents.
        Returns:
        a WritableGridFileChannel for writing to the file at pathname
        Throws:
        java.io.IOException - if an error occurs
      • getWritableChannel

        public WritableGridFileChannel getWritableChannel​(java.lang.String pathname,
                                                          boolean append,
                                                          int chunkSize)
                                                   throws java.io.IOException
        Opens a WritableGridFileChannel for writing to the file denoted by pathname.
        Parameters:
        pathname - the file to write to
        append - if true, the bytes written to the channel will be appended to the end of the file
        chunkSize - the size of the file's chunks. This parameter is honored only when the file at pathname does not yet exist. If the file already exists, the file's own chunkSize has precedence.
        Returns:
        a WritableGridFileChannel for writing to the file
        Throws:
        java.io.IOException - if the file is a directory, cannot be created or some other error occurs