-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
module net.vinrobot.webp.foreign.jdk21 { | ||
requires net.vinrobot.webp; | ||
requires java.desktop; | ||
|
||
exports net.vinrobot.webp.foreign.jdk21; | ||
|
||
provides net.vinrobot.webp.WebPReaderSpi with net.vinrobot.webp.foreign.jdk21.JDK21WebPReaderSpi; | ||
provides javax.imageio.spi.ImageReaderSpi with net.vinrobot.webp.foreign.jdk21.JDK21WebPImageReaderSpi; | ||
} |
38 changes: 38 additions & 0 deletions
38
...ebp-foreign-jdk21/src/main/java/net/vinrobot/webp/foreign/jdk21/JDK21WebPImageReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.vinrobot.webp.foreign.jdk21; | ||
|
||
import net.vinrobot.webp.WebPReader; | ||
import net.vinrobot.webp.imageio.BaseImageReader; | ||
|
||
import javax.imageio.spi.ImageReaderSpi; | ||
import javax.imageio.stream.ImageInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
public class JDK21WebPImageReader extends BaseImageReader { | ||
private static final int DEFAULT_BUFFER_SIZE = 16384; | ||
|
||
public JDK21WebPImageReader(final ImageReaderSpi originatingProvider) { | ||
super(originatingProvider); | ||
} | ||
|
||
private static byte[] readAll(final ImageInputStream stream) throws IOException { | ||
try (final ByteArrayOutputStream result = new ByteArrayOutputStream()) { | ||
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; | ||
int length; | ||
while ((length = stream.read(buffer)) != -1) { | ||
result.write(buffer, 0, length); | ||
} | ||
return result.toByteArray(); | ||
} | ||
} | ||
|
||
@Override | ||
protected WebPReader getReader(final ImageInputStream stream) throws IOException { | ||
return this.getReader(readAll(stream)); | ||
} | ||
|
||
@Override | ||
protected WebPReader getReader(final byte[] data) throws IOException { | ||
return new JDK21WebPReader(data, 0, data.length); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...-foreign-jdk21/src/main/java/net/vinrobot/webp/foreign/jdk21/JDK21WebPImageReaderSpi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.vinrobot.webp.foreign.jdk21; | ||
|
||
import net.vinrobot.webp.foreign.jdk21.internal.Loader; | ||
import net.vinrobot.webp.imageio.BaseImageReaderSpi; | ||
|
||
import javax.imageio.ImageReader; | ||
import javax.imageio.stream.ImageInputStream; | ||
import java.io.IOException; | ||
|
||
public final class JDK21WebPImageReaderSpi extends BaseImageReaderSpi { | ||
public JDK21WebPImageReaderSpi() { | ||
super(JDK21WebPImageReader.class, new Class[]{ImageInputStream.class, byte[].class}); | ||
} | ||
|
||
@Override | ||
public boolean canDecodeInput(final Object source) throws IOException { | ||
if (!super.canDecodeInput(source)) { | ||
return false; | ||
} | ||
|
||
try { | ||
// The reader needs the native library to work | ||
Loader.ensureLibrary(); | ||
return true; | ||
} catch (Exception ex) { | ||
// Unable to load native library | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public ImageReader createReaderInstance(final Object extension) { | ||
return new JDK21WebPImageReader(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
libwebp-foreign-jdk21/src/main/resources/META-INF/services/javax.imageio.spi.ImageReaderSpi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
net.vinrobot.webp.foreign.jdk21.JDK21WebPImageReaderSpi |
17 changes: 17 additions & 0 deletions
17
...eign-jdk21/src/test/java/net/vinrobot/webp/foreign/jdk21/JDK21WebPImageReaderSpiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.vinrobot.webp.foreign.jdk21; | ||
|
||
import net.vinrobot.webp.ImageReaderSpiTest; | ||
|
||
import javax.imageio.spi.ImageReaderSpi; | ||
|
||
class JDK21WebPImageReaderSpiTest extends ImageReaderSpiTest { | ||
@Override | ||
public Class<? extends ImageReaderSpi> getServiceClass() { | ||
return JDK21WebPImageReaderSpi.class; | ||
} | ||
|
||
@Override | ||
public ImageReaderSpi getService() { | ||
return new JDK21WebPImageReaderSpi(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...foreign-jdk21/src/test/java/net/vinrobot/webp/foreign/jdk21/JDK21WebPImageReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.vinrobot.webp.foreign.jdk21; | ||
|
||
import net.vinrobot.webp.ImageReaderTest; | ||
|
||
import javax.imageio.ImageReader; | ||
import java.io.IOException; | ||
|
||
class JDK21WebPImageReaderTest extends ImageReaderTest { | ||
@Override | ||
public Class<? extends ImageReader> getImageReaderClass() { | ||
return JDK21WebPImageReader.class; | ||
} | ||
|
||
@Override | ||
public ImageReader newImageReader() { | ||
try { | ||
return new JDK21WebPImageReaderSpi().createReaderInstance(); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |