diff --git a/.classpath b/.classpath deleted file mode 100644 index 49e600f..0000000 --- a/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/.project b/.project deleted file mode 100644 index 76fdc47..0000000 --- a/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - StfSearcher - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/libs/mina-core-2.0.4.jar b/libs/mina-core-2.0.4.jar deleted file mode 100644 index 1e7ba38..0000000 Binary files a/libs/mina-core-2.0.4.jar and /dev/null differ diff --git a/src/com/projectswg/tools/stf/StfTable.java b/src/com/projectswg/tools/stf/StfTable.java index b964e45..39b270c 100644 --- a/src/com/projectswg/tools/stf/StfTable.java +++ b/src/com/projectswg/tools/stf/StfTable.java @@ -19,12 +19,11 @@ package com.projectswg.tools.stf; import java.io.IOException; +import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; -import org.apache.mina.core.buffer.IoBuffer; - /* * Stf files don't appear to use the IFF format. * @@ -34,92 +33,58 @@ public class StfTable { private String[][] orderedTable; private List> disorderedTable; - - public class Pair { - - private K key; - private V value; - - public Pair(K key, V value) { - this.key = key; - this.value = value; - } - - public K getKey() { - return key; - } - - public V getValue() { - return value; - } - - } - + public StfTable() { - } - - public StfTable(String filePath) throws IOException { - readFile(filePath); - } - + public void readFile(String filePath) throws IOException { java.io.FileInputStream stf = new java.io.FileInputStream(filePath); - - IoBuffer buffer = IoBuffer.allocate(stf.available(), false); - - buffer.setAutoExpand(true); - buffer.order(ByteOrder.LITTLE_ENDIAN); - - byte[] buf = new byte[1024]; - - for (int i = stf.read(buf); i != -1; i = stf.read(buf)) { - buffer.put(buf, 0, i); - } - - buffer.flip(); - - buffer.getInt(); // Size? - - buffer.get(); // isMore? - - int arrayCount = buffer.getInt(); - - int rowCount = buffer.getInt(); - + + byte[] buffer = new byte[stf.available()]; + stf.read(buffer); + + ByteBuffer byteBuffer = ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN); + + byteBuffer.getInt(); // Size? + byteBuffer.get(); // isMore? + + int arrayCount = byteBuffer.getInt(); + + int rowCount = byteBuffer.getInt(); + orderedTable = new String[arrayCount][2]; - disorderedTable = new ArrayList>(); - + disorderedTable = new ArrayList<>(); + for (int i = 0; i < rowCount; i++) { - int id = buffer.getInt(); - buffer.getInt(); + int id = byteBuffer.getInt(); + byteBuffer.getInt(); String value = ""; - value = StringUtilities.getUnicodeString(buffer, true); + value = StringUtilities.getUnicodeString(byteBuffer, true); orderedTable[id][0] = null; orderedTable[id][1] = value; } - + for (int i = 0; i < rowCount; i++) { - int id = buffer.getInt(); - String name = StringUtilities.getAsciiString(buffer, true); + int id = byteBuffer.getInt(); + String name = StringUtilities.getAsciiString(byteBuffer, true); orderedTable[id][0] = name; disorderedTable.add(new Pair(name, orderedTable[id][1])); } - + stf.close(); } - + public int getRowCount() { return ((orderedTable == null) ? 0 : orderedTable.length); } - + public int getColumnCount() { return ((orderedTable == null) ? 0 : 3); } - + /* * @param id Iteration number - * + * * @returns String's key-value pair from an alphanumeric list */ public Pair getString(int id) { @@ -128,7 +93,7 @@ public class StfTable { /* * @param id Identifying number of the string from the .stf file, unlike above - * + * * @returns String's key-value pair from an unordered list */ public Pair getStringById(int id) { @@ -137,7 +102,7 @@ public class StfTable { /* * @param name Name of the string to return - * + * * @returns The value for this key, or null if the key is not found */ public String getString(String name) { @@ -146,8 +111,28 @@ public class StfTable { return columns[1]; } } - + return null; } + + public class Pair { + + private K key; + private V value; + + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + + } } diff --git a/src/com/projectswg/tools/stf/StringUtilities.java b/src/com/projectswg/tools/stf/StringUtilities.java index c3b3e2e..b4bd4a9 100644 --- a/src/com/projectswg/tools/stf/StringUtilities.java +++ b/src/com/projectswg/tools/stf/StringUtilities.java @@ -19,21 +19,20 @@ package com.projectswg.tools.stf; import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.apache.mina.core.buffer.IoBuffer; - public class StringUtilities { - - public static String getUnicodeString(IoBuffer buffer, boolean integer) { + + public static String getUnicodeString(ByteBuffer buffer, boolean integer) { return getString(buffer, "UTF-16LE", integer); } - - public static String getAsciiString(IoBuffer buffer, boolean integer) { + + public static String getAsciiString(ByteBuffer buffer, boolean integer) { return getString(buffer, "US-ASCII", integer); } - - private static String getString(IoBuffer buffer, String charFormat, boolean integer) { + + private static String getString(ByteBuffer buffer, String charFormat, boolean integer) { String result; int length;