Code example for RandomAccessFile

Methods: length, seek, skipBytes

0
			int nIndex, int data[]) {
		int ret = 0;
		try { 
			if (offset == 0) {
				int pos = 0;
				file.seek(file.length() - 4);
				pos = readIntLittleEndian(file);
				file.seek(file.length() - pos);
 
			} else { 
				file.seek(offset);
			} 
			int buffer[] = new int[2];
			buffer[0] = readIntLittleEndian(file);
			buffer[1] = readIntLittleEndian(file);
			if ((foucc == 0 || foucc == buffer[0])
					&& (nIndex > 0 && nIndex < buffer[1])) {
				file.skipBytes((nIndex - 1) * 4);
				buffer[0] = readIntLittleEndian(file);
				buffer[1] = readIntLittleEndian(file);
				ret = buffer[0];
				data[0] = buffer[0];
				data[1] = buffer[1];
				// if(pLength) *pLength = buffer[1]-buffer[0]; 
			} else if (foucc == buffer[0] && nIndex == 0) {
				return buffer[1];
			} 
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return ret;
	} 
 
	// private static byte[] fourccFile = {'F', 'I', 'L', 0}; 
	// private static byte[] fourccStringUtf8 = {'S', 'T', 'R', 0}; 
	// private static byte[] fourccStringUtf16 = {'S', 'T', 'R', 1}; 
	private static byte[] fourccOffset32 = { 'O', 'F', 'S', 0 };
	// private static byte[] fourccOffset64 = {'O', 'F', 'S', 1}; 
	private static byte[] fourccBfs = { 'B', 'F', 'S', 0 };
	private static byte[] fourccDWORD = { 'D', 'W', 'D', 0 };
 
	// list all filename from BFES file. 
	public static String[] getBfsFilenames(String fileName) {
 
		String[] names = null;
		try { 
			int data[] = new int[2];
			RandomAccessFile file = new RandomAccessFile(fileName, "r");
			int m_lNameTableOffset = getOffset(file, FOURCC(fourccBfs), 0, 2,
					data);
			int i;
			int nCount = getOffset(file, FOURCC(fourccOffset32),
					m_lNameTableOffset, 0, data);
			names = new String[nCount];
			for (i = 1; i < nCount; i++) {
				int t = getOffset(file, FOURCC(fourccOffset32),
						m_lNameTableOffset, i, data);
				int len = data[1] - data[0];
				byte p[] = new byte[len];
				file.seek(t);
				file.read(p, 0, len);
				names[i] = new String(p);
			} 
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return names;
	} 
 
	// get bfe file version. 
	public static int getBfsVersion(String fileName) {
		int ver = 0;
		try { 
			int data[] = new int[2];
			RandomAccessFile file = new RandomAccessFile(fileName, "r");
			int m_lNameTableOffset = getOffset(file, FOURCC(fourccBfs), 0, 4,
					data);
			ver = getOffset(file, FOURCC(fourccDWORD), m_lNameTableOffset, 1,
					data);
		} catch (Exception e) {