More java error codes in thrift

Reviewed By: aditya


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665011 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/TApplicationException.java b/lib/java/src/TApplicationException.java
index 0890282..b9c0d3d 100644
--- a/lib/java/src/TApplicationException.java
+++ b/lib/java/src/TApplicationException.java
@@ -20,7 +20,7 @@
   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();
diff --git a/lib/java/src/transport/TIOStreamTransport.java b/lib/java/src/transport/TIOStreamTransport.java
index aa4adf1..a32195b 100644
--- a/lib/java/src/transport/TIOStreamTransport.java
+++ b/lib/java/src/transport/TIOStreamTransport.java
@@ -99,12 +99,12 @@
    */
   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);
     }
   }
 
@@ -113,12 +113,12 @@
    */
   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);
     }
   }
 
@@ -127,12 +127,12 @@
    */
   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);
     }
   }
 }
diff --git a/lib/java/src/transport/TServerSocket.java b/lib/java/src/transport/TServerSocket.java
index ab2b5e7..6cbd0c1 100644
--- a/lib/java/src/transport/TServerSocket.java
+++ b/lib/java/src/transport/TServerSocket.java
@@ -82,7 +82,7 @@
   
   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();
diff --git a/lib/java/src/transport/TSocket.java b/lib/java/src/transport/TSocket.java
index 4922b04..a2aa233 100644
--- a/lib/java/src/transport/TSocket.java
+++ b/lib/java/src/transport/TSocket.java
@@ -55,7 +55,7 @@
         outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024);
       } catch (IOException iox) {
         close();
-        throw new TTransportException(iox);
+        throw new TTransportException(TTransportException.NOT_OPEN, iox);
       }
     }
   }
@@ -139,14 +139,14 @@
    */
   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) {
@@ -159,7 +159,7 @@
       outputStream_ = new BufferedOutputStream(socket_.getOutputStream(), 1024);
     } catch (IOException iox) {
       close();
-      throw new TTransportException(iox);
+      throw new TTransportException(TTransportException.NOT_OPEN, iox);
     }
   }
 
diff --git a/lib/java/src/transport/TTransportException.java b/lib/java/src/transport/TTransportException.java
index a67b6ed..5d9e371 100644
--- a/lib/java/src/transport/TTransportException.java
+++ b/lib/java/src/transport/TTransportException.java
@@ -8,14 +8,38 @@
  * @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);
   }
@@ -23,4 +47,14 @@
   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_;
+  }
+
 }