Skip to content
Permalink
Browse files

Fixed build and tests on JDK 11

  • Loading branch information...
apangin committed Apr 12, 2019
1 parent 3202cdb commit fe1f655142ef562a10fe418765da6f0a1ebd7c44
Showing with 22 additions and 24 deletions.
  1. +4 −1 pom.xml
  2. +18 −23 test/one/nio/lz4/LZ4Test.java
@@ -144,7 +144,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<version>3.0.1</version>
<configuration>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
@@ -4,40 +4,35 @@
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

public class LZ4Test {

@Test
public void compressAllClasses() throws IOException {
try (JarFile jf = new JarFile(System.getProperty("java.home") + "/lib/rt.jar")) {
for (Enumeration<JarEntry> entries = jf.entries(); entries.hasMoreElements(); ) {
JarEntry je = entries.nextElement();
if (je.isDirectory()) continue;

try (InputStream is = jf.getInputStream(je)) {
byte[] data = readResource(is, (int) je.getSize());
public void compressAllFiles() throws IOException {
Path javaHome = Paths.get(System.getProperty("java.home"));
Files.walkFileTree(javaHome, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (attrs.isRegularFile()) {
byte[] data = Files.readAllBytes(file);
int bytes1 = testCompression1(data);
int bytes2 = testCompression2(data);
Assert.assertEquals(bytes1, bytes2);
}
}
}
}

private byte[] readResource(InputStream is, int size) throws IOException {
byte[] uncompressed = new byte[size];
for (int p = 0; p < size; ) {
p += is.read(uncompressed, p, size - p);
}
return uncompressed;
return FileVisitResult.CONTINUE;
}
});
}

private int testCompression1(byte[] data) throws IOException {
private int testCompression1(byte[] data) {
byte[] compressed = new byte[LZ4.compressBound(data.length)];
int bytesCompressed = LZ4.compress(data, compressed);
ByteBuffer out = ByteBuffer.allocateDirect(data.length);
@@ -50,7 +45,7 @@ private int testCompression1(byte[] data) throws IOException {
return bytesCompressed;
}

private int testCompression2(byte[] data) throws IOException {
private int testCompression2(byte[] data) {
ByteBuffer compressed = ByteBuffer.allocateDirect(LZ4.compressBound(data.length));
int bytesCompressed = LZ4.compress(ByteBuffer.wrap(data), compressed);
compressed.flip();

0 comments on commit fe1f655

Please sign in to comment.
You can’t perform that action at this time.