Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.rgw.io
Class FileTool

java.lang.Object
  extended by ch.rgw.io.FileTool

public class FileTool
extends java.lang.Object

Author:
Gerry TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates

Field Summary
static int BACKUP_IF_EXISTS
           
static java.lang.String DIRECTORY_SEPARATOR
           
static int FAIL_IF_EXISTS
           
static int REPLACE_IF_EXISTS
           
static java.lang.String ZIP_EXTENSION
           
 
Constructor Summary
FileTool()
           
 
Method Summary
static byte[] asJar(java.lang.String directoryPath)
          Returns a directory (and all subdirectories) as jar
static void checkCreatePath(java.lang.String path)
          Ueberprueft, ob Verzeichnis existiert.
static byte[] checksum(java.io.File file)
          TODO: Kommentar
static void copyDirectory(java.io.File srcDir, java.io.File dstDir)
          Copies all files under srcDir to dstDir.
static boolean copyFile(java.io.File src, java.io.File dest, int if_exists)
          Kopiert Datei src nach dest .
static void copyStreams(java.io.InputStream is, java.io.OutputStream os)
          Kopiert Stream von
static byte[] copyStreamsWithChecksum(java.io.InputStream is, java.io.OutputStream os, java.lang.String algo)
          Kopiert Streams und erstellt MD5-Checksumme.
static boolean deleteFile(java.lang.String filePathName)
          Loescht Datei
static boolean deltree(java.lang.String d)
          Delete a directory with all of its contents and subcontents
static boolean doesFileExist(java.lang.String filePathName)
          Ueberprueft, ob eine Datei existiert
static java.lang.String getBasePath(java.lang.Class clazz)
          Gibt das Basisverzeichnis von clazz resp. des Jars, in dem diese Klasse sich befindet zurück.
static java.lang.String getClassPath(java.lang.Class clazz)
          Retourniert Verzeichnis einer Klasse
static java.lang.String getCorrectPath(java.lang.String path)
          Ueberprueft ob Verzeichnis korrekt ist.
static java.lang.String getExtension(java.lang.String name)
          Retourniert Dateiendung (mit Punkt).
static java.lang.String getFilename(java.lang.String filenamePath)
          Retourniert Dateinamen ohne Pfad als String
static java.lang.String getFilepath(java.lang.String filenamePath)
          Retourniert Pfad ohne Dateinamen als String
static java.lang.String getNakedFilename(java.lang.String filenamePath)
          Retourniert Dateinamen ohne Pfad und Endung.
static boolean isRootDir(java.lang.String dir)
          Ueberprueft, ob es sich um ein absolutes Verzeichnis handelt
static byte[] readFile(java.io.File file)
          Liest binaere Datei.
static java.lang.String readTextFile(java.io.File file)
          Liest Text Datei
static java.lang.String readTextFile(java.io.File file, java.lang.String charsetName)
          Liest Text Datei
static byte[] readZippedFile(java.lang.String filenamePath)
          Liest gezippte Datei
static java.io.File resolveFile(java.lang.String filepath)
          TODO: Kommentar
static void unjar(java.lang.String filenamePath)
          Unzips a file in the file directory
static void unzip(java.lang.String filenamePath)
          doesn't work because it depends on same DIRECTORY_SEPARATORs in zipper and unzipper Unzips a file in the file directory
static java.lang.String Version()
           
static void writeFile(java.io.File file, byte[] daten)
          Schreibt binaere Datei
static void writeTextFile(java.io.File file, java.lang.String text)
          Schreibt Text Datei
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTORY_SEPARATOR

public static java.lang.String DIRECTORY_SEPARATOR

ZIP_EXTENSION

public static final java.lang.String ZIP_EXTENSION
See Also:
Constant Field Values

REPLACE_IF_EXISTS

public static final int REPLACE_IF_EXISTS
See Also:
Constant Field Values

BACKUP_IF_EXISTS

public static final int BACKUP_IF_EXISTS
See Also:
Constant Field Values

FAIL_IF_EXISTS

public static final int FAIL_IF_EXISTS
See Also:
Constant Field Values
Constructor Detail

FileTool

public FileTool()
Method Detail

Version

public static java.lang.String Version()

getFilepath

public static java.lang.String getFilepath(java.lang.String filenamePath)
Retourniert Pfad ohne Dateinamen als String


getFilename

public static java.lang.String getFilename(java.lang.String filenamePath)
Retourniert Dateinamen ohne Pfad als String


getNakedFilename

public static java.lang.String getNakedFilename(java.lang.String filenamePath)
Retourniert Dateinamen ohne Pfad und Endung. Falls keine Endung vorhanden ist, wird der Dateinamen retourniert.


getExtension

public static java.lang.String getExtension(java.lang.String name)
Retourniert Dateiendung (mit Punkt). Falls keine Endung gefunden wird, wird ein leerer String retourniert.


checkCreatePath

public static void checkCreatePath(java.lang.String path)
                            throws java.lang.IllegalArgumentException
Ueberprueft, ob Verzeichnis existiert. Falls nicht, wird probiert, das Verzeichnis zu erstellen.

Parameters:
path - , darf nicht null sein.
Throws:
java.lang.IllegalArgumentException

getCorrectPath

