|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.anidb.udp.UdpConnection
public class UdpConnection
A connection to AniDB via UDP.
For further information on the UDP communication look at the UDP API Definition.
The flood protection limits the packets / requests per minute:
AUTH
,
NOTIFY
and BUDDYLIST
.
Field Summary | |
---|---|
static java.lang.String |
CLIENT_NAME
The client name of the Java AniDB API. |
static int |
CLIENT_VERSION
The client version of this version of the Java AniDB API. |
static int |
MAXMIMUM_NUMBER_OF_BONUS_PACKETS
The maximum number of bonus packets. |
static int |
PROTOCOL_VERSION
The supported protocol version. |
static int |
TIME_BETWEEN_BONUS_PACKETS
The time between the bonus packets in milliseconds. |
static int |
TIME_BETWEEN_NORMAL_PACKETS
The time between normal packets in milliseconds. |
Method Summary | |
---|---|
void |
acknowledgeNotification(NotificationListEntry listEntry)
Acknowledges the notification for the given list entry. |
void |
acknowledgeNotification(java.lang.String type,
long id)
Acknowledges the notification for the given type and Id. |
void |
authenticate(java.lang.String username,
java.lang.String password)
Authenticates the user and client to AniDB. |
void |
authenticate(java.lang.String username,
java.lang.String password,
java.lang.String clientname,
int clientversion)
Authenticates the user and client to AniDB. |
void |
close()
Closes the connection. |
Anime |
getAnime(long animeId)
Returns the anime with the given Id. |
Anime |
getAnime(long animeId,
AnimeMask mask)
Returns the anime with the given Id. |
Anime |
getAnime(java.lang.String animeName)
Returns the anime with the given name. |
Anime |
getAnime(java.lang.String animeName,
AnimeMask mask)
Returns the anime with the given name. |
java.lang.String |
getAnimeDescription(long animeId)
Returns the description for the anime with the given Id. |
Character |
getCharacter(long characterId)
Returns the character with the given character Id. |
Creator |
getCreator(long creatorId)
Returns the creator with the given creator Id. |
java.nio.charset.Charset |
getCurrentEncoding()
Returns the charset which is currently used for encoding. |
Episode |
getEpisode(long episodeId)
Returns the episode with the given Id. |
Episode |
getEpisode(long animeId,
long episodeNumber)
Returns the episode with the given anime Id and episode number. |
Episode |
getEpisode(java.lang.String animeName,
long episodeNumber)
Returns the episode with the given anime name and episode number. |
File |
getFile(long fileId,
FileMask fileMask,
AnimeFileMask animeFileMask)
Returns the file with the given Id. |
java.util.List<File> |
getFiles(long animeId,
long groupId,
long episodeNumber,
FileMask fileMask,
AnimeFileMask animeFileMask)
Returns the files with the given anime Id, group Id and episode number. |
java.util.List<File> |
getFiles(long size,
java.lang.String ed2kHash,
FileMask fileMask,
AnimeFileMask animeFileMask)
Returns the files with the given size and ed2k hash. |
java.util.List<File> |
getFiles(long animeId,
java.lang.String groupName,
long episodeNumber,
FileMask fileMask,
AnimeFileMask animeFileMask)
Returns the files with the given anime Id, group name and episode number. |
java.util.List<File> |
getFiles(java.lang.String animeName,
long groupId,
long episodeNumber,
FileMask fileMask,
AnimeFileMask animeFileMask)
Returns the files with the given anime name, group Id and episode number. |
java.util.List<File> |
getFiles(java.lang.String animeName,
java.lang.String groupName,
long episodeNumber,
FileMask fileMask,
AnimeFileMask animeFileMask)
Returns the files with the given anime name, group name and episode number. |
Group |
getGroup(long groupId)
Returns the group with the given group Id. |
Group |
getGroup(java.lang.String groupName)
Returns the group with the given group name or short name. |
java.util.List<GroupStatus> |
getGroupStatus(long animeId)
Returns a list of the group status for the anime with the given anime Id. |
java.util.List<GroupStatus> |
getGroupStatus(long animeId,
GroupStatusState state)
Returns a list of the group status for the anime with the given anime Id and the given state. |
Notification |
getNotification(NotificationListEntry listEntry)
Returns the notification for the given list entry. |
Notification |
getNotification(java.lang.String type,
long id)
Returns the notification for the given type and Id. |
java.util.List<NotificationListEntry> |
getNotifyList()
Returns a list of entries of all pending (not acknowledged) new private message and new file notifications. |
java.nio.charset.Charset |
getPreferredEncoding()
Returns the preferred charset for encoding. |
java.lang.String |
getServerVersion()
Returns the server version. |
long |
getUptime()
Returns the UDP server uptime in milliseconds. |
long |
getUserId(java.lang.String userName)
Returns the user Id for the user with the given user name. |
boolean |
isLoggedIn()
Return the state if the client is logged in. |
boolean |
isOpen()
Return the state if connection is open. |
void |
logout()
Logs the client out. |
void |
ping()
Sends a ping to a server. |
void |
sendMessage(java.lang.String userName,
java.lang.String title,
java.lang.String body)
Sends a message to the user with the given user name. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int PROTOCOL_VERSION
public static final int MAXMIMUM_NUMBER_OF_BONUS_PACKETS
public static final int TIME_BETWEEN_BONUS_PACKETS
public static final int TIME_BETWEEN_NORMAL_PACKETS
public static final java.lang.String CLIENT_NAME
public static final int CLIENT_VERSION
Method Detail |
---|
public boolean isOpen()
true
, if the connection is currently
open, otherwise false
.public void close() throws UdpConnectionException, AniDbException
Closes the connection.
If the client is not logged out, a logout will be performed. And if there any problems the logout will raise an exception. In spite of that the connection will be closed by all means.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.logout()
public boolean isLoggedIn()
true
, if the client is currently logged
in, otherwise false
.public java.nio.charset.Charset getCurrentEncoding()
Returns the charset which is currently used for encoding.
At the beginning of a connection the charset US-ASCII
will be used - as defined in the API documentation. If you don't specify
any encoding at the AUTHENTICATE
command, the preferred
charset will be used after that command.
Remark: In the current version of this class you can't specifiy
a encoding at the AUTHENTICATE
command. This will be
implemented later on.
getPreferredEncoding()
,
authenticate(String, String)
,
authenticate(String, String, String, int)
public java.nio.charset.Charset getPreferredEncoding()
Returns the preferred charset for encoding.
If you don't specify any encoding at the AUTHENTICATE
command, this charset will be used. But please keep in mind that the
used charset at the beginning of a connection is allways
US-ASCII
- as defined in the API documentation.
Remark: In the current version of this class you can't specifiy
a encoding at the AUTHENTICATE
command. This will be
implemented later on.
getCurrentEncoding()
,
authenticate(String, String)
,
authenticate(String, String, String, int)
public void authenticate(java.lang.String username, java.lang.String password) throws UdpConnectionException, AniDbException
username
- The username.password
- The password.
java.lang.IllegalArgumentException
- If the username is null
.
java.lang.IllegalArgumentException
- If the password is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.LOGIN_ACCEPTED
,
UdpReturnCodes.LOGIN_ACCEPTED_NEW_VER
,
UdpReturnCodes.LOGIN_FAILED
,
UdpReturnCodes.ACCESS_DENIED
,
UdpReturnCodes.CLIENT_VERSION_OUTDATED
,
UdpReturnCodes.CLIENT_BANNED
,
UdpReturnCodes.ILLEGAL_INPUT_OR_ACCESS_DENIED
,
UdpReturnCodes.ANIDB_OUT_OF_SERVICE
public void authenticate(java.lang.String username, java.lang.String password, java.lang.String clientname, int clientversion) throws UdpConnectionException, AniDbException
username
- The username.password
- The password.clientname
- The name of the client.clientversion
- The version of the client.
java.lang.IllegalArgumentException
- If the username is null
.
java.lang.IllegalArgumentException
- If the password is null
.
java.lang.IllegalArgumentException
- If the client name is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.LOGIN_ACCEPTED
,
UdpReturnCodes.LOGIN_ACCEPTED_NEW_VER
,
UdpReturnCodes.LOGIN_FAILED
,
UdpReturnCodes.ACCESS_DENIED
,
UdpReturnCodes.CLIENT_VERSION_OUTDATED
,
UdpReturnCodes.CLIENT_BANNED
,
UdpReturnCodes.ILLEGAL_INPUT_OR_ACCESS_DENIED
,
UdpReturnCodes.ANIDB_OUT_OF_SERVICE
public void logout() throws UdpConnectionException, AniDbException
Logs the client out.
If client is currently not logged in, an exception will be thrown.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.public void ping() throws UdpConnectionException, AniDbException
Sends a ping to a server.
If the server doesn't respond, an exception will be thrown.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.public java.lang.String getServerVersion() throws UdpConnectionException, AniDbException
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.public long getUptime() throws UdpConnectionException, AniDbException
Returns the UDP server uptime in milliseconds.
If client is currently not logged in, an exception will be thrown.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.public Anime getAnime(long animeId) throws UdpConnectionException, AniDbException
animeId
- The anime Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ANIME
public Anime getAnime(java.lang.String animeName) throws UdpConnectionException, AniDbException
animeName
- The anime name.
java.lang.IllegalArgumentException
- If the anime name is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ANIME
public Anime getAnime(long animeId, AnimeMask mask) throws UdpConnectionException, AniDbException
Returns the anime with the given Id.
Only the fields specified by the mask will be filled.
animeId
- The anime Id.mask
- The mask.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ANIME
public Anime getAnime(java.lang.String animeName, AnimeMask mask) throws UdpConnectionException, AniDbException
Returns the anime with the given name.
Only the fields specified by the mask will be filled.
animeName
- The anime name.mask
- The mask.
java.lang.IllegalArgumentException
- If the anime name is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ANIME
public java.lang.String getAnimeDescription(long animeId) throws UdpConnectionException, AniDbException
Returns the description for the anime with the given Id.
It should be considered that this method has to use more than one request for retrieving the complete description. The reason is that a descrption can take up to ~5000 characters while the maximum data of an UDP packet is ~1400 bytes.
animeId
- The anime Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ANIME
,
UdpReturnCodes.NO_SUCH_ANIME_DESCRIPTION
public Episode getEpisode(long episodeId) throws UdpConnectionException, AniDbException
episodeId
- The episode Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_EPISODE
public Episode getEpisode(java.lang.String animeName, long episodeNumber) throws UdpConnectionException, AniDbException
animeName
- The anime name.episodeNumber
- The episode number.
java.lang.IllegalArgumentException
- If the anime name is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_EPISODE
public Episode getEpisode(long animeId, long episodeNumber) throws UdpConnectionException, AniDbException
animeId
- The anime Id.episodeNumber
- The episode number.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_EPISODE
public File getFile(long fileId, FileMask fileMask, AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException
Returns the file with the given Id.
Only the fields specified by the two masks will be filled.
fileId
- The file Id.fileMask
- The file mask.animeFileMask
- The anime file mask.
java.lang.IllegalArgumentException
- If the file mask is null
.
java.lang.IllegalArgumentException
- If the anime file mask is
null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_FILE
public java.util.List<File> getFiles(long size, java.lang.String ed2kHash, FileMask fileMask, AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException
Returns the files with the given size and ed2k hash.
Only the fields specified by the two masks will be filled.
size
- The size.ed2kHash
- The ed2k hash.fileMask
- The file mask.animeFileMask
- The anime file mask.
java.lang.IllegalArgumentException
- If the size is less than 1
.
java.lang.IllegalArgumentException
- If the ed2k hash is null
.
java.lang.IllegalArgumentException
- If the file mask is null
.
java.lang.IllegalArgumentException
- If the anime file mask is
null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_FILE
public java.util.List<File> getFiles(java.lang.String animeName, java.lang.String groupName, long episodeNumber, FileMask fileMask, AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException
Returns the files with the given anime name, group name and episode number.
Only the fields specified by the two masks will be filled.
animeName
- The anime name.groupName
- The group name.episodeNumber
- The episode number.fileMask
- The file mask.animeFileMask
- The anime file mask.
java.lang.IllegalArgumentException
- If the anime name is null
.
java.lang.IllegalArgumentException
- If the group name is null
.
java.lang.IllegalArgumentException
- If the file mask is null
.
java.lang.IllegalArgumentException
- If the anime file mask is
null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_FILE
public java.util.List<File> getFiles(java.lang.String animeName, long groupId, long episodeNumber, FileMask fileMask, AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException
Returns the files with the given anime name, group Id and episode number.
Only the fields specified by the two masks will be filled.
animeName
- The anime name.groupId
- The group Id.episodeNumber
- The episode number.fileMask
- The file mask.animeFileMask
- The anime file mask.
java.lang.IllegalArgumentException
- If the anime name is null
.
java.lang.IllegalArgumentException
- If the file mask is null
.
java.lang.IllegalArgumentException
- If the anime file mask is
null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_FILE
public java.util.List<File> getFiles(long animeId, java.lang.String groupName, long episodeNumber, FileMask fileMask, AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException
Returns the files with the given anime Id, group name and episode number.
Only the fields specified by the two masks will be filled.
animeId
- The anime Id.groupName
- The group name.episodeNumber
- The episode number.fileMask
- The file mask.animeFileMask
- The anime file mask.
java.lang.IllegalArgumentException
- If the group name is null
.
java.lang.IllegalArgumentException
- If the file mask is null
.
java.lang.IllegalArgumentException
- If the anime file mask is
null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_FILE
public java.util.List<File> getFiles(long animeId, long groupId, long episodeNumber, FileMask fileMask, AnimeFileMask animeFileMask) throws UdpConnectionException, AniDbException
Returns the files with the given anime Id, group Id and episode number.
Only the fields specified by the two masks will be filled.
animeId
- The anime Id.groupId
- The group Id.episodeNumber
- The episode number.fileMask
- The file mask.animeFileMask
- The anime file mask.
java.lang.IllegalArgumentException
- If the file mask is null
.
java.lang.IllegalArgumentException
- If the anime file mask is
null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_FILE
public Group getGroup(long groupId) throws UdpConnectionException, AniDbException
groupId
- The group Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_GROUP
public Group getGroup(java.lang.String groupName) throws UdpConnectionException, AniDbException
groupName
- The group name or short name.
java.lang.IllegalArgumentException
- If the group name is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_GROUP
public java.util.List<GroupStatus> getGroupStatus(long animeId) throws UdpConnectionException, AniDbException
Returns a list of the group status for the anime with the given anime Id.
animeId
- The anime Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_GROUPS_FOUND
,
UdpReturnCodes.NO_SUCH_ANIME
public java.util.List<GroupStatus> getGroupStatus(long animeId, GroupStatusState state) throws UdpConnectionException, AniDbException
Returns a list of the group status for the anime with the given anime Id and the given state.
animeId
- The anime Id.state
- The state.
java.lang.IllegalArgumentException
- If the state is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_GROUPS_FOUND
,
UdpReturnCodes.NO_SUCH_ANIME
public Creator getCreator(long creatorId) throws UdpConnectionException, AniDbException
creatorId
- The creator Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_CREATOR
public Character getCharacter(long characterId) throws UdpConnectionException, AniDbException
characterId
- The character Id.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_CHARACTER
public java.util.List<NotificationListEntry> getNotifyList() throws UdpConnectionException, AniDbException
Returns a list of entries of all pending (not acknowledged) new private message and new file notifications.
Buddy events cannot be acknowledged.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.public Notification getNotification(NotificationListEntry listEntry) throws UdpConnectionException, AniDbException
listEntry
- The list entry.
java.lang.IllegalArgumentException
- If the list entry is null.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_MESSAGE
,
UdpReturnCodes.NO_SUCH_NOTIFY
public Notification getNotification(java.lang.String type, long id) throws UdpConnectionException, AniDbException
type
- The type.id
- The Id.
java.lang.IllegalArgumentException
- If the type is null
or the
given type isn't supported.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_MESSAGE
,
UdpReturnCodes.NO_SUCH_NOTIFY
public void acknowledgeNotification(NotificationListEntry listEntry) throws UdpConnectionException, AniDbException
listEntry
- The list entry.
java.lang.IllegalArgumentException
- If the list entry is null.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ENTRY_M
,
UdpReturnCodes.NO_SUCH_ENTRY_N
public void acknowledgeNotification(java.lang.String type, long id) throws UdpConnectionException, AniDbException
type
- The type.id
- The Id.
java.lang.IllegalArgumentException
- If the type is null
or the
given type isn't supported.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_ENTRY_M
,
UdpReturnCodes.NO_SUCH_ENTRY_N
public void sendMessage(java.lang.String userName, java.lang.String title, java.lang.String body) throws UdpConnectionException, AniDbException
userName
- The user name.title
- The title.body
- The body.
java.lang.IllegalArgumentException
- If the user name is null
.
java.lang.IllegalArgumentException
- If the title is null
or
has more than 50 chars.
java.lang.IllegalArgumentException
- If the body is null
or has
more than 900 chars.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.SENDMSG_SUCCESSFUL
,
UdpReturnCodes.NO_SUCH_USER
,
UdpReturnCodes.LOGIN_FIRST
public long getUserId(java.lang.String userName) throws UdpConnectionException, AniDbException
userName
- The user name.
java.lang.IllegalArgumentException
- If the user name is null
.
UdpConnectionException
- If a connection problem occured.
AniDbException
- If a problem with AniDB occured.UdpReturnCodes.NO_SUCH_USER
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |