Browse Source

PR 53457 - ByteBuffer::limit and ByteBuffer::rewind are new methods linked when building on jdk11 this prevents running ZIP related tasks on jdk8 from completing successfully

master
jkf 6 years ago
parent
commit
823a5316eb
3 changed files with 19 additions and 7 deletions
  1. +3
    -2
      src/main/org/apache/tools/zip/NioZipEncoding.java
  2. +2
    -2
      src/main/org/apache/tools/zip/Simple8BitZipEncoding.java
  3. +14
    -3
      src/main/org/apache/tools/zip/ZipEncodingHelper.java

+ 3
- 2
src/main/org/apache/tools/zip/NioZipEncoding.java View File

@@ -20,6 +20,7 @@
package org.apache.tools.zip; package org.apache.tools.zip;


import java.io.IOException; import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@@ -102,8 +103,8 @@ class NioZipEncoding implements ZipEncoding {
} }
} }


out.limit(out.position());
out.rewind();
ZipEncodingHelper.prepareBufferForRead(out);
return out; return out;
} }




+ 2
- 2
src/main/org/apache/tools/zip/Simple8BitZipEncoding.java View File

@@ -20,6 +20,7 @@
package org.apache.tools.zip; package org.apache.tools.zip;


import java.io.IOException; import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@@ -247,8 +248,7 @@ class Simple8BitZipEncoding implements ZipEncoding {
} }
} }


out.limit(out.position());
out.rewind();
ZipEncodingHelper.prepareBufferForRead(out);
return out; return out;
} }




+ 14
- 3
src/main/org/apache/tools/zip/ZipEncodingHelper.java View File

@@ -18,6 +18,7 @@


package org.apache.tools.zip; package org.apache.tools.zip;


import java.nio.Buffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
@@ -147,15 +148,25 @@ public abstract class ZipEncodingHelper {
* *
*/ */
static ByteBuffer growBuffer(final ByteBuffer b, final int newCapacity) { static ByteBuffer growBuffer(final ByteBuffer b, final int newCapacity) {
b.limit(b.position());
b.rewind();

prepareBufferForRead(b);
final int c2 = b.capacity() * 2; final int c2 = b.capacity() * 2;
final ByteBuffer on = ByteBuffer.allocate(c2 < newCapacity ? newCapacity : c2); final ByteBuffer on = ByteBuffer.allocate(c2 < newCapacity ? newCapacity : c2);


on.put(b); on.put(b);
return on; return on;
} }
/**
* Prepares a buffer to be read after writing.
*
* @param b The buffer
*/
static void prepareBufferForRead(final Buffer b) {
// ByteBuffer has overridden methods in java 11 but not in java 8
// so the Buffer is significant to get java 8 compatible classes
b.limit(b.position());
b.rewind();
}




/** /**


Loading…
Cancel
Save