Move loadResourceAsString to Resource class

It doesn't make much sense for this function to sit
inside IconResources, as it isn't an IconResource.
This commit is contained in:
Jannis Weis 2022-04-25 17:51:58 +02:00
parent 3d1f614687
commit 47e069c44f
No known key found for this signature in database
GPG key ID: 7C9D8D4B558049AB
4 changed files with 19 additions and 12 deletions

View file

@ -4,6 +4,7 @@ import java.io.IOException;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.resources.IconResources; import the.bytecode.club.bytecodeviewer.resources.IconResources;
import the.bytecode.club.bytecodeviewer.resources.Resource;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -46,7 +47,7 @@ public enum PluginTemplate
public String getContents() throws IOException public String getContents() throws IOException
{ {
if(contents == null) if(contents == null)
contents = IconResources.loadResourceAsString(resourcePath); contents = Resource.loadResourceAsString(resourcePath);
return contents; return contents;
} }

View file

@ -112,15 +112,6 @@ public class IconResources
} }
} }
public static String loadResourceAsString(String resourcePath) throws IOException
{
try (InputStream is = IconResources.class.getResourceAsStream(resourcePath)) {
if (is == null)
return null;
return IOUtils.toString(is, StandardCharsets.UTF_8);
}
}
public static BufferedImage resize(BufferedImage image, int width, int height) { public static BufferedImage resize(BufferedImage image, int width, int height) {
return Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, width, height); return Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, width, height);
} }

View file

@ -1,7 +1,12 @@
package the.bytecode.club.bytecodeviewer.resources; package the.bytecode.club.bytecodeviewer.resources;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com * * Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
@ -36,6 +41,15 @@ public class Resource
this.workingName = workingName; this.workingName = workingName;
this.container = container; this.container = container;
} }
public static String loadResourceAsString(String resourcePath) throws IOException
{
try (InputStream is = IconResources.class.getResourceAsStream(resourcePath)) {
if (is == null)
return null;
return IOUtils.toString(is, StandardCharsets.UTF_8);
}
}
/** /**
* Returns the resource bytes from the resource container * Returns the resource bytes from the resource container

View file

@ -14,6 +14,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Constants; import the.bytecode.club.bytecodeviewer.Constants;
import the.bytecode.club.bytecodeviewer.api.BCV; import the.bytecode.club.bytecodeviewer.api.BCV;
import the.bytecode.club.bytecodeviewer.resources.IconResources; import the.bytecode.club.bytecodeviewer.resources.IconResources;
import the.bytecode.club.bytecodeviewer.resources.Resource;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -158,7 +159,7 @@ public enum Language
if(translationMap == null) if(translationMap == null)
{ {
translationMap = BytecodeViewer.gson.fromJson( translationMap = BytecodeViewer.gson.fromJson(
IconResources.loadResourceAsString(resourcePath), Resource.loadResourceAsString(resourcePath),
new TypeToken<HashMap<String, String>>() {}.getType()); new TypeToken<HashMap<String, String>>() {}.getType());
} }
@ -178,7 +179,7 @@ public enum Language
return; return;
LinkedMap<String, String> translationMap = BytecodeViewer.gson.fromJson( LinkedMap<String, String> translationMap = BytecodeViewer.gson.fromJson(
IconResources.loadResourceAsString(resourcePath), Resource.loadResourceAsString(resourcePath),
new TypeToken<LinkedMap<String, String>>(){}.getType()); new TypeToken<LinkedMap<String, String>>(){}.getType());
Set<String> existingKeys = new HashSet<>(); Set<String> existingKeys = new HashSet<>();