View Javadoc

1   /***
2    *     Ambient - A music player for the Android platform
3    Copyright (C) 2007 Martin Vysny
4    
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9    
10   This program 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
13   GNU General Public License for more details.
14  
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package sk.baka.ambient.collection;
20  
21  import java.io.File;
22  import java.io.FileInputStream;
23  import java.io.IOException;
24  import java.io.InputStream;
25  
26  import sk.baka.ambient.library.LibraryUtils;
27  
28  /***
29   * Denotes a file on the filesystem.
30   * 
31   * @author Martin Vysny
32   */
33  public final class FileAudio extends AbstractAudio {
34  	private final File file;
35  
36  	/***
37  	 * Creates new object instance.
38  	 * 
39  	 * @param uri
40  	 *            the file location.
41  	 */
42  	FileAudio(final String uri) {
43  		super(uri);
44  		file = new File(uri);
45  	}
46  
47  	@Override
48  	public boolean exists() {
49  		return file.exists();
50  	}
51  
52  	@Override
53  	public String getMimeType() {
54  		return LibraryUtils.getMime(file.getName());
55  	}
56  
57  	@Override
58  	public boolean isReadable() {
59  		return LibraryUtils.TRACK_FILTER.accept(file);
60  	}
61  
62  	@Override
63  	public InputStream openInputStream() throws IOException {
64  		return new FileInputStream(file);
65  	}
66  
67  	@Override
68  	public long getSize() {
69  		return file.length();
70  	}
71  }