* Console: Use non-nio connector for Java 5 and JamVM/gij

(tickets #715 and #743)
 * SystemVersion: Centralize more methods here
This commit is contained in:
zzz
2012-10-14 13:54:08 +00:00
parent cb56b76ef9
commit 5d6d27907d
7 changed files with 76 additions and 25 deletions

View File

@ -20,6 +20,8 @@ import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import net.i2p.util.SystemVersion;
/**
* NOTE: As of 0.8.7, use getInstance() instead of new SHA1(), which will
* return the JVM's MessageDigest if it is faster.
@ -94,10 +96,8 @@ public final class SHA1 extends MessageDigest implements Cloneable {
static {
// oddly, Bitzi is faster than Oracle - see test results below
boolean useBitzi = true;
String vendor = System.getProperty("java.vendor");
if (vendor.startsWith("Apache") || // Harmony
vendor.startsWith("GNU Classpath") || // JamVM
vendor.startsWith("Free Software Foundation")) { // gij
if (SystemVersion.isApache() || // Harmony
SystemVersion.isGNU()) { // JamVM or gij
try {
MessageDigest.getInstance("SHA-1");
useBitzi = false;

View File

@ -9,7 +9,7 @@ import java.util.concurrent.LinkedBlockingQueue;
public class ReusableGZIPInputStream extends ResettableGZIPInputStream {
// Apache Harmony 5.0M13 Deflater doesn't work after reset()
// Neither does Android
private static final boolean ENABLE_CACHING = !(System.getProperty("java.vendor").startsWith("Apache") ||
private static final boolean ENABLE_CACHING = !(SystemVersion.isApache() ||
SystemVersion.isAndroid());
private static final LinkedBlockingQueue<ReusableGZIPInputStream> _available;
static {

View File

@ -20,7 +20,7 @@ import net.i2p.data.DataHelper;
public class ReusableGZIPOutputStream extends ResettableGZIPOutputStream {
// Apache Harmony 5.0M13 Deflater doesn't work after reset()
// Neither does Android
private static final boolean ENABLE_CACHING = !(System.getProperty("java.vendor").startsWith("Apache") ||
private static final boolean ENABLE_CACHING = !(SystemVersion.isApache() ||
SystemVersion.isAndroid());
private static final LinkedBlockingQueue<ReusableGZIPOutputStream> _available;
static {

View File

@ -15,14 +15,23 @@ public abstract class SystemVersion {
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
private static final boolean _isAndroid = System.getProperty("java.vendor").contains("Android");
private static final boolean _isAndroid;
private static final boolean _isApache;
private static final boolean _isGNU;
private static final boolean _is64 = "64".equals(System.getProperty("sun.arch.data.model")) ||
System.getProperty("os.arch").contains("64");
private static final boolean _hasWrapper = System.getProperty("wrapper.version") != null;
private static final boolean _oneDotSix;
private static final int _androidSDK;
static {
String vendor = System.getProperty("java.vendor");
_isAndroid = vendor.contains("Android");
_isApache = vendor.startsWith("Apache");
_isGNU = vendor.startsWith("GNU Classpath") || // JamVM
vendor.startsWith("Free Software Foundation"); // gij
int sdk = 0;
if (_isAndroid) {
try {
@ -52,6 +61,20 @@ public abstract class SystemVersion {
return _isAndroid;
}
/**
* Apache Harmony JVM, or Android
*/
public static boolean isApache() {
return _isApache || _isAndroid;
}
/**
* gij or JamVM with GNU Classpath
*/
public static boolean isGNU() {
return _isGNU;
}
/**
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0
* as it handles Android also, where java.version = "0".
@ -90,6 +113,6 @@ public abstract class SystemVersion {
* Same as I2PAppContext.hasWrapper()
*/
public static boolean hasWrapper() {
return System.getProperty("wrapper.version") != null;
return _hasWrapper;
}
}