Skip to content

Commit

Permalink
Cast a ByteBuffer to a Buffer before calling flip. This fixes compili…
Browse files Browse the repository at this point in the history
…ng to JDK 7 from JDK9+ compilers.

Details: plasma-umass/doppio#497
  • Loading branch information
Pedro Ferreira committed Jun 12, 2018
1 parent a3dcb32 commit b438f8a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package nl.cwi.monetdb.mcl.connection.helpers;

import java.nio.Buffer;
import java.nio.CharBuffer;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ private static int getNewCapacity(CharBuffer buffer) {
public static CharBuffer reallocateBuffer(CharBuffer buffer) {
int newCapacity = getNewCapacity(buffer);
CharBuffer newBuffer = CharBuffer.wrap(new char[newCapacity]);
buffer.flip();
((Buffer)buffer).flip();
newBuffer.put(buffer.array());
return newBuffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
Expand Down Expand Up @@ -56,7 +57,7 @@ public abstract class AbstractSocket implements Closeable {
this.bufferIn = ByteBuffer.wrap(new byte[getFullBlockSize()]);
this.bufferOut = ByteBuffer.wrap(new byte[getFullBlockSize()]);
this.stringsDecoded = CharBuffer.allocate(getFullBlockSize());
this.stringsDecoded.flip();
((Buffer)this.stringsDecoded).flip();
this.stringsEncoded = CharBuffer.allocate(getFullBlockSize());
}

Expand Down Expand Up @@ -151,7 +152,7 @@ private void readToInputBuffer() throws IOException {
this.utf8Decoder.reset();
this.utf8Decoder.decode(this.bufferIn, this.stringsDecoded,true);
this.utf8Decoder.flush(this.stringsDecoded);
this.stringsDecoded.flip();
((Buffer)this.stringsDecoded).flip();
}

/**
Expand Down Expand Up @@ -193,7 +194,7 @@ public CharBuffer readLine(CharBuffer lineBuffer) throws IOException {
}
this.stringsDecoded.position(sourcePosition);
lineBuffer.position(destinationPosition);
lineBuffer.flip();
((Buffer)lineBuffer).flip();
return lineBuffer;
}

Expand All @@ -204,7 +205,7 @@ public CharBuffer readLine(CharBuffer lineBuffer) throws IOException {
* @throws IOException If an error in the underlying connection happened
*/
private void writeToOutputBuffer(boolean toFlush) throws IOException {
this.stringsEncoded.flip();
((Buffer)this.stringsEncoded).flip();
this.utf8Encoder.reset();
CoderResult res;
int written = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;

/**
Expand Down Expand Up @@ -241,7 +242,7 @@ public int read(ByteBuffer b, int off, int len) throws IOException {
connection.getPort() + ": Incomplete block read from stream");
}
b.position(size);
b.flip();
((Buffer)b).flip();
return size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import nl.cwi.monetdb.mcl.responses.UpdateResponse;

import java.io.IOException;
import java.nio.Buffer;
import java.nio.CharBuffer;
import java.text.SimpleDateFormat;
import java.util.Map;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void fetchNextResponseData() throws IOException {
newbuffer.put("!22000");
newbuffer.put(this.lineBuffer.array(), 0, limit);
newbuffer.limit(limit + 6);
newbuffer.flip();
((Buffer)newbuffer).flip();
this.lineBuffer = newbuffer;
}
this.lineBuffer.position(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import nl.cwi.monetdb.mcl.protocol.ProtocolException;

import java.math.BigDecimal;
import java.nio.Buffer;
import java.nio.CharBuffer;
import java.sql.Types;
import java.util.Calendar;
Expand Down Expand Up @@ -163,7 +164,7 @@ static int oldMapiParseTupleLine(OldMapiProtocol protocol, int lineNumber, int[]
}
}
// put the unescaped string in the right place
tupleLineBuffer.flip();
((Buffer)tupleLineBuffer).flip();
oldMapiStringToJavaDataConversion(protocol, tupleLineBuffer.array(), 0,
tupleLineBuffer.limit(), lineNumber, values[column], typesMap[column]);
} else if ((i - 1) - cursor == 4 && OldMapiTupleLineParserHelper.charIndexOf(array,
Expand Down

0 comments on commit b438f8a

Please sign in to comment.