Path: blob/master/src/java.base/share/classes/sun/net/ftp/FtpReplyCode.java
41159 views
/*1* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.net.ftp;2526/**27* This class describes a FTP protocol reply code and associates a meaning28* to the numerical value according to the various RFCs (RFC 959 in29* particular).30*31*/32public enum FtpReplyCode {3334RESTART_MARKER(110),35SERVICE_READY_IN(120),36DATA_CONNECTION_ALREADY_OPEN(125),37FILE_STATUS_OK(150),38COMMAND_OK(200),39NOT_IMPLEMENTED(202),40SYSTEM_STATUS(211),41DIRECTORY_STATUS(212),42FILE_STATUS(213),43HELP_MESSAGE(214),44NAME_SYSTEM_TYPE(215),45SERVICE_READY(220),46SERVICE_CLOSING(221),47DATA_CONNECTION_OPEN(225),48CLOSING_DATA_CONNECTION(226),49ENTERING_PASSIVE_MODE(227),50ENTERING_EXT_PASSIVE_MODE(229),51LOGGED_IN(230),52SECURELY_LOGGED_IN(232),53SECURITY_EXCHANGE_OK(234),54SECURITY_EXCHANGE_COMPLETE(235),55FILE_ACTION_OK(250),56PATHNAME_CREATED(257),57NEED_PASSWORD(331),58NEED_ACCOUNT(332),59NEED_ADAT(334),60NEED_MORE_ADAT(335),61FILE_ACTION_PENDING(350),62SERVICE_NOT_AVAILABLE(421),63CANT_OPEN_DATA_CONNECTION(425),64CONNECTION_CLOSED(426),65NEED_SECURITY_RESOURCE(431),66FILE_ACTION_NOT_TAKEN(450),67ACTION_ABORTED(451),68INSUFFICIENT_STORAGE(452),69COMMAND_UNRECOGNIZED(500),70INVALID_PARAMETER(501),71BAD_SEQUENCE(503),72NOT_IMPLEMENTED_FOR_PARAMETER(504),73NOT_LOGGED_IN(530),74NEED_ACCOUNT_FOR_STORING(532),75PROT_LEVEL_DENIED(533),76REQUEST_DENIED(534),77FAILED_SECURITY_CHECK(535),78UNSUPPORTED_PROT_LEVEL(536),79PROT_LEVEL_NOT_SUPPORTED_BY_SECURITY(537),80FILE_UNAVAILABLE(550),81PAGE_TYPE_UNKNOWN(551),82EXCEEDED_STORAGE(552),83FILE_NAME_NOT_ALLOWED(553),84PROTECTED_REPLY(631),85UNKNOWN_ERROR(999);86private final int value;8788FtpReplyCode(int val) {89this.value = val;90}9192/**93* Returns the numerical value of the code.94*95* @return the numerical value.96*/97public int getValue() {98return value;99}100101/**102* Determines if the code is a Positive Preliminary response.103* This means beginning with a 1 (which means a value between 100 and 199)104*105* @return <code>true</code> if the reply code is a positive preliminary106* response.107*/108public boolean isPositivePreliminary() {109return value >= 100 && value < 200;110}111112/**113* Determines if the code is a Positive Completion response.114* This means beginning with a 2 (which means a value between 200 and 299)115*116* @return <code>true</code> if the reply code is a positive completion117* response.118*/119public boolean isPositiveCompletion() {120return value >= 200 && value < 300;121}122123/**124* Determines if the code is a positive internediate response.125* This means beginning with a 3 (which means a value between 300 and 399)126*127* @return <code>true</code> if the reply code is a positive intermediate128* response.129*/130public boolean isPositiveIntermediate() {131return value >= 300 && value < 400;132}133134/**135* Determines if the code is a transient negative response.136* This means beginning with a 4 (which means a value between 400 and 499)137*138* @return <code>true</code> if the reply code is a transient negative139* response.140*/141public boolean isTransientNegative() {142return value >= 400 && value < 500;143}144145/**146* Determines if the code is a permanent negative response.147* This means beginning with a 5 (which means a value between 500 and 599)148*149* @return <code>true</code> if the reply code is a permanent negative150* response.151*/152public boolean isPermanentNegative() {153return value >= 500 && value < 600;154}155156/**157* Determines if the code is a protected reply response.158* This means beginning with a 6 (which means a value between 600 and 699)159*160* @return <code>true</code> if the reply code is a protected reply161* response.162*/163public boolean isProtectedReply() {164return value >= 600 && value < 700;165}166167/**168* Determines if the code is a syntax related response.169* This means the second digit is a 0.170*171* @return <code>true</code> if the reply code is a syntax related172* response.173*/174public boolean isSyntax() {175return ((value / 10) - ((value / 100) * 10)) == 0;176}177178/**179* Determines if the code is an information related response.180* This means the second digit is a 1.181*182* @return <code>true</code> if the reply code is an information related183* response.184*/185public boolean isInformation() {186return ((value / 10) - ((value / 100) * 10)) == 1;187}188189/**190* Determines if the code is a connection related response.191* This means the second digit is a 2.192*193* @return <code>true</code> if the reply code is a connection related194* response.195*/196public boolean isConnection() {197return ((value / 10) - ((value / 100) * 10)) == 2;198}199200/**201* Determines if the code is an authentication related response.202* This means the second digit is a 3.203*204* @return <code>true</code> if the reply code is an authentication related205* response.206*/207public boolean isAuthentication() {208return ((value / 10) - ((value / 100) * 10)) == 3;209}210211/**212* Determines if the code is an unspecified type of response.213* This means the second digit is a 4.214*215* @return <code>true</code> if the reply code is an unspecified type of216* response.217*/218public boolean isUnspecified() {219return ((value / 10) - ((value / 100) * 10)) == 4;220}221222/**223* Determines if the code is a file system related response.224* This means the second digit is a 5.225*226* @return <code>true</code> if the reply code is a file system related227* response.228*/229public boolean isFileSystem() {230return ((value / 10) - ((value / 100) * 10)) == 5;231}232233/**234* Static utility method to convert a value into a FtpReplyCode.235*236* @param v the value to convert237* @return the <code>FtpReplyCode</code> associated with the value.238*/239public static FtpReplyCode find(int v) {240for (FtpReplyCode code : FtpReplyCode.values()) {241if (code.getValue() == v) {242return code;243}244}245return UNKNOWN_ERROR;246}247}248249250