Package com.subhajit.common.util.CommonUtils

Examples of com.subhajit.common.util.CommonUtils.IRepositoryParser


        public Set<String> call() throws Exception {
            Set<String> ret = new HashSet<String>();
            final URL _url = translateURL();
            if (_url.getProtocol().equals("file")) {
                File file = new File(_url.getFile());
                IRepositoryParser parser = null;
                ZipFile zipFile = null;
                try {
                    if (file.isDirectory()) {
                        int basePackageLength = StrUtils.parse(barePackageName,
                                ".").length;
                        for (int i = 0; i < basePackageLength; i++) {
                            file = file.getParentFile();
                        }
                        parser = new DirectoryParser(file);
                    } else if (file.isFile() && file.getName().endsWith(".jar")) {
                        zipFile = new ZipFile(file);
                        parser = new ZipParser(zipFile);
                    } else {
                        throw new UnsupportedOperationException(
                                "Unsupported file: neither directory nor name-ends-with \".jar\"");
                    }
                    for (Iterator<IResource> it = parser.iterator(); it
                            .hasNext();) {
                        IResource resource = it.next();
                        if (resource.isDirectory()) {
                            continue;
                        }
View Full Code Here


          URL projectJarURL = urls[0];
          progress
              .increment(1, "Scanning " + projectJarURL.getFile());
          final File file = new File(projectJarURL.getFile());
          IRepositoryParser parser = null;
          ZipFile zipFile = null;
          try {
            if (file.isFile() && file.getName().endsWith(".jar")) {
              zipFile = new ZipFile(file);
              parser = new ZipParser(zipFile);
            } else if (file.isDirectory()) {
              parser = new DirectoryParser(file);
            }
            for (Iterator<IResource> it = parser
                .iterator(); it.hasNext();) {
              IResource resource = it.next();
              if (!resource.isDirectory()
                  && resource.getName().endsWith(".class")
                  && resource.getName().indexOf("$") == -1) {
View Full Code Here

        5);
    for (final File file : jarFiles) {
      executor.submit(new Callable<Map<String, byte[]>>() {
        public Map<String, byte[]> call() throws Exception {
          Map<String, byte[]> ret = new HashMap<String, byte[]>();
          IRepositoryParser parser = null;
          try {
            if (file.isFile()) {
              parser = new CommonUtils.ZipParser(
                  new ZipFile(file));
            } else {
              parser = new CommonUtils.DirectoryParser(file);
            }
            Iterator<IResource> it = parser.iterator();
            while (it.hasNext()) {
              IResource resource = it.next();
              if (!resource.isDirectory()) {
                InputStream in = null;
                try {
                  in = resource.getInputStream();
                  ret.put(resource.getName(), StreamUtils
                      .readFully(in));
                } finally {
                  if (in != null) {
                    in.close();
                  }
                }
              }
            }
            return ret;
          } finally {
            if (parser != null) {
              parser.close();
            }
          }
        }
      });
    }
View Full Code Here

    // visit it.
    if (!isValidZipFile(indexFile)) {
      return;
    }

    IRepositoryParser parser = null;
    try {
      parser = new CommonUtils.ZipParser(new ZipFile(indexFile));
      Iterator<IResource> it = parser.iterator();
      while (it.hasNext()) {
        IResource resource = it.next();
        if (!resource.isDirectory()) {
          visitResource(visitor, resource);
        }
      }
    } finally {
      if (parser != null) {
        parser.close();
      }
    }
  }
View Full Code Here

    // visit it.
    if (!isValidZipFile(indexFile)) {
      return;
    }

    IRepositoryParser parser = null;
    try {
      parser = new CommonUtils.ZipParser(new ZipFile(indexFile));
      Iterator<IResource> it = parser.iterator();
      CompletionExecutor<Void> executor = null;
      try {
        executor = new CompletionExecutor<Void>(threads);
        while (it.hasNext()) {
          final IResource resource = it.next();
          if (!resource.isDirectory()) {
            executor.submit(new Callable<Void>() {
              public Void call() throws Exception {
                visitResource(visitor, resource);
                return null;
              }
            });
          }
        }
        while (true) {
          try {
            Map.Entry<Boolean, Void> result = executor
                .getNextCompleted();
            if (!result.getKey()) {
              break;
            }
          } catch (ExecutionException exc) {
            throw new UndeclaredThrowableException(exc.getCause());
          } catch (InterruptedException exc) {
            // The thread running this task was interrupted.
            Thread.currentThread().interrupt();
            return;
          }
        }
      } finally {
        if (executor != null) {
          executor.close();
        }
      }
    } finally {
      if (parser != null) {
        parser.close();
      }
    }
  }
View Full Code Here

   * @throws ExecutionException
   * @throws IOException
   */
  private void createIndex(File file, IProgress... progresses)
      throws InterruptedException, ExecutionException, IOException {
    IRepositoryParser parser = null;
    try {
      if (file.isDirectory()) {
        parser = new CommonUtils.DirectoryParser(file);
      } else {
        parser = new CommonUtils.ZipParser(new ZipFile(file));
      }

      File index = computeIndex(file);
      ZipOutputStream zOut = null;
      try {
        zOut = new ZipOutputStream(new BufferedOutputStream(
            new FileOutputStream(index)));
        ClassInfoUtils.createIndex(parser, zOut, progresses);
        zOut.flush();
      } finally {
        if (zOut != null) {
          try {
            zOut.close();
          } catch (ZipException exc) {
            throw exc;
          }
        }
      }
    } finally {
      if (parser != null) {
        parser.close();
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.subhajit.common.util.CommonUtils.IRepositoryParser

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.