org.kuali.common.util
Class LocationUtils

java.lang.Object
  extended by org.kuali.common.util.LocationUtils

public class LocationUtils
extends Object


Constructor Summary
LocationUtils()
           
 
Method Summary
static void copyLocationsToFiles(List<String> locations, List<File> files)
           
static void copyLocationToFile(String location, File destination)
           
static byte[] createChecksum(InputStream in, String algorithm)
           
static byte[] createChecksum(String location, String algorithm)
           
static boolean deleteFileQuietly(String filename)
          Null safe method to unconditionally attempt to delete filename without throwing an exception.
static boolean exists(File file)
          Null safe method for determining if location exists.
static boolean exists(String location)
          Null safe method for determining if location exists.
static void forceMkdir(File file)
           
static List<String> getAbsolutePaths(List<File> files)
           
static BufferedReader getBufferedReader(File file, String encoding)
          Return a BufferedReader that reads from file using the indicated encoding.
static BufferedReader getBufferedReader(InputStream in, String encoding)
          Return a BufferedReader that reads from in using the indicated encoding.
static BufferedReader getBufferedReader(String location)
          Return a BufferedReader for the location indicated using the platform default encoding.
static BufferedReader getBufferedReader(String location, String encoding)
          Return a BufferedReader for the location indicated using the encoding indicated.
static BufferedReader getBufferedReaderFromString(String s)
          Return a BufferedReader that reads from s
static String getCanonicalPath(File file)
           
static List<String> getCanonicalPaths(List<File> files)
           
static String getCanonicalURLString(File file)
           
static String getChecksum(byte[] bytes, String algorithm)
           
static String getChecksum(String location, String algorithm)
           
static String getClasspathFilename(String location)
          Return the text that appears after classpath:.
static List<String> getClasspathFilenames(List<String> locations)
          Return the text that appears after classpath:.
static String getFilename(String location)
           
static List<String> getFilenames(List<String> locations)
           
static File getFileQuietly(String filename)
          Null safe method for getting a File handle from filename.
static List<File> getFiles(File dir, List<String> filenames)
           
static InputStream getInputStream(String location)
          Open an InputStream to location.
static long getLineCount(File file)
          Count the lines of text in the file.
static long getLineCount(File file, String encoding)
           
static long getLineCount(String location)
          Deprecated. Use getLineCount(location,encoding) instead
static long getLineCount(String location, String encoding)
          Count the lines of text in the location.
static ComparisonResults getLocationListComparison(List<String> newLocations, List<String> originalLocations)
           
static Properties getLocationProperties(LocationPropertiesContext context)
           
static List<String> getLocations(List<String> locationListings)
           
static List<String> getLocations(List<String> locationListings, String encoding)
           
static List<String> getLocations(String locationListing)
           
static List<String> getLocations(String location, LocationType type)
           
static List<String> getLocations(String location, LocationType type, String encoding)
           
static List<String> getLocations(String locationListing, String encoding)
           
static String getMD5Checksum(File file)
          Get the MD5 checksum of the file
static String getMD5Checksum(String location)
          Get the MD5 checksum of the location
static String getNormalizedAbsolutePath(String absolutePath)
          Resolve and remove .. and . from absolutePath after converting any back slashes to forward slashes
static List<String> getNormalizedPathFragments(String absolutePath, boolean directory)
           
static org.springframework.core.io.Resource getResource(String location)
           
static TextMetaData getTextMetaData(File file)
           
static TextMetaData getTextMetaData(String location)
           
static String getURLString(File file)
           
static Writer getWriter(OutputStream out, String encoding)
          Return a Writer that writes to out using the indicated encoding.
static boolean isClasspathLocation(String location)
          Return true if location starts with classpath:
static boolean isExistingFile(String location)
          Null safe method for determining if location is an existing file.
static PrintStream openPrintStream(File file)
          Open a PrintStream to the indicated file.
static Writer openWriter(File file)
          Open a Writer to the indicated file.
static Writer openWriter(String location)
          Open a Writer to the location (It must be a writable file on the local file system).
static List<String> readLines(File file)
          Get the contents of file as a list of String's one entry per line using the platform default encoding
static List<String> readLines(String location)
          Get the contents of location as a list of String's one entry per line using the platform default encoding
static List<String> readLines(String location, String encoding)
          Get the contents of location as a list of String's one entry per line using the encoding indicated.
static List<String> readLinesAndClose(InputStream in)
           
static List<String> readLinesAndClose(InputStream in, String encoding)
           
static List<String> readLinesAndClose(Reader reader)
           
static List<String> readLinesFromString(String s)
          Get the contents of s as a list of String's one entry per line
static String toString(File file)
          Get the contents of file as a String using the platform's default character encoding.
static String toString(File file, String encoding)
          Get the contents of file as a String using the specified character encoding.
