String foundName = null;
byte[] name = new byte[1024];
ByteBuffer buffer = getTableBuffer(nameTag);
if (buffer != null) {
ShortBuffer sbuffer = buffer.asShortBuffer();
sbuffer.get(); // format - not needed.
short numRecords = sbuffer.get();
/* The name table uses unsigned shorts. Many of these
* are known small values that fit in a short.
* The values that are sizes or offsets into the table could be
* greater than 32767, so read and store those as ints
*/
int stringPtr = ((int) sbuffer.get()) & 0xffff;
for (int i=0; i<numRecords; i++) {
short platformID = sbuffer.get();
if (platformID != MS_PLATFORM_ID) {
sbuffer.position(sbuffer.position()+5);
continue; // skip over this record.
}
short encodingID = sbuffer.get();
short langID = sbuffer.get();
short nameID = sbuffer.get();
int nameLen = ((int) sbuffer.get()) & 0xffff;
int namePtr = (((int) sbuffer.get()) & 0xffff) + stringPtr;
if (nameID == findNameID &&
((foundName == null && langID == ENGLISH_LOCALE_ID)
|| langID == findLocaleID)) {
buffer.position(namePtr);
buffer.get(name, 0, nameLen);