You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/04/02 20:06:59 UTC

svn commit: r159780 - in jakarta/httpclient/trunk/http-common/src: java/org/apache/http/HttpRuntime.java java/org/apache/http/util/EncodingUtil.java test/org/apache/http/util/TestEncodingUtils.java

Author: olegk
Date: Sat Apr  2 10:06:58 2005
New Revision: 159780

URL: http://svn.apache.org/viewcvs?view=rev&rev=159780
Log:
Added HttpRuntime

Added:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java   (with props)
Modified:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java
    jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java

Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java?view=auto&rev=159780
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java Sat Apr  2 10:06:58 2005
@@ -0,0 +1,98 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+import org.apache.http.util.ExceptionUtil;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public class HttpRuntime {
+
+    public static int JAVA_MAJOR_VER = 1;
+    public static int JAVA_MINOR_VER = 0;
+    
+    static {
+        initHttpRuntime();
+    }
+    
+    private static void initHttpRuntime() {
+        String verstr = (String) System.getProperty("java.specification.version");
+        if (verstr == null) {
+            throw new FatalError("Failed to determine Java specification version");
+        }
+        int i = verstr.indexOf(".");
+        if (i == -1) {
+            throw new FatalError("Invalid Java specification version: " + verstr);
+        }
+        try {
+            JAVA_MAJOR_VER = Integer.parseInt(verstr.substring(0, i));
+        } catch (NumberFormatException ex) {
+            throw new FatalError("Invalid Java specification major version: " + verstr);
+        }
+        try {
+            JAVA_MINOR_VER = Integer.parseInt(verstr.substring(i - 1));
+        } catch (NumberFormatException ex) {
+            throw new FatalError("Invalid Java specification minor version: " + verstr);
+        }
+    }
+    
+    public static boolean isNIOCapable() {
+        return (JAVA_MAJOR_VER == 1 && JAVA_MINOR_VER >= 4) || JAVA_MAJOR_VER > 1;
+    }
+    
+    public static boolean isSSLNIOCapable() {
+        return (JAVA_MAJOR_VER == 1 && JAVA_MINOR_VER >= 5) || JAVA_MAJOR_VER > 1;
+    }
+    
+    private HttpRuntime() {
+        super();
+    }
+    
+    public static class FatalError extends Error {
+        
+        public FatalError(final String message) {
+            super(message);
+        }
+        
+        public FatalError(final String message, final Throwable cause) {
+            super(message);
+            ExceptionUtil.initCause(this, cause);
+        }
+        
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpRuntime.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java?view=diff&r1=159779&r2=159780
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/util/EncodingUtil.java Sat Apr  2 10:06:58 2005
@@ -30,6 +30,8 @@
 
 import java.io.UnsupportedEncodingException;
 
+import org.apache.http.HttpRuntime;
+
 /**
  * The home for utility methods that handle various encoding tasks.
  * 
@@ -141,7 +143,7 @@
         try {
             return data.getBytes(ASCII_CHARSET);
         } catch (UnsupportedEncodingException e) {
-            throw new AsciiNotSupportedError("HttpClient requires ASCII support");
+            throw new HttpRuntime.FatalError("HttpClient requires ASCII support");
         }
     }
 
@@ -166,7 +168,7 @@
         try {
             return new String(data, offset, length, ASCII_CHARSET);
         } catch (UnsupportedEncodingException e) {
-            throw new AsciiNotSupportedError("HttpClient requires ASCII support");
+            throw new HttpRuntime.FatalError("HttpClient requires ASCII support");
         }
     }
 
@@ -194,12 +196,4 @@
         super();
     }
 
-    static class AsciiNotSupportedError extends Error {
-        
-        public AsciiNotSupportedError(final String message) {
-            super(message);
-        }
-        
-    }
-    
 }

Modified: jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java?view=diff&r1=159779&r2=159780
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java (original)
+++ jakarta/httpclient/trunk/http-common/src/test/org/apache/http/util/TestEncodingUtils.java Sat Apr  2 10:06:58 2005
@@ -188,8 +188,4 @@
         }
     }
     
-    public void testAsciiNotSupportedError() {
-        new EncodingUtil.AsciiNotSupportedError("Fatal error");
-    }
-    
 }