utils
Class FileUtils

java.lang.Object
  extended by utils.FileUtils

public final class FileUtils
extends java.lang.Object

Version:
1.0
Author:
Oscar Flores

Constructor Summary
FileUtils()
           
 
Method Summary
static void copyFromJAR(java.lang.String fromStr, java.lang.String toFile)
          Copies from one file to another
static java.lang.String escapeFilename(java.lang.String s)
           
static java.nio.charset.Charset getCharset(java.io.File f)
          Naive charset autodetector.
static java.lang.String getExtension(java.io.File f)
          Returns the extension (last string after the ".") of a file
static javax.swing.filechooser.FileFilter getFileFilter(java.lang.String extension, java.lang.String description)
          Returns a custom FileFilter that accepts the files with the given extension
static javax.swing.ImageIcon getImage(java.lang.String imgPath)
          Returns an image inside "img" folder
static java.lang.String getNameNoExtension(java.io.File f)
          Returns the name (the string before the ".") of a file
static java.lang.String showFileChooseSave(java.lang.String[] allowedFormats, java.lang.String title)
          Shows a JFileChooser and let the user choose one of the formats passed to the function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

getExtension

public static java.lang.String getExtension(java.io.File f)
Returns the extension (last string after the ".") of a file

Parameters:
f - File
Returns:
the extension of file

getNameNoExtension

public static java.lang.String getNameNoExtension(java.io.File f)
Returns the name (the string before the ".") of a file

Parameters:
f - File
Returns:
the name of file

getCharset

public static java.nio.charset.Charset getCharset(java.io.File f)
Naive charset autodetector. It just tries to identify a file with an standard UTF-8 charset or mark it as ISO-8859-1

Parameters:
f - File to be identified
Returns:
The identified charset

escapeFilename

public static java.lang.String escapeFilename(java.lang.String s)

showFileChooseSave

public static java.lang.String showFileChooseSave(java.lang.String[] allowedFormats,
                                                  java.lang.String title)
Shows a JFileChooser and let the user choose one of the formats passed to the function. The formats is a n*2 positions array, for n allowed Formats. position i*2 contains the extension of the format (ie, "jpg") the position i*2+1 contains the description of the file (ie, "JPEG Image"). If this array is null, it accepts all the files

Parameters:
allowedFormats - Array with the extension and descriptions.
title - Title of the dialog
Returns:
path to the file or null if something's gone wrong

getFileFilter

public static javax.swing.filechooser.FileFilter getFileFilter(java.lang.String extension,
                                                               java.lang.String description)
Returns a custom FileFilter that accepts the files with the given extension

Parameters:
extension - Extension of the file to accept, without dot
description - Description of this file type
Returns:
the customized FileFilter

copyFromJAR

public static void copyFromJAR(java.lang.String fromStr,
                               java.lang.String toFile)
                        throws java.io.IOException
Copies from one file to another

Parameters:
fromFileName -
toFileName -
Throws:
java.io.IOException

getImage

public static javax.swing.ImageIcon getImage(java.lang.String imgPath)
Returns an image inside "img" folder

Parameters:
imgPath - path of the image inside "img" folder
Returns:
Loaded image