📄 authenticateresponse.java
字号:
package com.bv.api.response;import com.bv.api.Error;/** * A structure to hold the information returned by the server in response to an authenticate call. * @author C. Oattes, Kris Nobes */public class AuthenticateResponse extends ApiResponse { /** * Create a "successful" AuthenticateResponse. */ public AuthenticateResponse() { super(); } /** * Create a "successful" AuthenticateResponse. * @param response The response from the server. */ public AuthenticateResponse(String response) { super(response); } /** * Create an AuthenticateResponse when the API call failed. * @param error The error that occured. */ public AuthenticateResponse(Error error) { super(error); } /** * Create an AuthenticateResponse when the API call failed. <code>Response</code> is the response from the server. * @param error The error that occured. * @param response The response from the server. */ public AuthenticateResponse(Error error, String response) { super(error, response); } /** * Generate an AuthenticateResponse, with "response" set to whatever is returned by the server * @param serverResponse The response from the server * @return An AuthenticateResponse */ public AuthenticateResponse processResponse(String serverResponse) { //In all cases, successful response should start with "OK" if(serverResponse.startsWith("OK")) { String[] lines = serverResponse.split("\n"); this.setResponse(lines[0]); this.setVersion(lines[0].split(" ")[1]); return this; } else if (serverResponse.startsWith("FAIL")) { String[] lines = serverResponse.split("\n"); Error error; this.setVersion(lines[0].split(" ")[1]); // for(int i = 1; i < lines.length; i++) { String line = lines[i]; if(line.startsWith("ERROR")) { //line.split(" ", 3) divides the line into at most 3 sections (ERROR) (ID) (ERROR CODE) String[] splitString = line.split(" " , 3); switch(splitString.length) { case 3: error = Error.getError(splitString[1]); this.setResponse(splitString[2]); break; case 2: error = Error.getError(splitString[1]); break; default: error = Error.UnknownError; break; } //end switch this.setError(error); }//end if }//end for return this; } //Response from API unknown - return an error. //shouldn't reach this point this.setError(Error.UnknownError); return this; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -