Skip to content

Commit

Permalink
Merge pull request #24 from breiler/load-local-config
Browse files Browse the repository at this point in the history
Allow loading mappings from local file path
  • Loading branch information
MrStahlfelge authored Oct 30, 2023
2 parents bb3661b + 66a8ad4 commit 783336a
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.badlogic.gdx.utils.SharedLibraryLoader;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -283,6 +285,7 @@ public boolean update() {
public void addMappingsFromFile(String path) throws IOException, IllegalStateException {
InputStream source = getClass().getResourceAsStream(path);
if(source==null) source = ClassLoader.getSystemResourceAsStream(path);
if(source==null && new File(path).exists()) source = new FileInputStream(path);
if(source==null) throw new IOException("Cannot open resource from classpath "+path);

if(configuration.loadDatabaseInMemory) {
Expand All @@ -294,6 +297,7 @@ public void addMappingsFromFile(String path) throws IOException, IllegalStateExc
while((read = source.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, read);
}
source.close();

byte[] b = buffer.toByteArray();
if(!nativeAddMappingsFromBuffer(b, b.length)) {
Expand Down

0 comments on commit 783336a

Please sign in to comment.