Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Java 8 for ByteBuffer #3545

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -248,18 +249,18 @@ private Message<?> decodeNativeFormat(byte[] bytes, @Nullable Map<String, Object
if (buffer.remaining() > 4) { // NOSONAR
int headersLen = buffer.getInt();
if (headersLen >= 0 && headersLen < buffer.remaining() - 4) { // NOSONAR
buffer.position(headersLen + 4); // NOSONAR
((Buffer) buffer).position(headersLen + 4); // NOSONAR
int payloadLen = buffer.getInt();
if (payloadLen != buffer.remaining()) {
return null;
}
else {
buffer.position(4); // NOSONAR
((Buffer) buffer).position(4); // NOSONAR
@SuppressWarnings("unchecked")
Map<String, Object> headers = this.objectMapper.readValue(bytes, buffer.position(), headersLen,
Map.class);

buffer.position(buffer.position() + headersLen);
((Buffer) buffer).position(buffer.position() + headersLen);
buffer.getInt();
Object payload;
byte[] payloadBytes = new byte[payloadLen];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package org.springframework.integration.ip.tcp.connection;

import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.concurrent.Semaphore;
Expand Down Expand Up @@ -135,7 +136,7 @@ protected void sendToPipe(final ByteBuffer networkBuffer) throws IOException {
networkBuffer.compact();
}
else {
networkBuffer.clear();
((Buffer) networkBuffer).clear();
}
if (logger.isDebugEnabled()) {
logger.debug("sendToPipe.x " + resultToString(result) + ", remaining: " + networkBuffer.remaining());
Expand All @@ -160,7 +161,7 @@ private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException {
case NEED_UNWRAP:
case FINISHED:
case NOT_HANDSHAKING:
this.decoded.clear();
((Buffer) this.decoded).clear();
result = this.sslEngine.unwrap(networkBuffer, this.decoded);
if (logger.isDebugEnabled()) {
logger.debug("After unwrap: " + resultToString(result));
Expand All @@ -171,13 +172,13 @@ private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException {
this.allocateEncryptionBuffer(this.sslEngine.getSession().getApplicationBufferSize());
}
if (result.bytesProduced() > 0) {
this.decoded.flip();
((Buffer) this.decoded).flip();
super.sendToPipe(this.decoded);
}
break;
case NEED_WRAP:
if (!resumeWriterIfNeeded()) {
this.encoded.clear();
((Buffer) this.encoded).clear();
result = this.sslEngine.wrap(networkBuffer, this.encoded);
if (logger.isDebugEnabled()) {
logger.debug("After wrap: " + resultToString(result));
Expand All @@ -186,7 +187,7 @@ private SSLEngineResult decode(ByteBuffer networkBuffer) throws IOException {
this.encoded = this.allocateEncryptionBuffer(this.sslEngine.getSession().getPacketBufferSize());
}
else {
this.encoded.flip();
((Buffer) this.encoded).flip();
getSSLChannelOutputStream().writeEncoded(this.encoded);
}
}
Expand Down Expand Up @@ -393,9 +394,9 @@ private void doClientSideHandshake(ByteBuffer plainText, SSLEngineResult resultA
}

private void writeEncodedIfAny() throws IOException {
TcpNioSSLConnection.this.encoded.flip();
((Buffer) TcpNioSSLConnection.this.encoded).flip();
writeEncoded(TcpNioSSLConnection.this.encoded);
TcpNioSSLConnection.this.encoded.clear();
((Buffer) TcpNioSSLConnection.this.encoded).clear();
}

/**
Expand Down Expand Up @@ -430,7 +431,7 @@ else if (!isOpen()) {
* Encrypts plain text data. The result may indicate handshaking is needed.
*/
private SSLEngineResult encode(ByteBuffer plainText) throws IOException {
TcpNioSSLConnection.this.encoded.clear();
((Buffer) TcpNioSSLConnection.this.encoded).clear();
SSLEngineResult result =
TcpNioSSLConnection.this.sslEngine.wrap(plainText, TcpNioSSLConnection.this.encoded);
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.io.UncheckedIOException;
import java.io.UnsupportedEncodingException;
import java.net.DatagramPacket;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -303,7 +304,7 @@ private boolean startsWith(ByteBuffer buffer, String prefix) {
}
finally {
//reposition the buffer
buffer.position(pos);
((Buffer) buffer).position(pos);
}
}

Expand Down