List Resource Bundle Creator
/*
Java Internationalization
By Andy Deitsch, David Czarnecki
ISBN: 0-596-00019-7
O'Reilly
*/
/*import java.io.*;
import java.util.Vector;
public class ListResourceBundleCreator {
public static void main(String [] argv) throws Exception{
FileInputStream inputFileReader = new FileInputStream(argv[0]);
DataInputStream dis = new DataInputStream(inputFileReader);
long fileSize;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Vector myVector = new Vector();
while (true) {
try {
myVector.addElement(new Integer(dis.readUnsignedByte()));
} catch (EOFException e) {
break;
}
}
fileSize = myVector.size();
FileWriter outputFileWriter = new FileWriter(argv[2] + ".java");
outputFileWriter.write("import java.util.ListResourceBundle;\n\n");
outputFileWriter.write("public class " + argv[2] + " extends ListResourceBundle {\n\n");
outputFileWriter.write(" public Object [][] getContents() {\n");
outputFileWriter.write(" return contents;\n");
outputFileWriter.write(" }\n\n");
outputFileWriter.write(" static byte [] " + argv[1] + " = {\n");
for (int i = 0; i < fileSize; i++) {
outputFileWriter.write("\t(byte)");
outputFileWriter.write(((Integer)myVector.elementAt(i)).toString());
if (i < fileSize - 1)
outputFileWriter.write(",\n");
}
outputFileWriter.write("\n\t};\n\n");
outputFileWriter.write(" static final Object [][] contents = {\n");
outputFileWriter.write(" {\"" + argv[1] + "\", " + argv[1] + "}\n");
outputFileWriter.write(" };\n");
outputFileWriter.write("}\n");
outputFileWriter.close();
}
}
*/
import java.io.*;
import java.util.Vector;
public class ListResourceBundleCreator {
public static void main(String [] argv) throws Exception{
FileInputStream inputFileReader = new FileInputStream(argv[0]);
DataInputStream dis = new DataInputStream(inputFileReader);
long fileSize;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Vector myVector = new Vector();
while (true) {
try {
myVector.addElement(new Integer(dis.readUnsignedByte()));
} catch (EOFException e) {
break;
}
}
fileSize = myVector.size();
FileWriter outputFileWriter = new FileWriter(argv[2] + ".java");
outputFileWriter.write("import java.util.ListResourceBundle;\n\n");
outputFileWriter.write("public class " + argv[2] +
" extends ListResourceBundle {\n\n");
outputFileWriter.write(" public Object [][] getContents() {\n");
outputFileWriter.write(" return contents;\n");
outputFileWriter.write(" }\n\n");
outputFileWriter.write(" static byte [] " + argv[1] + " = {\n");
for (int i = 0; i < fileSize; i++) {
outputFileWriter.write("\t(byte)");
outputFileWriter.write(((Integer)myVector.elementAt(i)).toString());
if (i < fileSize - 1)
outputFileWriter.write(",\n");
}
outputFileWriter.write("\n\t};\n\n");
outputFileWriter.write(" static final Object [][] contents = {\n");
outputFileWriter.write(" {\"" + argv[1] + "\", " + argv[1] + "}\n");
outputFileWriter.write(" };\n");
outputFileWriter.write("}\n");
outputFileWriter.close();
}
}
Related examples in the same category