Java Code Examples for io.netty.util.internal.PlatformDependent#javaVersion()

The following examples show how to use io.netty.util.internal.PlatformDependent#javaVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
        return new JZlibEncoder(wrapper);
    } else {
        return new JdkZlibEncoder(wrapper);
    }
}
 
Example 2
Source File: NioSocketChannel.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private void shutdownInput0() throws Exception {
    if (PlatformDependent.javaVersion() >= 7) {
        javaChannel().shutdownInput();
    } else {
        javaChannel().socket().shutdownInput();
    }
}
 
Example 3
Source File: ZlibCodecFactory.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder ||
            windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
        return new JZlibEncoder(wrapper, compressionLevel, windowBits, memLevel);
    } else {
        return new JdkZlibEncoder(wrapper, compressionLevel);
    }
}
 
Example 4
Source File: ZlibCodecFactory.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
public static ZlibDecoder newZlibDecoder(byte[] dictionary) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
        return new JZlibDecoder(dictionary);
    } else {
        return new JdkZlibDecoder(dictionary);
    }
}
 
Example 5
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibDecoder newZlibDecoder(ZlibWrapper wrapper) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
        return new JZlibDecoder(wrapper);
    } else {
        return new JdkZlibDecoder(wrapper);
    }
}
 
Example 6
Source File: PooledUnsafeHeapByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf setZero(int index, int length) {
    if (PlatformDependent.javaVersion() >= 7) {
        checkIndex(index, length);
        // Only do on java7+ as the needed Unsafe call was only added there.
        UnsafeByteBufUtil.setZero(memory, idx(index), length);
        return this;
    }
    return super.setZero(index, length);
}
 
Example 7
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibEncoder newZlibEncoder(int compressionLevel, byte[] dictionary) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
        return new JZlibEncoder(compressionLevel, dictionary);
    } else {
        return new JdkZlibEncoder(compressionLevel, dictionary);
    }
}
 
Example 8
Source File: UnitializedArrayBenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Setup(Level.Trial)
public void setupTrial() {
    if (PlatformDependent.javaVersion() < 9) {
        throw new IllegalStateException("Needs Java9");
    }
    if (!PlatformDependent.hasUnsafe()) {
        throw new IllegalStateException("Needs Unsafe");
    }
}
 
Example 9
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibEncoder newZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder ||
        windowBits != DEFAULT_JDK_WINDOW_SIZE || memLevel != DEFAULT_JDK_MEM_LEVEL) {
        return new JZlibEncoder(wrapper, compressionLevel, windowBits, memLevel);
    } else {
        return new JdkZlibEncoder(wrapper, compressionLevel);
    }
}
 
Example 10
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibEncoder newZlibEncoder(byte[] dictionary) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
        return new JZlibEncoder(dictionary);
    } else {
        return new JdkZlibEncoder(dictionary);
    }
}
 
Example 11
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibDecoder newZlibDecoder() {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
        return new JZlibDecoder();
    } else {
        return new JdkZlibDecoder();
    }
}
 
Example 12
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibEncoder newZlibEncoder(int compressionLevel) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibEncoder) {
        return new JZlibEncoder(compressionLevel);
    } else {
        return new JdkZlibEncoder(compressionLevel);
    }
}
 
Example 13
Source File: UkcpClientUdpChannel.java    From kcp-netty with MIT License 5 votes vote down vote up
private void doBind0(SocketAddress localAddress) throws Exception {
    if (PlatformDependent.javaVersion() >= 7) {
        SocketUtils.bind(javaChannel(), localAddress);
    } else {
        javaChannel().socket().bind(localAddress);
    }
}
 
Example 14
Source File: ZlibCodecFactory.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
public static ZlibDecoder newZlibDecoder(byte[] dictionary) {
    if (PlatformDependent.javaVersion() < 7 || noJdkZlibDecoder) {
        return new JZlibDecoder(dictionary);
    } else {
        return new JdkZlibDecoder(dictionary);
    }
}
 
