Removed mina dependency

This commit is contained in:
Waverunner
2015-05-28 09:22:17 -04:00
parent b10d6653ad
commit 62021393b5
5 changed files with 59 additions and 99 deletions

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="libs/mina-core-2.0.4.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>StfSearcher</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

Binary file not shown.

View File

@@ -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<Pair<String, String>> disorderedTable;
public class Pair<K, V> {
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<Pair<String, String>>();
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<String, String>(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<String, String> 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<String, String> 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<K, V> {
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;
}
}
}

View File

@@ -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;