1 /* 2 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * - Redistribution of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * - Redistribution in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * Neither the name of Sun Microsystems, Inc. or the names of 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * This software is provided "AS IS," without a warranty of any kind. ALL 20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN 23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR 24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR 25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR 26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR 27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE 28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, 29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF 30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 31 * 32 * You acknowledge that this software is not designed or intended for use 33 * in the design, construction, operation or maintenance of any nuclear 34 * facility. 35 * 36 * Sun gratefully acknowledges that this software was originally authored 37 * and developed by Kenneth Bradley Russell and Christopher John Kline. 38 */ 39 40 package com.sun.opengl.util; 41 42 import java.io.*; 43 44 /** Utilities for dealing with files. */ 45 46 public class FileUtil { FileUtil()47 private FileUtil() {} 48 49 /** 50 * Returns the lowercase suffix of the given file name (the text 51 * after the last '.' in the file name). Returns null if the file 52 * name has no suffix. Only operates on the given file name; 53 * performs no I/O operations. 54 * 55 * @param file name of the file 56 * @return lowercase suffix of the file name 57 * @throws NullPointerException if file is null 58 */ 59 getFileSuffix(File file)60 public static String getFileSuffix(File file) { 61 return getFileSuffix(file.getName()); 62 } 63 64 /** 65 * Returns the lowercase suffix of the given file name (the text 66 * after the last '.' in the file name). Returns null if the file 67 * name has no suffix. Only operates on the given file name; 68 * performs no I/O operations. 69 * 70 * @param filename name of the file 71 * @return lowercase suffix of the file name 72 * @throws NullPointerException if filename is null 73 */ getFileSuffix(String filename)74 public static String getFileSuffix(String filename) { 75 int lastDot = filename.lastIndexOf('.'); 76 if (lastDot < 0) { 77 return null; 78 } 79 return toLowerCase(filename.substring(lastDot + 1)); 80 } 81 toLowerCase(String arg)82 private static String toLowerCase(String arg) { 83 if (arg == null) { 84 return null; 85 } 86 87 return arg.toLowerCase(); 88 } 89 } 90