org.apache.sysds.runtime.util

## Class LocalFileUtils

- java.lang.Object
- - org.apache.sysds.runtime.util.LocalFileUtils

-     public class LocalFileUtils
      extends Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BUFFER_SIZE`
    `static String` | `CATEGORY_CACHE`
    `static String` | `CATEGORY_CODEGEN`
    `static String` | `CATEGORY_LINEAGE`
    `static String` | `CATEGORY_PARTITIONING`
    `static String` | `CATEGORY_RESULTMERGE`
    `static String` | `CATEGORY_WORK`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LocalFileUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `checkAndCreateStagingDir(String dir)`
    `static int` | `cleanupRcWorkingDirectory(String dir)`
    `static void` | `cleanupWorkingDirectory()`
    `static void` | `cleanupWorkingDirectory(String dir)`
    `static boolean` | `createLocalFileIfNotExist(String dir)`
    `static boolean` | `createLocalFileIfNotExist(String dir, String permission)`
    `static String` | `createWorkingDirectory()`
    `static String` | `createWorkingDirectoryWithUUID(String uuid)`
    `static void` | `deleteFileIfExists(String dir)`
    `static void` | `deleteFileIfExists(String dir, boolean fileOnly)`
    `static String` | `getUniqueWorkingDir(String category)`
    `static String` | `getWorkingDir(String category)`
    `static boolean` | `isExisting(String dir)`
    `static int` | `rcDelete(File dir)` Recursively deletes an entire local file system directory and returns the number of files deleted.
    `static void` | `rDelete(File dir)` Recursively deletes an entire local file system directory.
    `static int` | `readBlockSequenceFromLocal(String fname, Pair<MatrixIndexes,MatrixValue>[] outValues, HashMap<MatrixIndexes,Integer> outMap)`
    `static CacheBlock` | `readCacheBlockFromLocal(String fname, boolean matrix)` Reads a matrix/frame block from local file system.
    `static FrameBlock` | `readFrameBlockFromLocal(String fname)` Reads a frame block from local file system.
    `static FrameBlock` | `readFrameBlockFromStream(InputStream is)` Reads a frame block from an input stream, using a fused buffered reader with special support for matrix blocks.
    `static MatrixBlock` | `readMatrixBlockFromLocal(String fname)` Reads a matrix block from local file system.
    `static MatrixBlock` | `readMatrixBlockFromLocal(String fname, MatrixBlock reuse)` Reads a matrix block from local file system.
    `static MatrixBlock` | `readMatrixBlockFromStream(InputStream is)` Reads a matrix block from an input stream, using a fused buffered reader with special support for matrix blocks.
    `static org.apache.hadoop.io.Writable` | `readWritableFromLocal(String fname, org.apache.hadoop.io.Writable ret)` Reads an arbitrary writable from local file system, using a fused buffered reader with special support for matrix blocks.
    `static org.apache.hadoop.io.Writable` | `readWritableFromStream(InputStream is, org.apache.hadoop.io.Writable ret)` Reads an arbitrary writable from an input stream, using a fused buffered reader with special support for matrix blocks.
    `static void` | `setLocalFilePermissions(File file, String permissions)`
    `static void` | `writeBlockSequenceToLocal(String fname, Pair<MatrixIndexes,MatrixValue>[] inValues, int len)`
    `static void` | `writeByteArrayToLocal(String fname, byte[] data)`
    `static void` | `writeCacheBlockToLocal(String fname, CacheBlock cb)` Writes a matrix/frame block to local file system.
    `static void` | `writeFrameBlockToLocal(String fname, FrameBlock fb)` Writes a frame block to local file system.
    `static void` | `writeMatrixBlockToLocal(String fname, MatrixBlock mb)` Writes a matrix block to local file system.
    `static void` | `writeTextFile(File file, String text)` Writes a simple text file to local file system.
    `static void` | `writeWritableToLocal(String fname, org.apache.hadoop.io.Writable mb)` Writes an arbitrary writable to local file system, using a fused buffered writer with special support for matrix blocks.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BUFFER_SIZE

          public static final int BUFFER_SIZE

      See Also:
        Constant Field Values

    - #### CATEGORY_CACHE

          public static final String CATEGORY_CACHE

      See Also:
        Constant Field Values

    - #### CATEGORY_PARTITIONING

          public static final String CATEGORY_PARTITIONING

      See Also:
        Constant Field Values

    - #### CATEGORY_RESULTMERGE

          public static final String CATEGORY_RESULTMERGE

      See Also:
        Constant Field Values

    - #### CATEGORY_WORK

          public static final String CATEGORY_WORK

      See Also:
        Constant Field Values

    - #### CATEGORY_CODEGEN

          public static final String CATEGORY_CODEGEN

      See Also:
        Constant Field Values

    - #### CATEGORY_LINEAGE

          public static final String CATEGORY_LINEAGE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LocalFileUtils

          public LocalFileUtils()

  - ### Method Detail

    - #### readMatrixBlockFromLocal

          public static MatrixBlock readMatrixBlockFromLocal(String fname)
                                                      throws IOException

      Reads a matrix block from local file system.
      Parameters:
        `fname` - file name to read
      Returns:
        matrix block
      Throws:
        `IOException` - if IOException occurs

    - #### readMatrixBlockFromLocal

          public static MatrixBlock readMatrixBlockFromLocal(String fname,
                                                             MatrixBlock reuse)
                                                      throws IOException

      Reads a matrix block from local file system.
      Parameters:
        `fname` - file name to read
        `reuse` - matrix block to reuse
      Returns:
        matrix block
      Throws:
        `IOException` - if IOException occurs

    - #### readFrameBlockFromLocal

          public static FrameBlock readFrameBlockFromLocal(String fname)
                                                    throws IOException

      Reads a frame block from local file system.
      Parameters:
        `fname` - file name to read
      Returns:
        frame block
      Throws:
        `IOException` - if IOException occurs

    - #### readCacheBlockFromLocal

          public static CacheBlock readCacheBlockFromLocal(String fname,
                                                           boolean matrix)
                                                    throws IOException

      Reads a matrix/frame block from local file system.
      Parameters:
        `fname` - file name to read
        `matrix` - if true, read matrix. if false, read frame.
      Returns:
        cache block (common interface to MatrixBlock and FrameBlock)
      Throws:
        `IOException` - if IOException occurs

    - #### readWritableFromLocal

          public static org.apache.hadoop.io.Writable readWritableFromLocal(String fname,
                                                                            org.apache.hadoop.io.Writable ret)
                                                                     throws IOException

      Reads an arbitrary writable from local file system, using a fused buffered reader with special support for matrix blocks.
      Parameters:
        `fname` - file name to read
        `ret` - hadoop writable
      Returns:
        hadoop writable
      Throws:
        `IOException` - if IOException occurs

    - #### readMatrixBlockFromStream

          public static MatrixBlock readMatrixBlockFromStream(InputStream is)
                                                       throws IOException

      Reads a matrix block from an input stream, using a fused buffered reader with special support for matrix blocks.
      Parameters:
        `is` - input stream to read
      Returns:
        matrix block
      Throws:
        `IOException` - if IOException occurs

    - #### readFrameBlockFromStream

          public static FrameBlock readFrameBlockFromStream(InputStream is)
                                                     throws IOException

      Reads a frame block from an input stream, using a fused buffered reader with special support for matrix blocks.
      Parameters:
        `is` - input stream to read
      Returns:
        frame block
      Throws:
        `IOException` - if IOException occurs

    - #### readWritableFromStream

          public static org.apache.hadoop.io.Writable readWritableFromStream(InputStream is,
                                                                             org.apache.hadoop.io.Writable ret)
                                                                      throws IOException

      Reads an arbitrary writable from an input stream, using a fused buffered reader with special support for matrix blocks.
      Parameters:
        `is` - input stream to read
        `ret` - hadoop writable
      Returns:
        hadoop writable
      Throws:
        `IOException` - if IOException occurs

    - #### writeMatrixBlockToLocal

          public static void writeMatrixBlockToLocal(String fname,
                                                     MatrixBlock mb)
                                              throws IOException

      Writes a matrix block to local file system.
      Parameters:
        `fname` - file name to write
        `mb` - matrix block
      Throws:
        `IOException` - if IOException occurs

    - #### writeFrameBlockToLocal

          public static void writeFrameBlockToLocal(String fname,
                                                    FrameBlock fb)
                                             throws IOException

      Writes a frame block to local file system.
      Parameters:
        `fname` - file name to write
        `fb` - fame block
      Throws:
        `IOException` - if IOException occurs

    - #### writeCacheBlockToLocal

          public static void writeCacheBlockToLocal(String fname,
                                                    CacheBlock cb)
                                             throws IOException

      Writes a matrix/frame block to local file system.
      Parameters:
        `fname` - file name to write
        `cb` - cache block (common interface to matrix block and frame block)
      Throws:
        `IOException` - if IOException occurs

    - #### writeWritableToLocal

          public static void writeWritableToLocal(String fname,
                                                  org.apache.hadoop.io.Writable mb)
                                           throws IOException

      Writes an arbitrary writable to local file system, using a fused buffered writer with special support for matrix blocks.
      Parameters:
        `fname` - file name to write
        `mb` - Hadoop writable
      Throws:
        `IOException` - if IOException occurs

    - #### writeByteArrayToLocal

          public static void writeByteArrayToLocal(String fname,
                                                   byte[] data)
                                            throws IOException

      Throws:
        `IOException`

    - #### readBlockSequenceFromLocal

          public static int readBlockSequenceFromLocal(String fname,
                                                       Pair<MatrixIndexes,MatrixValue>[] outValues,
                                                       HashMap<MatrixIndexes,Integer> outMap)
                                                throws IOException

      Throws:
        `IOException`

    - #### writeBlockSequenceToLocal

          public static void writeBlockSequenceToLocal(String fname,
                                                       Pair<MatrixIndexes,MatrixValue>[] inValues,
                                                       int len)
                                                throws IOException

      Throws:
        `IOException`

    - #### createLocalFileIfNotExist

          public static boolean createLocalFileIfNotExist(String dir)

    - #### deleteFileIfExists

          public static void deleteFileIfExists(String dir)

    - #### deleteFileIfExists

          public static void deleteFileIfExists(String dir,
                                                boolean fileOnly)

    - #### isExisting

          public static boolean isExisting(String dir)

    - #### createLocalFileIfNotExist

          public static boolean createLocalFileIfNotExist(String dir,
                                                          String permission)

    - #### setLocalFilePermissions

          public static void setLocalFilePermissions(File file,
                                                     String permissions)

    - #### checkAndCreateStagingDir

          public static String checkAndCreateStagingDir(String dir)

    - #### createWorkingDirectory

          public static String createWorkingDirectory()

    - #### createWorkingDirectoryWithUUID

          public static String createWorkingDirectoryWithUUID(String uuid)

    - #### cleanupWorkingDirectory

          public static void cleanupWorkingDirectory()

    - #### cleanupWorkingDirectory

          public static void cleanupWorkingDirectory(String dir)

    - #### cleanupRcWorkingDirectory

          public static int cleanupRcWorkingDirectory(String dir)

    - #### rDelete

          public static void rDelete(File dir)

      Recursively deletes an entire local file system directory.
      Parameters:
        `dir` - directory to delete recursively

    - #### rcDelete

          public static int rcDelete(File dir)

      Recursively deletes an entire local file system directory and returns the number of files deleted.
      Parameters:
        `dir` - directory to delete recursively
      Returns:
        number of files deleted

    - #### getWorkingDir

          public static String getWorkingDir(String category)

    - #### getUniqueWorkingDir

          public static String getUniqueWorkingDir(String category)

    - #### writeTextFile

          public static void writeTextFile(File file,
                                           String text)
                                    throws IOException

      Writes a simple text file to local file system.
      Parameters:
        `file` - output file
        `text` - content of text file
      Throws:
        `IOException` - errors in file open/write/close

Copyright © 2020 The Apache Software Foundation. All rights reserved.