Example 15
Source File: SpdyHeaderBlockEncoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
static SpdyHeaderBlockEncoder newInstance(
        SpdyVersion version, int compressionLevel, int windowBits, int memLevel) {

    if (PlatformDependent.javaVersion() >= 7) {
        return new SpdyHeaderBlockZlibEncoder(
                version, compressionLevel);
    } else {
        return new SpdyHeaderBlockJZlibEncoder(
                version, compressionLevel, windowBits, memLevel);
    }
}
 
Example 16
Source File: ReferenceCountedOpenSslContext.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public final int verify(long ssl, byte[][] chain, String auth) {
    X509Certificate[] peerCerts = certificates(chain);
    final ReferenceCountedOpenSslEngine engine = engineMap.get(ssl);
    try {
        verify(engine, peerCerts, auth);
        return CertificateVerifier.X509_V_OK;
    } catch (Throwable cause) {
        logger.debug("verification of certificate failed", cause);
        SSLHandshakeException e = new SSLHandshakeException("General OpenSslEngine problem");
        e.initCause(cause);
        engine.handshakeException = e;

        // Try to extract the correct error code that should be used.
        if (cause instanceof OpenSslCertificateException) {
            // This will never return a negative error code as its validated when constructing the
            // OpenSslCertificateException.
            return ((OpenSslCertificateException) cause).errorCode();
        }
        if (cause instanceof CertificateExpiredException) {
            return CertificateVerifier.X509_V_ERR_CERT_HAS_EXPIRED;
        }
        if (cause instanceof CertificateNotYetValidException) {
            return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
        }
        if (PlatformDependent.javaVersion() >= 7) {
            if (cause instanceof CertificateRevokedException) {
                return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
            }

            // The X509TrustManagerImpl uses a Validator which wraps a CertPathValidatorException into
            // an CertificateException. So we need to handle the wrapped CertPathValidatorException to be
            // able to send the correct alert.
            Throwable wrapped = cause.getCause();
            while (wrapped != null) {
                if (wrapped instanceof CertPathValidatorException) {
                    CertPathValidatorException ex = (CertPathValidatorException) wrapped;
                    CertPathValidatorException.Reason reason = ex.getReason();
                    if (reason == CertPathValidatorException.BasicReason.EXPIRED) {
                        return CertificateVerifier.X509_V_ERR_CERT_HAS_EXPIRED;
                    }
                    if (reason == CertPathValidatorException.BasicReason.NOT_YET_VALID) {
                        return CertificateVerifier.X509_V_ERR_CERT_NOT_YET_VALID;
                    }
                    if (reason == CertPathValidatorException.BasicReason.REVOKED) {
                        return CertificateVerifier.X509_V_ERR_CERT_REVOKED;
                    }
                }
                wrapped = wrapped.getCause();
            }
        }

        // Could not detect a specific error code to use, so fallback to a default code.
        return CertificateVerifier.X509_V_ERR_UNSPECIFIED;
    }
}
 
Example 17
Source File: ReferenceCountedOpenSslContext.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
    return PlatformDependent.javaVersion() >= 7 && trustManager instanceof X509ExtendedTrustManager;
}
 
Example 18
Source File: OpenSslContext.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
static boolean useExtendedTrustManager(X509TrustManager trustManager) {
     return PlatformDependent.javaVersion() >= 7 && trustManager instanceof X509ExtendedTrustManager;
}
 
Example 19
Source File: JdkSslEngineTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
boolean isAvailable() {
    return PlatformDependent.javaVersion() >= 9 && Java9SslUtils.supportsAlpn();
}
 
Example 20
Source File: NioDatagramChannel.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
private static void checkJavaVersion() {
    if (PlatformDependent.javaVersion() < 7) {
        throw new UnsupportedOperationException("Only supported on java 7+.");
    }
}