001package com.github.theholywaffle.teamspeak3.api.wrapper; 002 003/* 004 * #%L 005 * TeamSpeak 3 Java API 006 * %% 007 * Copyright (C) 2016 Bert De Geyter, Roger Baumgartner 008 * %% 009 * Permission is hereby granted, free of charge, to any person obtaining a copy 010 * of this software and associated documentation files (the "Software"), to deal 011 * in the Software without restriction, including without limitation the rights 012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 013 * copies of the Software, and to permit persons to whom the Software is 014 * furnished to do so, subject to the following conditions: 015 * 016 * The above copyright notice and this permission notice shall be included in 017 * all copies or substantial portions of the Software. 018 * 019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 025 * THE SOFTWARE. 026 * #L% 027 */ 028 029import java.util.HashMap; 030import java.util.Map; 031 032/** 033 * Represents an internally started file transfer and encapsulates the command response. 034 */ 035public class FileTransferParameters extends Wrapper { 036 037 public FileTransferParameters(Map<String, String> map) { 038 super(map); 039 } 040 041 /** 042 * Returns the key that the client has sent to the server to identify their file transfer. 043 * 044 * @return the client's file transfer ID 045 */ 046 public int getClientTransferId() { 047 return getInt("clientftfid"); 048 } 049 050 /** 051 * Returns an internal ID that the server uses to identify their file transfer. 052 * This is <strong>not</strong> the key that can be used to request a file from the file server. 053 * 054 * @return the server's file transfer ID 055 */ 056 public int getServerTransferId() { 057 return getInt("serverftfid"); 058 } 059 060 /** 061 * Gets the key needed identify ourselves to the file server and to start the file transfer. 062 * 063 * @return the file transfer key 064 */ 065 public String getFileTransferKey() { 066 return get("ftkey"); 067 } 068 069 /** 070 * Gets the IP address or hostname of the file server the TS3 instance wants us to send our data to. 071 * 072 * @return the IP address of the file server 073 */ 074 public String getFileServerHost() { 075 return get("ip"); 076 } 077 078 /** 079 * Gets the port of the file server the TS3 instance wants us to send our data to. 080 * 081 * @return the port of the file server 082 */ 083 public int getFileServerPort() { 084 return getInt("port"); 085 } 086 087 /** 088 * Gets the size of the file being downloaded in bytes. 089 * Only present if this is a successfully started download. 090 * 091 * @return the size of the file being downloaded. 092 */ 093 public long getFileSize() { 094 return getLong("size"); 095 } 096 097 /** 098 * Gets a {@link QueryError} that can be used when throwing an exception. 099 * 100 * @return a query error for this command's success value 101 */ 102 public QueryError getQueryError() { 103 Map<String, String> errorMap = new HashMap<>(2); 104 errorMap.put("id", String.valueOf(getStatus())); 105 errorMap.put("msg", getMessage()); 106 return new QueryError(errorMap); 107 } 108 109 /** 110 * Gets the status / error code of this command. Only present if the command failed. 111 * 112 * @return the command's status value 113 */ 114 public int getStatus() { 115 final int status = getInt("status"); 116 return status == -1 ? 0 : status; 117 } 118 119 /** 120 * Gets the message that is provided in case the command fails. 121 * 122 * @return the failure message 123 */ 124 public String getMessage() { 125 return get("msg"); 126 } 127}