Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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) {
       }
     }
   }
 }