示例#1
0
 // Compresses files listed in "files" into a .zip file called "name"
 public void compress(ArrayList<String> files, String zipName) throws Exception {
   byte data[] = new byte[BUFFER];
   // File buffer streams
   BufferedInputStream origin = null;
   String zipDir = zipName;
   FileOutputStream zipDest = new FileOutputStream(zipDir);
   ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(zipDest));
   // Set compression method
   zipOut.setMethod(ZipOutputStream.DEFLATED);
   // Iterate compressing contained files
   for (int i = 0; i < files.size(); i++) {
     String address = files.get(i);
     FileInputStream fj = new FileInputStream(address);
     origin = new BufferedInputStream(fj, BUFFER);
     String[] splits = address.split("\\\\");
     String name = splits[splits.length - 1];
     ZipEntry entry = new ZipEntry(name);
     zipOut.putNextEntry(entry);
     int count;
     while ((count = origin.read(data, 0, BUFFER)) != -1) {
       zipOut.write(data, 0, count);
     }
     origin.close();
   }
   zipOut.close();
 }
示例#2
0
 /** Creates a new JAR file. */
 void create(OutputStream out, Manifest manifest) throws IOException {
   ZipOutputStream zos = new JarOutputStream(out);
   if (flag0) {
     zos.setMethod(ZipOutputStream.STORED);
   }
   if (manifest != null) {
     if (vflag) {
       output(getMsg("out.added.manifest"));
     }
     ZipEntry e = new ZipEntry(MANIFEST_DIR);
     e.setTime(System.currentTimeMillis());
     e.setSize(0);
     e.setCrc(0);
     zos.putNextEntry(e);
     e = new ZipEntry(MANIFEST_NAME);
     e.setTime(System.currentTimeMillis());
     if (flag0) {
       crc32Manifest(e, manifest);
     }
     zos.putNextEntry(e);
     manifest.write(zos);
     zos.closeEntry();
   }
   for (File file : entries) {
     addFile(zos, file);
   }
   zos.close();
 }
  public void installFramework(File frameFile, String tag) throws AndrolibException {
    InputStream in = null;
    ZipOutputStream out = null;
    try {
      ZipFile zip = new ZipFile(frameFile);
      ZipEntry entry = zip.getEntry("resources.arsc");

      if (entry == null) {
        throw new AndrolibException("Can't find resources.arsc file");
      }

      in = zip.getInputStream(entry);
      byte[] data = IOUtils.toByteArray(in);

      ARSCData arsc = ARSCDecoder.decode(new ByteArrayInputStream(data), true, true);
      publicizeResources(data, arsc.getFlagsOffsets());

      File outFile =
          new File(
              getFrameworkDir(),
              String.valueOf(arsc.getOnePackage().getId())
                  + (tag == null ? "" : '-' + tag)
                  + ".apk");

      out = new ZipOutputStream(new FileOutputStream(outFile));
      out.setMethod(ZipOutputStream.STORED);
      CRC32 crc = new CRC32();
      crc.update(data);
      entry = new ZipEntry("resources.arsc");
      entry.setSize(data.length);
      entry.setCrc(crc.getValue());
      out.putNextEntry(entry);
      out.write(data);

      LOGGER.info("Framework installed to: " + outFile);
    } catch (ZipException ex) {
      throw new AndrolibException(ex);
    } catch (IOException ex) {
      throw new AndrolibException(ex);
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException ex) {
        }
      }
      if (out != null) {
        try {
          out.close();
        } catch (IOException ex) {
        }
      }
    }
  }