Skip to content

Commit af6d7bf

Browse files
committed
Cast ByteBuffer instances to Buffer to solve compatibility issue
These changes were applied to ease further work on java9. For more inforemation see https://jira.mongodb.org/browse/JAVA-2559 DEVSIX-1680
1 parent 1ef9b02 commit af6d7bf

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

io/src/main/java/com/itextpdf/io/source/ByteBufferRandomAccessSource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This file is part of the iText (R) project.
5353
import java.io.Serializable;
5454
import java.lang.invoke.MethodHandle;
5555
import java.lang.reflect.Method;
56+
import java.nio.Buffer;
5657
import java.nio.BufferUnderflowException;
5758
import java.security.AccessController;
5859
import java.security.PrivilegedAction;
@@ -100,7 +101,7 @@ public int get(long position) throws java.io.IOException {
100101
throw new IllegalArgumentException("Position must be less than Integer.MAX_VALUE");
101102
try {
102103

103-
if (position >= byteBuffer.limit())
104+
if (position >= ((Buffer) byteBuffer).limit())
104105
return -1;
105106
byte b = byteBuffer.get((int) position);
106107
return b & 0xff;
@@ -120,11 +121,11 @@ public int get(long position, byte[] bytes, int off, int len) throws java.io.IOE
120121
if (position > Integer.MAX_VALUE)
121122
throw new IllegalArgumentException("Position must be less than Integer.MAX_VALUE");
122123

123-
if (position >= byteBuffer.limit())
124+
if (position >= ((Buffer) byteBuffer).limit())
124125
return -1;
125126

126127
// Not thread safe!
127-
byteBuffer.position((int) position);
128+
((Buffer) byteBuffer).position((int) position);
128129
int bytesFromThisBuffer = Math.min(len, byteBuffer.remaining());
129130
byteBuffer.get(bytes, off, bytesFromThisBuffer);
130131

@@ -136,7 +137,7 @@ public int get(long position, byte[] bytes, int off, int len) throws java.io.IOE
136137
* {@inheritDoc}
137138
*/
138139
public long length() {
139-
return byteBuffer.limit();
140+
return ((Buffer) byteBuffer).limit();
140141
}
141142

142143
/**

io/src/main/java/com/itextpdf/io/util/EncodingUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.io.font.PdfEncodings;
4747

4848
import java.io.UnsupportedEncodingException;
49+
import java.nio.Buffer;
4950
import java.nio.CharBuffer;
5051
import java.nio.charset.CharacterCodingException;
5152
import java.nio.charset.Charset;
@@ -66,8 +67,8 @@ public static byte[] convertToBytes(char[] chars, String encoding) throws Charac
6667
CharsetEncoder ce = cc.newEncoder();
6768
ce.onUnmappableCharacter(CodingErrorAction.IGNORE);
6869
java.nio.ByteBuffer bb = ce.encode(CharBuffer.wrap(chars));
69-
bb.rewind();
70-
int lim = bb.limit();
70+
((Buffer) bb).rewind();
71+
int lim = ((Buffer) bb).limit();
7172
int offset = PdfEncodings.UTF8.equals(encoding) ? 3 : 0;
7273
byte[] br = new byte[lim + offset];
7374
if (PdfEncodings.UTF8.equals(encoding)) {

0 commit comments

Comments
 (0)