sk.baka.ambient.lrc
Class LRCStorage

java.lang.Object
  extended by sk.baka.ambient.commons.AbstractFileStorage
      extended by sk.baka.ambient.lrc.LRCStorage

public final class LRCStorage
extends AbstractFileStorage

Storage for downloaded LRC files.

Author:
Martin Vysny

Field Summary
 
Fields inherited from class sk.baka.ambient.commons.AbstractFileStorage
maxStorageSize, theCache
 
Constructor Summary
LRCStorage()
          Creates new LRC storage.
 
Method Summary
 void deleteLyrics(TrackMetadataBean track)
          Deletes lyrics for given track.
protected  String[] getFilenameAndExt(URL url, Object fetchInfo)
          Retrieves target file name.
 LRCLyrics getLyrics(TrackMetadataBean track)
          Fetches the lyrics for a track and returns it.
protected  void onFileDownloaded(URL url, Object fetchInfo, boolean success)
          The file was downloaded and is already registered in the storage.
 void setLyricsForTrack(TrackMetadataBean track, LyrdbTrack lyrics)
          Sets preferred lyrics for given track.
protected  URL toURL(Object fetchInfo)
          Converts given fetch info to an URL object.
 
Methods inherited from class sk.baka.ambient.commons.AbstractFileStorage
cleanup, close, createFile, fetchFileAsync, getCacheFile, getCacheFileNull, getFile, getNames, isFull, isProceedWithDownload, purge, registerFile, removeFile, setMaxStorageSize, supportsExtension
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LRCStorage

public LRCStorage()
Creates new LRC storage.

Method Detail

getFilenameAndExt

protected String[] getFilenameAndExt(URL url,
                                     Object fetchInfo)
Description copied from class: AbstractFileStorage
Retrieves target file name. Default implementation throws UnsupportedOperationException. Must be thread-safe as it is not invoked from a Handler thread.

Overrides:
getFilenameAndExt in class AbstractFileStorage
Parameters:
url - the source URL. May be null - in this case the extension is not needed and returned extension may be null or the result may contain only the name.
fetchInfo - the fetch info object
Returns:
array containing two items - filename and extension. The extension must start with a dot. If null is returned then the object is not downloadable nor storable into the storage.

onFileDownloaded

protected void onFileDownloaded(URL url,
                                Object fetchInfo,
                                boolean success)
Description copied from class: AbstractFileStorage
The file was downloaded and is already registered in the storage. Default implementation does nothing. Must be thread-safe as it is not invoked from a Handler thread.

Overrides:
onFileDownloaded in class AbstractFileStorage
Parameters:
url - the source URL
fetchInfo - the fetch info object
success - if true then the file is available in the cache. If false then the download process was aborted ( AbstractFileStorage.toURL(Object) returned null).

toURL

protected URL toURL(Object fetchInfo)
             throws IOException
Description copied from class: AbstractFileStorage
Converts given fetch info to an URL object. Default implementation throws UnsupportedOperationException. Must be thread-safe as it is not invoked from a Handler thread.

Overrides:
toURL in class AbstractFileStorage
Parameters:
fetchInfo - the fetch info object, never null.
Returns:
URL which is used to download the file contents. If null then this download is aborted.
Throws:
IOException - if i/o error occurs

setLyricsForTrack

public void setLyricsForTrack(TrackMetadataBean track,
                              LyrdbTrack lyrics)
Sets preferred lyrics for given track. On next lyrics download for this track these lyrics will be downloaded - no search will be performed.

Parameters:
track - the track, must not be null.
lyrics - preferred lyrics, must not be null.

deleteLyrics

public void deleteLyrics(TrackMetadataBean track)
Deletes lyrics for given track.

Parameters:
track - the track to delete the lyrics for.

getLyrics

public LRCLyrics getLyrics(TrackMetadataBean track)
                    throws IOException,
                           ParseException
Fetches the lyrics for a track and returns it. If the cover is not present in the cache and we are not offline the lyrics are fetched in a worker thread and ILibraryListener.lyricsLoaded(TrackMetadataBean, List) is emitted.

Parameters:
track - the track.
Returns:
lyrics available or null if the lyrics are not yet available.
Throws:
ParseException - if lyrics parsing failed
IOException - if i/o exception occurred.


Copyright © 2007-2008. All Rights Reserved.