Example #1
0
 /**
  * 读取头文件
  *
  * @param dis
  * @return
  * @throws Exception
  */
 public static LPKHeader readHeader(DataInputStream dis) throws Exception {
   LPKHeader header = new LPKHeader();
   header.setPAKIdentity(dis.readInt());
   byte[] pass = readByteArray(dis, LPKHeader.LF_PASSWORD_LENGTH);
   header.setPassword(pass);
   header.setVersion(dis.readFloat());
   header.setTables(dis.readLong());
   return header;
 }
Example #2
0
 /**
  * 返回LPK文件信息
  *
  * @param pakFilePath
  * @return
  * @throws Exception
  */
 public static List getLPKInfo(String resName) throws Exception {
   InputStream in = Resources.getResourceAsStream(resName);
   DataInputStream dis = new DataInputStream(in);
   LPKHeader header = readHeader(dis);
   LPKTable[] fileTable = readLPKTable(dis, (int) header.getTables());
   List<Object> result = new ArrayList<Object>();
   result.add(header);
   result.add(fileTable);
   return result;
 }
Example #3
0
 /**
  * 查找指定资源包中的指定资源文件并返回为Byte[]
  *
  * @param fileName
  * @param resName
  * @return
  */
 public static byte[] openResource(String fileName, String resName) {
   InputStream in = null;
   DataInputStream dis = null;
   try {
     in = Resources.getResourceAsStream(fileName);
     dis = new DataInputStream(in);
     LPKHeader header = readHeader(dis);
     LPKTable[] fileTable = readLPKTable(dis, (int) header.getTables());
     boolean find = false;
     int fileIndex = 0;
     String innerName = null;
     for (int i = 0; i < fileTable.length; i++) {
       innerName = new String(fileTable[i].getFileName()).trim();
       if (innerName.equals(resName)) {
         find = true;
         fileIndex = i;
         break;
       }
     }
     if (find == false) {
       throw new RuntimeException("File not found. ( " + fileName + " )");
     } else {
       return readFileFromPak(dis, header, fileTable[fileIndex]);
     }
   } catch (Exception e) {
     throw new RuntimeException("File not found. ( " + fileName + " )");
   } finally {
     if (dis != null) {
       try {
         dis.close();
         dis = null;
       } catch (IOException e) {
       }
     }
   }
 }
Example #4
0
 /**
  * 获得指定头文件的偏移长度
  *
  * @param header
  * @return
  */
 public static long outputOffset(LPKHeader header) {
   return LPKHeader.size() + header.getTables() * LPKTable.size();
 }