public static java.lang.String getCorrectPath(java.lang.String path)
                                       throws java.lang.IllegalArgumentException
Ueberprueft ob Verzeichnis korrekt ist. Falls nicht, wird das Verzeichnis korrigiert und retourniert.

Parameters:
path - oder null
Throws:
java.lang.IllegalArgumentException

doesFileExist

public static boolean doesFileExist(java.lang.String filePathName)
Ueberprueft, ob eine Datei existiert


isRootDir

public static boolean isRootDir(java.lang.String dir)
Ueberprueft, ob es sich um ein absolutes Verzeichnis handelt


deleteFile

public static boolean deleteFile(java.lang.String filePathName)
                          throws java.lang.IllegalArgumentException
Loescht Datei

Parameters:
filePathName - Kompletter Filename mit Pfad
Returns:
true wenn geloescht, sonst false
Throws:
java.lang.IllegalArgumentException

readZippedFile

public static byte[] readZippedFile(java.lang.String filenamePath)
                             throws java.io.IOException
Liest gezippte Datei

Throws:
java.io.IOException

getBasePath

public static java.lang.String getBasePath(java.lang.Class clazz)
Gibt das Basisverzeichnis von clazz resp. des Jars, in dem diese Klasse sich befindet zurück. Holt hierfür die URL der Klass und unterscheidet folgende Fälle: jar:file://netzlaufwerk/pfad/MyApp.jar file://netzlaufwerk/pfad/MyApp.class jar:file:/X:/pfad/MyApp.jar file://X:/pfad/MyApp.class


getClassPath

public static java.lang.String getClassPath(java.lang.Class clazz)
Retourniert Verzeichnis einer Klasse


copyFile

public static boolean copyFile(java.io.File src,
                               java.io.File dest,
                               int if_exists)
Kopiert Datei

src

nach

dest

.

Parameters:
src - Quelldatei
dest - Zieldatei
if_exists -
  • REPLACE_IF_EXISTS
  • BACKUP_IF_EXISTS
  • FAIL_IF_EXISTS
  • Returns:

    copyStreams

    public static void copyStreams(java.io.InputStream is,
                                   java.io.OutputStream os)
                            throws java.io.IOException
    Kopiert Stream von

    Parameters:
    is -
    os -
    Throws:
    java.io.IOException

    copyStreamsWithChecksum

    public static byte[] copyStreamsWithChecksum(java.io.InputStream is,
                                                 java.io.OutputStream os,
                                                 java.lang.String algo)
                                          throws java.io.IOException
    Kopiert Streams und erstellt MD5-Checksumme. Streams werden nicht geschlossen, aber output wird geflusht.

    Throws:
    java.io.IOException

    readFile

    public static byte[] readFile(java.io.File file)
                           throws java.io.IOException
    Liest binaere Datei. Vorsicht bei grossen Dateien. Diese koennen zu einem OutOfMemory Error fuehren. Grosse Dateien sollten wenn moeglich in einzelnen Bloecken (InputStream) gelesen werden.

    Throws:
    java.io.IOException

    readTextFile

    public static java.lang.String readTextFile(java.io.File file)
                                         throws java.io.IOException
    Liest Text Datei

    Throws:
    java.io.IOException

    readTextFile

    public static java.lang.String readTextFile(java.io.File file,
                                                java.lang.String charsetName)
                                         throws java.io.IOException
    Liest Text Datei

    Throws:
    java.io.IOException

    writeFile

    public static void writeFile(java.io.File file,
                                 byte[] daten)
                          throws java.io.IOException
    Schreibt binaere Datei

    Throws:
    java.io.IOException

    writeTextFile

    public static void writeTextFile(java.io.File file,
                                     java.lang.String text)
                              throws java.io.IOException
    Schreibt Text Datei

    Throws:
    java.io.IOException

    deltree

    public static boolean deltree(java.lang.String d)
    Delete a directory with all of its contents and subcontents

    Parameters:
    Directory - to Delete
    Returns:
    true if successful, otherwise false

    resolveFile

    public static java.io.File resolveFile(java.lang.String filepath)
    TODO: Kommentar


    checksum

    public static byte[] checksum(java.io.File file)
    TODO: Kommentar

    Parameters:
    file -
    Returns:

    unzip

    public static final void unzip(java.lang.String filenamePath)
                            throws java.io.IOException
    doesn't work because it depends on same DIRECTORY_SEPARATORs in zipper and unzipper Unzips a file in the file directory

    Throws:
    java.io.IOException

    unjar

    public static final void unjar(java.lang.String filenamePath)
                            throws java.io.IOException
    Unzips a file in the file directory

    Throws:
    java.io.IOException

    asJar

    public static byte[] asJar(java.lang.String directoryPath)
                        throws java.io.IOException
    Returns a directory (and all subdirectories) as jar

    Throws:
    java.io.IOException

    copyDirectory

    public static void copyDirectory(java.io.File srcDir,
                                     java.io.File dstDir)
                              throws java.io.IOException
    Copies all files under srcDir to dstDir. If dstDir does not exist, it will be created.

    Throws:
    java.io.IOException

    Elexis API documentation
    Version 2.1.6 as of December 11 2011

    Copyright 2005-2011 by Gerry Weirich, Elexis