net.anidb.http
Class AnimeTitlesDownloader

java.lang.Object
  extended by net.anidb.http.AnimeTitlesDownloader

public class AnimeTitlesDownloader
extends java.lang.Object

A class for downloading the anime titles file.

You can use these anime titles for the seconds level cache. The xml data will be automatically downloaded and decompressed.

You should use the methods in the following order:

You can't call store(File) and/or getInputStream() more than one time on a connected downloader. Before that you have to disconnect and connect the downloader.

For further information look at Anime Titles.

Version:
1.0, 12.01.2010
Author:
grizzlyxp (http://anidb.net/perl-bin/animedb.pl?show=userpage&uid=63935)

Field Summary
static java.lang.String ANIME_TITLES_ADDRESS
          The default address for the file.
static int TIMEOUT
          The connection timeout.
 
Constructor Summary
AnimeTitlesDownloader()
          Creates a downloader object.
AnimeTitlesDownloader(java.lang.String address)
          Creates a downloader object.
AnimeTitlesDownloader(java.net.URL url)
          Creates a downloader object.
 
Method Summary
 void connect()
          Connects the downloader to the server.
 void disconnect()
          Disconnects the downloader from the server.
 java.io.InputStream getInputStream()
          Returns an InputStream to the xml data.
 void store(java.io.File file)
          Stores the xml data in a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANIME_TITLES_ADDRESS

public static final java.lang.String ANIME_TITLES_ADDRESS
The default address for the file.

See Also:
Constant Field Values

TIMEOUT

public static final int TIMEOUT
The connection timeout.

See Also:
Constant Field Values
Constructor Detail

AnimeTitlesDownloader

public AnimeTitlesDownloader()
                      throws java.net.MalformedURLException
Creates a downloader object.

Throws:
java.net.MalformedURLException - If the default address specifies an unknown protocol.
See Also:
ANIME_TITLES_ADDRESS

AnimeTitlesDownloader

public AnimeTitlesDownloader(java.net.URL url)
                      throws HttpConnectionException
Creates a downloader object.

Parameters:
url - The URL of the file.
Throws:
java.lang.IllegalArgumentException - If the URL is null.
HttpConnectionException - If the protocol of the URL isn't http or a new instance of the URL couldn't be created.

AnimeTitlesDownloader

public AnimeTitlesDownloader(java.lang.String address)
                      throws java.net.MalformedURLException,
                             HttpConnectionException
Creates a downloader object.

Parameters:
address - The address of the file.
Throws:
java.lang.IllegalArgumentException - If the address is null.
java.net.MalformedURLException - If the address specifies an unknown protocol.
HttpConnectionException - If the protocol of the address isn't http.
Method Detail

connect

public void connect()
             throws java.io.IOException
Connects the downloader to the server.

Throws:
java.lang.IllegalStateException - If the downloader is already connected.
java.io.IOException - If an error occured while opening the connection.

disconnect

public void disconnect()
Disconnects the downloader from the server.

Throws:
java.lang.IllegalStateException - If the downloader is already disconnected.

store

public void store(java.io.File file)
           throws java.io.IOException
Stores the xml data in a file.

Parameters:
file - The file.
Throws:
java.lang.IllegalArgumentException - If the file is null.
java.lang.IllegalStateException - If the downloader is already disconnected.
java.lang.IllegalStateException - If the file has already been downloaded.
java.io.IOException - If an I/O error occured while downloading the file from the server or while writting it to the filesystem.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an InputStream to the xml data.

Returns:
The InputStream.
Throws:
java.lang.IllegalStateException - If the downloader is already disconnected.
java.lang.IllegalStateException - If the file has already been downloaded.
java.io.IOException - If an I/O error occured while opening the stream to the file on the server.