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.Map; 030 031public class FileTransfer extends Wrapper { 032 033 public FileTransfer(Map<String, String> map) { 034 super(map); 035 } 036 037 /** 038 * Gets the ID of the client who started this file transfer. 039 * 040 * @return the ID of the involved client 041 */ 042 public int getClientId() { 043 return getInt("clid"); 044 } 045 046 /** 047 * Gets the path of the folder that the file which is being transferred is stored in on disk. 048 * This path seems to be relative to the folder the TS3 server is installed in. 049 * 050 * @return the disk path of the folder containing the transferring file 051 */ 052 public String getDiskFilePath() { 053 return get("path"); 054 } 055 056 /** 057 * Returns the name of the file on the TS3 server without its full path. 058 * 059 * @return the file's name 060 */ 061 public String getFileName() { 062 return get("name"); 063 } 064 065 /** 066 * Gets the size in bytes the file will have once it is fully transferred. 067 * 068 * @return the final file size in bytes 069 */ 070 public long getTotalFileSize() { 071 return getLong("size"); 072 } 073 074 /** 075 * Gets the amount of bytes that have already been transferred. 076 * 077 * @return the amount of transferred bytes 078 */ 079 public long getTransferredFileSize() { 080 return getLong("sizedone"); 081 } 082 083 /** 084 * Returns the key that the client has sent to the server to identify their file transfer. 085 * 086 * @return the client's file transfer ID 087 */ 088 public int getClientTransferId() { 089 return getInt("clientftfid"); 090 } 091 092 /** 093 * Returns an internal ID that the server uses to identify their file transfer. 094 * This is <strong>not</strong> the key that can be used to request a file from the file server. 095 * 096 * @return the server's file transfer ID 097 */ 098 public int getServerTransferId() { 099 return getInt("serverftfid"); 100 } 101 102 /** 103 * Returns the current status of the file transfer. 104 * <p> 105 * Currently known status codes: 106 * </p> 107 * <ul> 108 * <li>0 - Not started</li> 109 * <li>1 - Active</li> 110 * <li>2 - Inactive (paused, stalled or done)</li> 111 * </ul> 112 * 113 * @return the current transfer status 114 */ 115 public int getStatus() { 116 return getInt("status"); 117 } 118 119 /** 120 * Returns {@code true} if the file transfer has started. 121 * 122 * @return whether the file transfer has started 123 */ 124 public boolean hasStarted() { 125 return getStatus() > 0; 126 } 127 128 /** 129 * Returns {@code true} if the file transfer is still active. 130 * This is the case when the transfer has started and is not done or paused. 131 * 132 * @return whether the file transfer is active 133 */ 134 public boolean isActive() { 135 return getStatus() == 1; 136 } 137 138 /** 139 * Returns the current file transfer speed in bytes per second. 140 * 141 * @return the current transfer speed 142 */ 143 public double getCurrentSpeed() { 144 return getDouble("current_speed"); 145 } 146 147 /** 148 * Returns the current file transfer speed in bytes per second. 149 * 150 * @return the current transfer speed 151 */ 152 public double getAverageSpeed() { 153 return getDouble("average_speed"); 154 } 155 156 /** 157 * Returns how many milliseconds have elapsed since the file transfer was first announced to 158 * the server. This value will count up even if the file transfer has not yet been started, 159 * but will stop if the transfer has been paused or is complete. 160 * 161 * @return the transfer runtime in milliseconds 162 */ 163 public long getRuntime() { 164 return getLong("runtime"); 165 } 166}