com.sun.enterprise.universal.io
Class SmartFile

java.lang.Object
  extended by com.sun.enterprise.universal.io.SmartFile

public class SmartFile
extends java.lang.Object

A class for sanitizing Files. Note that the main reason for this class is that on non-Windows, getCanonicalXXX and getAbsoluteXXX might point at different files. If the file is a soft link then the Canonical will be the file that is linked to. The Absolute will be the link file itself. This method will give you the benefits of Canonical -- but will always point at the link file itself. Windows is horribly complex compared to "everything else". Windows does not have the symbolic link issue -- so use getCanonicalXXX to do the work on Windows. Windows will return paths with all forward slashes -- no backward slashes unless it is the special Windows network address that starts with "\\"

I.e. It is just like getAbsoluteXXX -- but it removes all relative path elements from the path.

Author:
bnevins

Method Summary
static java.io.File sanitize(java.io.File f)
          Sanitize a File object -- remove all relative path portions, i.e.
static java.lang.String sanitize(java.lang.String filename)
          Sanitize a path -- remove all relative path portions, i.e.
static java.lang.String sanitizePaths(java.lang.String pathsString)
          Sanitize a "Classpath-like" list of Paths.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sanitize

public static java.io.File sanitize(java.io.File f)
Sanitize a File object -- remove all relative path portions, i.e. dots e.g. "/xxx/yyy/././././../yyy" --> /xxx/yyy on UNIX, perhaps C:/xxx/yyy on Windows

Parameters:
f - The file to sanitize
Returns:
THe sanitized File

sanitize

public static java.lang.String sanitize(java.lang.String filename)
Sanitize a path -- remove all relative path portions, i.e. dots e.g. "/xxx/yyy/././././../yyy" --> /xxx/yyy on UNIX, perhaps C:/xxx/yyy on Windows Note that the main reason for this class is that on non-Windows, getCanonicalXXX and getAbsoluteXXX might point at different files. If the file is a soft link then the Canonical will be the file that is linked to. The Absolute will be the link file itself. This method will give you the benefits of Canonical -- but will always point at the link file path itself.

Parameters:
filename - The path to sanitize
Returns:
The sanitized path

sanitizePaths

public static java.lang.String sanitizePaths(java.lang.String pathsString)
Sanitize a "Classpath-like" list of Paths.

Parameters:
pathsString - A string of paths, each separated by File.pathSeparator
Returns:
The sanitized paths


Copyright © 2012 GlassFish Community. All Rights Reserved.