Package libsidutils

Klasse IOUtils

java.lang.Object
libsidutils.IOUtils

public class IOUtils extends Object
This class provides general IO utility functions.
Autor:
Ken Händel
  • Felddetails

    • SEPARATOR

      private static final Pattern SEPARATOR
      Linux, OSX and ZIP entries use slash, Windows uses backslash.
    • COPY_BUFFER_CHUNK_SIZE

      private static final int COPY_BUFFER_CHUNK_SIZE
      Siehe auch:
    • BUFFER_LENGTH

      private static final int BUFFER_LENGTH
      Siehe auch:
  • Konstruktordetails

    • IOUtils

      public IOUtils()
  • Methodendetails

    • getCollectionName

      public static final String getCollectionName(File collectionRoot, File file)
      Create a filename of the given path relative to the collection root dir.
      e.g. "<root>/MUSICIANS/D/Daglish_Ben/Bombo.sid" -> "/MUSICIANS/D/Daglish_Ben/Bombo.sid"
      Parameter:
      collectionRoot - root file of the path
      file - file to get the relative path for
      Gibt zurück:
      relative path to the collection root file (empty string, if the path is not relative to the collection root file)
    • createFilename

      private static final String createFilename(List<File> files)
      Reverse function of getFiles(String, File, FileFilter).
      e.g. [File(D), File(Daglish_Ben), File(Bombo.sid)] -> "/MUSICIANS/D/Daglish_Ben/Bombo.sid"
      Parameter:
      files - file list to create a filename for
      Gibt zurück:
      filename filename where each path segment is delimited by a slash.
    • getFile

      public static final File getFile(String path, File hvscRoot, File cgscRoot)
      Get file for a given path. The path can be relative to HVSC or CGSC or even absolute.
      e.g. "<root>/MUSICIANS/D/Daglish_Ben/Bombo.sid" -> File(/MUSICIANS/D/Daglish_Ben/Bombo.sid)
      Parameter:
      path - path to get a file for, possible root directory can be either hvscRoot or cgscRoot or none, if absolute
      hvscRoot - root of HVSC
      cgscRoot - root of CGSC
      Gibt zurück:
      file of the path
    • getFiles

      public static final List<File> getFiles(String path, File rootFile, FileFilter fileFilter)
      Get the file list of the given file path. Each entry corresponds to a path segment. It is sorted from parent to child.
      e.g. "<root>/MUSICIANS/D/Daglish_Ben/Bombo.sid" -> [File(MUSICIANS), File(D), File(Daglish_Ben), File(Bombo.sid)]
      Parameter:
      path - file path to get the file list for. Each path segment is delimited by slash or backslash.
      rootFile - Root file to start. The first path segment must match a direct child of rootPath and so on.
      fileFilter - Files contained in the file filter are visible as child files (null means filter disabled)
      Gibt zurück:
      a file list sorted from the parent file to the child file (empty list, if the path is wrong or incomplete)
    • deleteDirectory

      public static final void deleteDirectory(File directory) throws IOException
      Delete directory and contained files and sub-directories.
      Parameter:
      directory - directory to delete
      Löst aus:
      IOException - error during delete
    • getFilenameWithoutSuffix

      public static final String getFilenameWithoutSuffix(String filename)
      Strip suffix of a filename.
      Parameter:
      filename - filename to get the suffix for
      Gibt zurück:
      filename without suffix (e.g. "Bombo.sid" -> "Bombo")
    • getFilenameSuffix

      public static final String getFilenameSuffix(String filename)
      Get suffix of a filename.
      Parameter:
      filename - filename to get the suffix for
      Gibt zurück:
      suffix of a filename (e.g. "Bombo.sid" -> ".sid")
    • addUpperCase

      public static List<String> addUpperCase(List<String> fileExtensions)
      Add upper case file extensions to the file extensions list.
      Parameter:
      fileExtensions - file extensions to add to
      Gibt zurück:
      file extensions with added upper case file extensions
    • getPhysicalSize

      public static String getPhysicalSize(long size)
      Get physical size in b, Kb, Mb, Gb or Tb.
      Parameter:
      size - size to calculate physical size for
      Gibt zurück:
      physical size
    • copy

      public static void copy(InputStream is, OutputStream os) throws IOException
      Fast file channel based copy.
      Parameter:
      is - input
      os - output
      Löst aus:
      IOException - I/O error
    • convertStreamToString

      public static String convertStreamToString(InputStream is, Charset charset)
      Convert InputStream to String using charset.
      Parameter:
      is - input
      charset - charset
      Gibt zurück:
      read string
    • convertStreamToString

      public static String convertStreamToString(InputStream is, Charset charset, Map<String,String> replacements)
      Convert InputStream to String using charset and replace strings on demand.
      Parameter:
      is - input
      charset - charset
      replacements - replacement strings
      Gibt zurück:
      read string
    • readAllBytes

      public static byte[] readAllBytes(InputStream is) throws IOException
      Read complete InputStream contents into byte array
      Parameter:
      is - input
      Gibt zurück:
      byte array
      Löst aus:
      IOException - I/O error
    • readNBytes

      public static int readNBytes(InputStream is, byte[] b, int off, int len) throws IOException
      Read specific amount of InputStream contents into byte array
      Parameter:
      is - input
      b - byte array
      off - offset in byte array
      len - number of bytes to read from input
      Gibt zurück:
      byte array
      Löst aus:
      IOException - I/O error
    • extract

      public static File extract(File baseDir, File inputFile) throws IOException
      Eventually extract file, if compressed (ZIP, GZIP, TAR, etc.), otherwise return same file.
      Parameter:
      baseDir - base directory to extract into a newly created sub-directory
      inputFile - input to extract
      Gibt zurück:
      extracted file or same file (if it was uncompressed)
      Löst aus:
      IOException - I/O error