static String toString(String location)
          Get the contents of location as a String using the platform's default character encoding.
static String toString(String location, String encoding)
          Get the contents of location as a String using the specified character encoding.
static void touch(File file)
           
static void validateExists(List<String> locations)
           
static void validateLocation(String location)
          Throw IllegalArgumentException if the location does not exist
static void validateLocation(String location, String message)
          Throw IllegalArgumentException if the location does not exist
static void validateLocationListing(String locationListing)
          Throw IllegalArgumentException if the locationListing does not exist, or if any of the locations inside the locationListing do not exist
static void validateLocationListings(List<String> locationListings)
          Throw IllegalArgumentException if any of the locationListings do not exist, or if any of the locations inside any of the locationListings do not exist
static void validateLocations(List<String> locations)
           
static void validateNormalizedPath(String originalPath, String normalizedPath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocationUtils

public LocationUtils()
Method Detail

getMD5Checksum

public static String getMD5Checksum(String location)
Get the MD5 checksum of the location


getMD5Checksum

public static String getMD5Checksum(File file)
Get the MD5 checksum of the file


openPrintStream

public static final PrintStream openPrintStream(File file)
                                         throws IOException
Open a PrintStream to the indicated file. Parent directories are created if necessary.

Throws:
IOException

openWriter

public static final Writer openWriter(File file)
                               throws IOException
Open a Writer to the indicated file. Parent directories are created if necessary.

Throws:
IOException

openWriter

public static final Writer openWriter(String location)
                               throws IOException
Open a Writer to the location (It must be a writable file on the local file system). Parent directories are created if necessary.

Throws:
IOException

getLocationProperties

public static Properties getLocationProperties(LocationPropertiesContext context)

getTextMetaData

public static TextMetaData getTextMetaData(File file)

getTextMetaData

public static TextMetaData getTextMetaData(String location)

getLineCount

public static long getLineCount(File file)
Count the lines of text in the file.

Parameters:
file - The file to read lines of text from
Returns:
A count representing the number of lines of text
Throws:
IllegalStateException - If there is an i/o exception reading the file
See Also:
BufferedReader

getLineCount

public static long getLineCount(File file,
                                String encoding)

getLineCount

@Deprecated
public static long getLineCount(String location)
Deprecated. Use getLineCount(location,encoding) instead

Count the lines of text in the location.

Parameters:
location - The location to read lines of text from
Returns:
A count representing the number of lines of text
Throws:
IllegalStateException - If there is an i/o exception reading the file
See Also:
BufferedReader

getLineCount

public static long getLineCount(String location,
                                String encoding)
Count the lines of text in the location.

Parameters:
location - The location to read lines of text from
Returns:
A count representing the number of lines of text
Throws:
IllegalStateException - If there is an i/o exception reading the file
See Also:
BufferedReader

copyLocationsToFiles

public static final void copyLocationsToFiles(List<String> locations,
                                              List<File> files)

getClasspathFilename

public static final String getClasspathFilename(String location)
Return the text that appears after classpath:. Throws IllegalArgumentException if location does not start with classpath:


getClasspathFilenames

public static final List<String> getClasspathFilenames(List<String> locations)
Return the text that appears after classpath:. Throws IllegalArgumentException if any locations do not start with classpath:


isClasspathLocation

public static final boolean isClasspathLocation(String location)
Return true if location starts with classpath:


getNormalizedPathFragments

public static final List<String> getNormalizedPathFragments(String absolutePath,
                                                            boolean directory)

getCanonicalPaths

public static final List<String> getCanonicalPaths(List<File> files)

getLocations

public static final List<String> getLocations(String location,
                                              LocationType type,
                                              String encoding)

getLocations

public static final List<String> getLocations(String location,
                                              LocationType type)

getLocations

public static final List<String> getLocations(String locationListing)

getLocations

public static final List<String> getLocations(String locationListing,
                                              String encoding)

getLocations

public static final List<String> getLocations(List<String> locationListings)

copyLocationToFile

public static final void copyLocationToFile(String location,
                                            File destination)

getFiles

public static final List<File> getFiles(File dir,
                                        List<String> filenames)

getFilenames

public static final List<String> getFilenames(List<String> locations)

validateLocationListing

public static final void validateLocationListing(String locationListing)
Throw IllegalArgumentException if the locationListing does not exist, or if any of the locations inside the locationListing do not exist


validateLocationListings

public static final void validateLocationListings(List<String> locationListings)
Throw IllegalArgumentException if any of the locationListings do not exist, or if any of the locations inside any of the locationListings do not exist


validateLocations

public static final void validateLocations(List<String> locations)

validateLocation

public static final void validateLocation(String location)
Throw IllegalArgumentException if the location does not exist


validateLocation

public static final void validateLocation(String location,
                                          String message)
Throw IllegalArgumentException if the location does not exist


getLocations

public static final List<String> getLocations(List<String> locationListings,
                                              String encoding)

getCanonicalURLString

public static final String getCanonicalURLString(File file)

validateNormalizedPath

public static final void validateNormalizedPath(String originalPath,
                                                String normalizedPath)

getNormalizedAbsolutePath

public static final String getNormalizedAbsolutePath(String absolutePath)
Resolve and remove .. and . from absolutePath after converting any back slashes to forward slashes


getURLString

public static final String getURLString(File file)

forceMkdir

public static final void forceMkdir(File file)

touch

public static final void touch(File file)

getCanonicalPath

public static final String getCanonicalPath(File file)

deleteFileQuietly

public static final boolean deleteFileQuietly(String filename)
Null safe method to unconditionally attempt to delete filename without throwing an exception. If filename is a directory, delete it and all sub-directories.


getFileQuietly

public static final File getFileQuietly(String filename)
Null safe method for getting a File handle from filename. If filename is null, null is returned.


toString

public static final String toString(File file)
Get the contents of file as a String using the platform's default character encoding.


toString

public static final String toString(File file,
                                    String encoding)
Get the contents of file as a String using the specified character encoding.


toString

public static final String toString(String location)
Get the contents of location as a String using the platform's default character encoding.


toString

public static final String toString(String location,
                                    String encoding)
Get the contents of location as a String using the specified character encoding.


readLinesFromString

public static final List<String> readLinesFromString(String s)
Get the contents of s as a list of String's one entry per line


readLinesAndClose

public static final List<String> readLinesAndClose(InputStream in)

readLinesAndClose

public static final List<String> readLinesAndClose(InputStream in,
                                                   String encoding)

readLinesAndClose

public static final List<String> readLinesAndClose(Reader reader)

readLines

public static final List<String> readLines(File file)
Get the contents of file as a list of String's one entry per line using the platform default encoding


readLines

public static final List<String> readLines(String location)
Get the contents of location as a list of String's one entry per line using the platform default encoding


readLines

public static final List<String> readLines(String location,
                                           String encoding)
Get the contents of location as a list of String's one entry per line using the encoding indicated.


getBufferedReader

public static final BufferedReader getBufferedReader(String location)
                                              throws IOException
Return a BufferedReader for the location indicated using the platform default encoding.

Throws:
IOException

getBufferedReader

public static final BufferedReader getBufferedReader(String location,
                                                     String encoding)
                                              throws IOException
Return a BufferedReader for the location indicated using the encoding indicated.

Throws:
IOException

getBufferedReaderFromString

public static final BufferedReader getBufferedReaderFromString(String s)
Return a BufferedReader that reads from s


getWriter

public static final Writer getWriter(OutputStream out,
                                     String encoding)
                              throws IOException
Return a Writer that writes to out using the indicated encoding. null means use the platform's default encoding.

Throws:
IOException

getBufferedReader

public static final BufferedReader getBufferedReader(File file,
                                                     String encoding)
                                              throws IOException
Return a BufferedReader that reads from file using the indicated encoding. null means use the platform's default encoding.

Throws:
IOException

getBufferedReader

public static final BufferedReader getBufferedReader(InputStream in,
                                                     String encoding)
                                              throws IOException
Return a BufferedReader that reads from in using the indicated encoding. null means use the platform's default encoding.

Throws:
IOException

isExistingFile

public static final boolean isExistingFile(String location)
Null safe method for determining if location is an existing file.


exists

public static final boolean exists(File file)
Null safe method for determining if location exists.


validateExists

public static void validateExists(List<String> locations)

exists

public static final boolean exists(String location)
Null safe method for determining if location exists.


getInputStream

public static final InputStream getInputStream(String location)
                                        throws IOException
Open an InputStream to location. If location is the path to an existing File on the local file system, a FileInputStream is returned. Otherwise Spring's resource loading framework is used to open an InputStream to location.

Throws:
IOException

getResource

public static final org.springframework.core.io.Resource getResource(String location)

getFilename

public static final String getFilename(String location)

getAbsolutePaths

public static final List<String> getAbsolutePaths(List<File> files)

getLocationListComparison

public static final ComparisonResults getLocationListComparison(List<String> newLocations,
                                                                List<String> originalLocations)

getChecksum

public static String getChecksum(String location,
                                 String algorithm)

getChecksum

public static String getChecksum(byte[] bytes,
                                 String algorithm)

createChecksum

public static byte[] createChecksum(String location,
                                    String algorithm)

createChecksum

public static byte[] createChecksum(InputStream in,
                                    String algorithm)
                             throws IOException
Throws:
IOException


Copyright © 2010-2013 The Kuali Foundation. All Rights Reserved.