Package java.util.zip

Examples of java.util.zip.ZipInputStream


    private boolean recurse;

    public Iter(File file) {
      this.parent = null;
      try {
        this.zip = new ZipInputStream(new FileInputStream(file));
      } catch (FileNotFoundException ex) {
        throw new RuntimeException(ex);
      }
    }
View Full Code Here


      return this;
    }

    public Iter(Entry parent, InputStream in) {
      this.parent = parent;
      this.zip = new ZipInputStream(in);
    }
View Full Code Here

    protected Map<String, MojoAnnotatedClass> scanArchive( File archiveFile, Artifact artifact, boolean excludeMojo )
        throws IOException, ExtractionException
    {
        Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = new HashMap<String, MojoAnnotatedClass>();

        ZipInputStream archiveStream = new ZipInputStream( new FileInputStream( archiveFile ) );

        try
        {
            for ( ZipEntry zipEntry = archiveStream.getNextEntry(); zipEntry != null;
                  zipEntry = archiveStream.getNextEntry() )
            {
                if ( !zipEntry.getName().endsWith( ".class" ) )
                {
                    continue;
                }
View Full Code Here

     */
    protected void addArchiveContent(File baseDir, File archive, String targetdir, List<OsConstraint> osList, int override, PackInfo pack, Map additionals, String condition) throws IOException
    {

        FileInputStream fin = new FileInputStream(archive);
        ZipInputStream zin = new ZipInputStream(fin);
        while (true)
        {
            ZipEntry zentry = zin.getNextEntry();
            if (zentry == null)
            {
                break;
            }
            if (zentry.isDirectory())
View Full Code Here

  private static TreeSet<String> findClasses(String path, String packageName) throws MalformedURLException, IOException {
    TreeSet<String> classes = new TreeSet<String>();
    if (path.startsWith("file:") && path.contains("!")) {
      String[] split = path.split("!");
      URL jar = new URL(split[0]);
      ZipInputStream zip = new ZipInputStream(jar.openStream());
      ZipEntry entry;
      while ((entry = zip.getNextEntry()) != null) {
        if (entry.getName().endsWith(".class")) {
          String className = entry.getName().replaceAll("[$].*", "").replaceAll("[.]class", "").replace('/', '.');
          if (className.startsWith(packageName)) {
            classes.add(className);
          }
View Full Code Here

    }

    private static InputStream entryInJar(InputStream jar, String entry) throws IOException {
        entry = trimTrailingSlashes(entry);

        ZipInputStream jstream = new ZipInputStream(jar);
        ZipEntry zentry = null;
        while ((zentry = jstream.getNextEntry()) != null) {
            if (trimTrailingSlashes(zentry.getName()).equals(entry)) {
                return jstream;
            }
            jstream.closeEntry();
        }
        throw new FileNotFoundException("entry '" + entry + "' not found in " + jar);
    }
View Full Code Here

    public void testGetInputStream() throws IOException {
        byte[] sample = "Hello World lllllllllllots of repeated charactersssssssssssss Hello World again".getBytes();
        ZipDataSource dataSource = new ZipDataSource("name", new ByteArrayInputStream(sample));
        InputStream in = dataSource.getInputStream();

        ZipInputStream zin = new ZipInputStream(in);
        // Need this to move the ZipInputStream to the start of the "file"
        zin.getNextEntry();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int size;
        byte[] buffer = new byte[BUFFER_SIZE];
        while ((size = zin.read(buffer, 0, buffer.length)) > 0) {
            baos.write(buffer, 0, size);
        }
        assertArrayEquals(sample, baos.toByteArray());
    }
View Full Code Here

  protected void parseManifest(FetchResult result) {
    InputStream is = null;
    try {
      is = result.asBucket().getInputStream();
      ZipInputStream zis = new ZipInputStream(is);
      try {
        ZipEntry ze;
        while(true) {
          ze = zis.getNextEntry();
          if(ze == null) break;
          if(ze.isDirectory()) continue;
          String name = ze.getName();
         
          if(name.equals("META-INF/MANIFEST.MF")) {
            if(logMINOR) Logger.minor(this, "Found manifest");
            long size = ze.getSize();
            if(logMINOR) Logger.minor(this, "Manifest size: "+size);
            if(size > MAX_MANIFEST_SIZE) {
              Logger.error(this, "Manifest is too big: "+size+" bytes, limit is "+MAX_MANIFEST_SIZE);
              break;
            }
            byte[] buf = new byte[(int) size];
            DataInputStream dis = new DataInputStream(zis);
            dis.readFully(buf);
            ByteArrayInputStream bais = new ByteArrayInputStream(buf);
            InputStreamReader isr = new InputStreamReader(bais, "UTF-8");
            BufferedReader br = new BufferedReader(isr);
            String line;
            while((line = br.readLine()) != null) {
              parseManifestLine(line);
            }
          } else {
            zis.closeEntry();
          }
        }
      } finally {
        Closer.close(zis);
      }
View Full Code Here

   * @param filename The filename of the manifest file containing the properties (normally
   * META-INF/MANIFEST.MF).
   * @throws IOException If there is a temporary files error or the jar is corrupted. */
  static Properties parseProperties(InputStream is, String filename) throws IOException {
    Properties props = new Properties();
    ZipInputStream zis = new ZipInputStream(is);
    try {
      ZipEntry ze;
      while(true) {
        ze = zis.getNextEntry();
        if(ze == null) break;
        if(ze.isDirectory()) continue;
        String name = ze.getName();
       
        if(name.equals(filename)) {
          if(logMINOR) Logger.minor(NodeUpdater.class, "Found manifest");
          long size = ze.getSize();
          if(logMINOR) Logger.minor(NodeUpdater.class, "Manifest size: "+size);
          if(size > MAX_MANIFEST_SIZE) {
            Logger.error(NodeUpdater.class, "Manifest is too big: "+size+" bytes, limit is "+MAX_MANIFEST_SIZE);
            break;
          }
          byte[] buf = new byte[(int) size];
          DataInputStream dis = new DataInputStream(zis);
          dis.readFully(buf);
          ByteArrayInputStream bais = new ByteArrayInputStream(buf);
          props.load(bais);
        } else {
            // Read the file. Throw if there is a CRC error.
            // Note that java.util.zip.ZipInputStream only checks the CRC for compressed
            // files, so this is not entirely foolproof.
            long size = ze.getSize();
            FileUtil.copy(zis, new NullOutputStream(), size);
          zis.closeEntry();
        }
      }
    } finally {
      Closer.close(zis);
    }
View Full Code Here

  }
 
  public static void editLauncher() {
    try {
      System.out.println(hackedFile.toString());
      ZipInputStream in = new ZipInputStream(new FileInputStream(normalLauncherFilename));
      ZipOutputStream out = new ZipOutputStream(new FileOutputStream(hackedFile));
      ZipEntry entry;
      String n;
      InputStream dataSource;
      while((entry = in.getNextEntry()) != null) {
        n = entry.getName();
        if(n.contains(".svn")
            || n.equals("META-INF/MOJANG_C.SF")
            || n.equals("META-INF/MOJANG_C.DSA")
            || n.equals("net/minecraft/minecraft.key")
            || n.equals("net/minecraft/Util$OS.class")) continue;
       
        out.putNextEntry(entry);
        if(n.equals("META-INF/MANIFEST.MF")) dataSource = new ByteArrayInputStream(MANIFEST_TEXT.getBytes());
        else if(n.equals("net/minecraft/Util.class")) dataSource = Resources.load("net/minecraft/Util.class");
        else dataSource = in;
        Streams.pipeStreams(dataSource, out);
        out.flush();
      }
      in.close();
      out.close();
    } catch(Exception e) {
      System.out.println("Editing launcher failed:");
      e.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of java.util.zip.ZipInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.