| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AudioFileFilter |
|
| 4.0;4 |
| 1 | /* | |
| 2 | * Entagged Audio Tag library | |
| 3 | * Copyright (c) 2003-2005 Raphaƫl Slinckx <raphael@slinckx.net> | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This library is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this library; if not, write to the Free Software | |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 18 | */ | |
| 19 | package org.jaudiotagger.audio; | |
| 20 | ||
| 21 | import org.jaudiotagger.audio.generic.Utils; | |
| 22 | ||
| 23 | import java.io.FileFilter; | |
| 24 | import java.io.File; | |
| 25 | ||
| 26 | /** | |
| 27 | * <p>This is a simple FileFilter that will only allow the file supported by this library.</p> | |
| 28 | * <p>It will also accept directories. An additional condition is that file must be readable (read permission) and | |
| 29 | * are not hidden (dot files, or hidden files)</p> | |
| 30 | * | |
| 31 | * @author Raphael Slinckx | |
| 32 | * @version $Id: AudioFileFilter.java 836 2009-11-12 15:44:07Z paultaylor $ | |
| 33 | * @since v0.01 | |
| 34 | */ | |
| 35 | public class AudioFileFilter implements FileFilter | |
| 36 | { | |
| 37 | /** | |
| 38 | * allows Directories | |
| 39 | */ | |
| 40 | private final boolean allowDirectories; | |
| 41 | ||
| 42 | public AudioFileFilter( boolean allowDirectories) | |
| 43 | 4 | { |
| 44 | 4 | this.allowDirectories=allowDirectories; |
| 45 | 4 | } |
| 46 | ||
| 47 | public AudioFileFilter() | |
| 48 | { | |
| 49 | 4 | this(true); |
| 50 | 4 | } |
| 51 | ||
| 52 | /** | |
| 53 | * <p>Check whether the given file meet the required conditions (supported by the library OR directory). | |
| 54 | * The File must also be readable and not hidden.</p> | |
| 55 | * | |
| 56 | * @param f The file to test | |
| 57 | * @return a boolean indicating if the file is accepted or not | |
| 58 | */ | |
| 59 | public boolean accept(File f) | |
| 60 | { | |
| 61 | 40 | if (f.isHidden() || !f.canRead()) |
| 62 | { | |
| 63 | 0 | return false; |
| 64 | } | |
| 65 | ||
| 66 | 40 | if (f.isDirectory()) |
| 67 | { | |
| 68 | 0 | return allowDirectories; |
| 69 | } | |
| 70 | ||
| 71 | 40 | String ext = Utils.getExtension(f); |
| 72 | ||
| 73 | try | |
| 74 | { | |
| 75 | 40 | if (SupportedFileFormat.valueOf(ext.toUpperCase()) != null) |
| 76 | { | |
| 77 | 32 | return true; |
| 78 | } | |
| 79 | } | |
| 80 | 8 | catch(IllegalArgumentException iae) |
| 81 | { | |
| 82 | //Not known enum value | |
| 83 | 8 | return false; |
| 84 | 0 | } |
| 85 | 0 | return false; |
| 86 | } | |
| 87 | } |