public static final int BAD_SEQUENCE_ID = 4;
public static final int MISSING_RESULT = 5;
- protected int type_ = 0;
+ protected int type_ = UNKNOWN;
public TApplicationException() {
super();
*/
public int read(byte[] buf, int off, int len) throws TTransportException {
if (inputStream_ == null) {
- throw new TTransportException("Cannot read from null inputStream");
+ throw new TTransportException(TTransportException.NOT_OPEN, "Cannot read from null inputStream");
}
try {
return inputStream_.read(buf, off, len);
} catch (IOException iox) {
- throw new TTransportException(iox);
+ throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
*/
public void write(byte[] buf, int off, int len) throws TTransportException {
if (outputStream_ == null) {
- throw new TTransportException("Cannot write to null outputStream");
+ throw new TTransportException(TTransportException.NOT_OPEN, "Cannot write to null outputStream");
}
try {
outputStream_.write(buf, off, len);
} catch (IOException iox) {
- throw new TTransportException(iox);
+ throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
*/
public void flush() throws TTransportException {
if (outputStream_ == null) {
- throw new TTransportException("Cannot flush null outputStream");
+ throw new TTransportException(TTransportException.NOT_OPEN, "Cannot flush null outputStream");
}
try {
outputStream_.flush();
} catch (IOException iox) {
- throw new TTransportException(iox);
+ throw new TTransportException(TTransportException.UNKNOWN, iox);
}
}
}
protected TSocket acceptImpl() throws TTransportException {
if (serverSocket_ == null) {
- throw new TTransportException("No underlying server socket.");
+ throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
}
try {
Socket result = serverSocket_.accept();
outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024);
} catch (IOException iox) {
close();
- throw new TTransportException(iox);
+ throw new TTransportException(TTransportException.NOT_OPEN, iox);
}
}
}
*/
public void open() throws TTransportException {
if (isOpen()) {
- throw new TTransportException("Socket already connected.");
+ throw new TTransportException(TTransportException.ALREADY_OPEN, "Socket already connected.");
}
if (host_.length() == 0) {
- throw new TTransportException("Cannot open null host.");
+ throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open null host.");
}
if (port_ <= 0) {
- throw new TTransportException("Cannot open without port.");
+ throw new TTransportException(TTransportException.NOT_OPEN, "Cannot open without port.");
}
if (socket_ == null) {
outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024);
} catch (IOException iox) {
close();
- throw new TTransportException(iox);
+ throw new TTransportException(TTransportException.NOT_OPEN, iox);
}
}
* @author Mark Slee <mcslee@facebook.com>
*/
public class TTransportException extends TException {
+
+ public static final int UNKNOWN = 0;
+ public static final int NOT_OPEN = 1;
+ public static final int ALREADY_OPEN = 2;
+ public static final int TIMED_OUT = 3;
+ public static final int END_OF_FILE = 4;
+
+ protected int type_ = UNKNOWN;
+
public TTransportException() {
super();
}
+ public TTransportException(int type) {
+ super();
+ type_ = type;
+ }
+
+ public TTransportException(int type, String message) {
+ super(message);
+ type_ = type;
+ }
+
public TTransportException(String message) {
super(message);
}
+ public TTransportException(int type, Throwable cause) {
+ super(cause);
+ type_ = type;
+ }
+
public TTransportException(Throwable cause) {
super(cause);
}
public TTransportException(String message, Throwable cause) {
super(message, cause);
}
+
+ public TTransportException(int type, String message, Throwable cause) {
+ super(message, cause);
+ type_ = type;
+ }
+
+ public int getType() {
+ return type_;
+ }
+
}