Trying to load a Font from resources throws a BufferUnderflowException

I am trying to load a Selawik font from my project's resources with following code:
try (InputStream is = getClass().getResourceAsStream("/fonts/selawk.ttf")) {
    Font selawik = Font.createFont(Font.TRUETYPE_FONT, is);
}

but it results in an exception:
java.awt.FontFormatException: java.nio.BufferUnderflowException
    at java.desktop/sun.font.TrueTypeFont.init(TrueTypeFont.java:532)
    at java.desktop/sun.font.TrueTypeFont.<init>(TrueTypeFont.java:216)
    at java.desktop/sun.font.TrueTypeFont.<init>(TrueTypeFont.java:196)
    at java.desktop/sun.font.SunFontManager.createFont2D(SunFontManager.java:2208)
    at java.desktop/java.awt.Font.createFont0(Font.java:1169)
    at java.desktop/java.awt.Font.createFont(Font.java:1076)
    at io.github.defective4.onematch.game.Application.<init>(Application.java:82)
    at io.github.defective4.onematch.game.Application.<clinit>(Application.java:69)

Does anyone have any clue why? The font appears to be a valid TrueType font, but Java still refuses to load it...
Was this page helpful?