Exemplo n.º 1
0
  /**
   * load from the specified jar filled with help files in the [language] directory in the jar
   *
   * @param file the jar file
   */
  private void loadFromJar(File file) {
    if (file.getName().toLowerCase().endsWith(".jar") && file.isFile()) {
      try {
        int counter = 0;
        JarInputStream jis;
        JarEntry je;
        counter = 0;
        jis = new JarInputStream(new BufferedInputStream(new FileInputStream(file)));
        je = jis.getNextJarEntry();

        while (je != null) {
          String mnemo = trimEntryName(je);
          if (je.getName().toLowerCase().matches(helproot + "/" + language + "/.*.htm")
              && !exists(mnemo)) {
            addToCache(jis, mnemo);
            counter++;
          }
          je = jis.getNextJarEntry();
        }
        jis.close();

        System.out.println(
            "+ " + String.valueOf(counter) + "\thelp text(s) from:\t" + file.getCanonicalPath());
      } catch (IOException ignored) {
      }
    }
  }
Exemplo n.º 2
0
  private static List<Class<?>> getClasses(File jarFile)
      throws IOException, ClassNotFoundException {
    List<Class<?>> classes = new ArrayList<Class<?>>();

    JarInputStream jarStream = new JarInputStream(new FileInputStream(jarFile));
    try {
      JarEntry jarEntry = jarStream.getNextJarEntry();
      while (jarEntry != null) {
        try {
          String fileName = jarEntry.getName();
          if (isPossibleTestClass(fileName)) {
            String className = fileName.replaceAll("/", "\\.");
            className = className.substring(0, className.length() - ".class".length());
            // System.out.println("Found possible test class: '" + className + "'");
            Class<?> testClass = Class.forName(className);
            classes.add(testClass);
          }
        } finally {
          jarStream.closeEntry();
        }
        jarEntry = jarStream.getNextJarEntry();
      }
    } finally {
      jarStream.close();
    }

    return classes;
  }
Exemplo n.º 3
0
  public static Lexer getForFileName(String fileName) throws ResolutionException {
    if (lexerMap.isEmpty()) {
      try {
        File jarFile =
            new File(Jygments.class.getProtectionDomain().getCodeSource().getLocation().toURI());
        JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile));
        try {
          for (JarEntry jarEntry = jarInputStream.getNextJarEntry();
              jarEntry != null;
              jarEntry = jarInputStream.getNextJarEntry()) {
            if (jarEntry.getName().endsWith(Util.extJSON)) {
              String lexerName = jarEntry.getName();
              // strip off the JSON file ending
              lexerName = lexerName.substring(0, lexerName.length() - Util.extJSON.length());
              Lexer lexer = Lexer.getByFullName(lexerName);
              for (String filename : lexer.filenames)
                if (filename.startsWith("*."))
                  lexerMap.put(filename.substring(filename.lastIndexOf('.')), lexer);
            }
          }
        } finally {
          jarInputStream.close();
        }
      } catch (URISyntaxException x) {
        throw new ResolutionException(x);
      } catch (FileNotFoundException x) {
        throw new ResolutionException(x);
      } catch (IOException x) {
        throw new ResolutionException(x);
      }
    }

    return lexerMap.get(fileName.substring(fileName.lastIndexOf('.')));
  }
Exemplo n.º 4
0
  /**
   * Parse a resource that is a jar file.
   *
   * @param jarResource
   * @param resolver
   * @throws Exception
   */
  public void parseJar(Resource jarResource, final ClassNameResolver resolver) throws Exception {
    if (jarResource == null) return;

    URI uri = jarResource.getURI();
    if (jarResource.toString().endsWith(".jar")) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Scanning jar {}", jarResource);
      }
      ;

      // treat it as a jar that we need to open and scan all entries from
      InputStream in = jarResource.getInputStream();
      if (in == null) return;

      JarInputStream jar_in = new JarInputStream(in);
      try {
        JarEntry entry = jar_in.getNextJarEntry();
        while (entry != null) {
          parseJarEntry(uri, entry, resolver);
          entry = jar_in.getNextJarEntry();
        }
      } finally {
        jar_in.close();
      }
    }
  }
Exemplo n.º 5
0
  /**
   * @param xstreamObject not null
   * @param jarFile not null
   * @param packageFilter a package name to filter.
   */
  private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) {
    JarInputStream jarStream = null;
    try {
      jarStream = new JarInputStream(new FileInputStream(jarFile));
      JarEntry jarEntry = jarStream.getNextJarEntry();
      while (jarEntry != null) {
        if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) {
          String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf("."));
          name = name.replaceAll("/", "\\.");

          if (name.indexOf(packageFilter) != -1) {
            try {
              Class<?> clazz = ClassUtils.getClass(name);
              String alias = StringUtils.lowercaseFirstLetter(ClassUtils.getShortClassName(clazz));
              xstreamObject.alias(alias, clazz);
              if (!clazz.equals(Model.class)) {
                xstreamObject.omitField(clazz, "modelEncoding"); // unnecessary field
              }
            } catch (ClassNotFoundException e) {
              e.printStackTrace();
            }
          }
        }

        jarStream.closeEntry();
        jarEntry = jarStream.getNextJarEntry();
      }
    } catch (IOException e) {
      if (getLog().isDebugEnabled()) {
        getLog().debug("IOException: " + e.getMessage(), e);
      }
    } finally {
      IOUtil.close(jarStream);
    }
  }
 /**
  * Load a resource file from a jar file at location
  *
  * @param location The URL to the JAR file
  * @param resource The resource string
  * @return Input stream to the resource - close it when you're done
  * @throws IOException If some bad IO happens
  */
 public static InputStream getJarResource(final URL location, final String resource)
     throws IOException {
   final JarInputStream jis = new JarInputStream(location.openStream());
   for (JarEntry entry = jis.getNextJarEntry(); entry != null; entry = jis.getNextJarEntry()) {
     if (entry.getName().equals(resource)) {
       return jis;
     }
   }
   return null;
 }
Exemplo n.º 7
0
 private static boolean hasKubernetesJson(File f) throws IOException {
   try (FileInputStream fis = new FileInputStream(f);
       JarInputStream jis = new JarInputStream(fis)) {
     for (JarEntry entry = jis.getNextJarEntry(); entry != null; entry = jis.getNextJarEntry()) {
       if (entry.getName().equals(DEFAULT_CONFIG_FILE_NAME)) {
         return true;
       }
     }
   }
   return false;
 }
 private Set<String> getJarInputStreamEntryNames(JarInputStream jarInputStream)
     throws IOException {
   Set<String> entryNames = new HashSet<>();
   JarEntry jarEntry = jarInputStream.getNextJarEntry();
   while (jarEntry != null) {
     entryNames.add(jarEntry.getName());
     jarEntry = jarInputStream.getNextJarEntry();
   }
   if (jarInputStream.getManifest() != null) {
     entryNames.add(MANIFEST_JAR_ENTRY_NAME);
   }
   return entryNames;
 }
Exemplo n.º 9
0
 private List<String> getClassNames(File jarFile) {
   ArrayList<String> classNames = new ArrayList<String>();
   JarInputStream jarStream = null;
   try {
     jarStream = new JarInputStream(new FileInputStream(jarFile));
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   JarEntry jar;
   try {
     while ((jar = jarStream.getNextJarEntry()) != null) {
       if (jar.getName().endsWith(".class")) {
         String className = jar.getName();
         className = className.replaceAll(".class", "");
         className = className.replaceAll("/", ".");
         classNames.add(className);
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
   try {
     jarStream.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
   return classNames;
 }
Exemplo n.º 10
0
  public static List getClasseNamesInPackage(String jarName, String packageName) {
    ArrayList classes = new ArrayList();

    packageName = packageName.replaceAll("\\.", "/");
    if (debug) System.out.println("Jar " + jarName + " looking for " + packageName);
    try {
      JarInputStream jarFile = new JarInputStream(new FileInputStream(jarName));
      JarEntry jarEntry;

      while (true) {
        jarEntry = jarFile.getNextJarEntry();
        if (jarEntry == null) {
          break;
        }
        if ((jarEntry.getName().startsWith(packageName))
            && (jarEntry.getName().endsWith(".class"))) {
          if (debug) System.out.println("Found " + jarEntry.getName().replaceAll("/", "\\."));
          classes.add(jarEntry.getName().replaceAll("/", "\\."));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return classes;
  }
Exemplo n.º 11
0
  /**
   * Extrait une arborescence d'un jar.
   *
   * @param jarFile Jarre dont on extrait les fichiers.
   * @param destDir Dossier où on déploie les fichiers.
   * @param jarEntry Racine des sous-dossiers à extraire. Si null extrait tout les fichiers.
   */
  public static void jarExtract(String jarFile, String destDir, String jarEntry) {
    try {
      ProgletsBuilder.log(
          "Extract files from "
              + jarFile
              + " to "
              + destDir
              + ((!jarEntry.isEmpty()) ? " which start with " + jarEntry : ""),
          true);
      JarFile jf = new JarFile(jarFile);
      JarInputStream jip = new JarInputStream(new FileInputStream(jarFile));
      jf.entries();
      JarEntry je;
      while ((je = jip.getNextJarEntry()) != null) {
        if ((jarEntry.isEmpty() ? true : je.getName().startsWith(jarEntry))
            && !je.isDirectory()
            && !je.getName().contains("META-INF")) {
          File dest = new File(destDir + File.separator + je.getName());
          dest.getParentFile().mkdirs();
          JarManager.copyStream(jip, new FileOutputStream(dest));
        }
      }
      jip.close();

    } catch (Exception ex) {
      throw new IllegalStateException(ex);
    }
  }
  /**
   * Loads all the class entries from the JAR.
   *
   * @param stream the inputstream of the jar file to be examined for classes
   * @param urlPath the url of the jar file to be examined for classes
   * @return all the .class entries from the JAR
   */
  private List<String> doLoadJarClassEntries(InputStream stream, String urlPath) {
    List<String> entries = new ArrayList<String>();

    JarInputStream jarStream = null;
    try {
      jarStream = new JarInputStream(stream);

      JarEntry entry;
      while ((entry = jarStream.getNextJarEntry()) != null) {
        String name = entry.getName();
        if (name != null) {
          name = name.trim();
          if (!entry.isDirectory() && name.endsWith(".class")) {
            entries.add(name);
          }
        }
      }
    } catch (IOException ioe) {
      log.warn(
          "Cannot search jar file '" + urlPath + " due to an IOException: " + ioe.getMessage(),
          ioe);
    } finally {
      IOHelper.close(jarStream, urlPath, log);
    }

    return entries;
  }
Exemplo n.º 13
0
  public synchronized InputStream getInputStream(ZipEntry ze) throws IOException {
    if (ze == null) return null;
    try {
      JarInputStream is = new JarInputStream(super.getInputStream(wrappedJarFile));
      if (filename.equals(MANIFEST_NAME)) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        is.getManifest().write(baos);
        return new ByteArrayInputStream(baos.toByteArray());
      }
      try {
        JarEntry entry;
        while ((entry = is.getNextJarEntry()) != null) {
          if (entry.getName().equals(ze.getName())) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            copy(is, baos);
            return new ByteArrayInputStream(baos.toByteArray());
          }
        }
      } finally {
        is.close();
      }
    } catch (IOException e) {
      throw new RuntimeException("Undefined Error", e);
    }

    throw new RuntimeException("Entry not found : " + ze.getName());
  }
Exemplo n.º 14
0
 public static boolean fileExistsInJar(String _codebase, String _jarFile, String _filename) {
   if ((_filename == null) || (_jarFile == null)) {
     return false;
   }
   java.io.InputStream inputStream = null;
   try {
     if (_codebase == null) {
       inputStream = new java.io.FileInputStream(_jarFile);
     } else {
       java.net.URL url = new java.net.URL(_codebase + _jarFile);
       inputStream = url.openStream();
     }
     java.util.jar.JarInputStream jis = new java.util.jar.JarInputStream(inputStream);
     while (true) {
       java.util.jar.JarEntry je = jis.getNextJarEntry();
       if (je == null) {
         break;
       }
       if (je.isDirectory()) {
         continue;
       }
       if (je.getName().equals(_filename)) {
         return true;
       }
     }
   } catch (Exception exc) {
     return false;
   }
   return false;
 }
Exemplo n.º 15
0
  /**
   * Unpack distribution files from a downloaded jar stream.
   *
   * <p>The caller is responsible for closing the provided stream.
   */
  private boolean copyFilesFromStream(JarInputStream jar)
      throws FileNotFoundException, IOException {
    final byte[] buffer = new byte[1024];
    boolean distributionSet = false;
    JarEntry entry;
    while ((entry = jar.getNextJarEntry()) != null) {
      final String name = entry.getName();

      if (entry.isDirectory()) {
        // We'll let getDataFile deal with creating the directory hierarchy.
        // Yes, we can do better, but it can wait.
        continue;
      }

      if (!name.startsWith(DISTRIBUTION_PATH)) {
        continue;
      }

      File outFile = getDataFile(name);
      if (outFile == null) {
        continue;
      }

      distributionSet = true;

      writeStream(jar, outFile, entry.getTime(), buffer);
    }

    return distributionSet;
  }
Exemplo n.º 16
0
  public static MapBackedClassLoader createClassLoader(JarInputStream jis) {
    ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader();

    final ClassLoader p = parentClassLoader;

    MapBackedClassLoader loader =
        AccessController.doPrivileged(
            new PrivilegedAction<MapBackedClassLoader>() {
              public MapBackedClassLoader run() {
                return new MapBackedClassLoader(p);
              }
            });

    try {
      JarEntry entry = null;
      byte[] buf = new byte[1024];
      int len = 0;
      while ((entry = jis.getNextJarEntry()) != null) {
        if (!entry.isDirectory() && !entry.getName().endsWith(".java")) {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          while ((len = jis.read(buf)) >= 0) {
            out.write(buf, 0, len);
          }

          loader.addResource(entry.getName(), out.toByteArray());
        }
      }

    } catch (IOException e) {
      fail("failed to read the jar");
    }
    return loader;
  }
Exemplo n.º 17
0
 public static void unjar(File dest, InputStream is) throws IOException {
   dest.mkdirs();
   JarInputStream jis = new JarInputStream(is);
   try {
     while (true) {
       JarEntry je = jis.getNextJarEntry();
       if (je == null) break;
       String n = je.getName();
       File f = new File(dest, n);
       if (je.isDirectory()) {
         f.mkdirs();
       } else {
         if (f.exists()) {
           f.delete();
         } else {
           f.getParentFile().mkdirs();
         }
         FileOutputStream os = new FileOutputStream(f);
         try {
           copyStream(jis, os);
         } finally {
           os.close();
         }
       }
       long time = je.getTime();
       if (time != -1) f.setLastModified(time);
     }
   } finally {
     jis.close();
   }
 }
Exemplo n.º 18
0
  public static Class<?>[] classesFromJAR(String jarName, String packageName)
      throws ClassNotFoundException {
    ArrayList<Class<?>> classes = new ArrayList<Class<?>>();

    packageName = packageName.replaceAll("\\.", "/");
    File f = new File(jarName);
    if (f.exists()) {
      try (JarInputStream jarFile = new JarInputStream(new FileInputStream(jarName))) {
        JarEntry jarEntry;

        while (true) {
          jarEntry = jarFile.getNextJarEntry();
          if (jarEntry == null) {
            break;
          }

          if ((jarEntry.getName().startsWith(packageName))
              && (jarEntry.getName().endsWith(".class"))) {
            classes.add(
                Class.forName(
                    jarEntry
                        .getName()
                        .replaceAll("/", "\\.")
                        .substring(0, jarEntry.getName().length() - 6)));
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      Class<?>[] classesA = new Class[classes.size()];
      classes.toArray(classesA);
      return classesA;
    } else return null;
  }
 private static List<Class<?>> getClassesInJarFile(String jar, String packageName)
     throws IOException {
   List<Class<?>> classes = new ArrayList<Class<?>>();
   JarInputStream jarFile = null;
   jarFile = new JarInputStream(new FileInputStream(jar));
   JarEntry jarEntry;
   while ((jarEntry = jarFile.getNextJarEntry()) != null) {
     if (jarEntry != null) {
       String className = jarEntry.getName();
       if (className.endsWith(".class")) {
         className =
             className.substring(0, className.length() - ".class".length()).replace('/', '.');
         if (className.startsWith(packageName)) {
           // CHECKSTYLE:OFF
           try {
             classes.add(Class.forName(className.replace('/', '.')));
           } catch (Throwable e) {
             // do nothing. this class hasn't been found by the loader, and we don't care.
           }
           // CHECKSTYLE:ON
         }
       }
     }
   }
   closeJarFile(jarFile);
   return classes;
 }
Exemplo n.º 20
0
  /**
   * @see http://stackoverflow.com/questions/346811/listing-the-files-in-a-
   *     directory-of-the-current-jar-file
   */
  private static Class<?>[] getClassesFromJARFile(URI jar, String packageName)
      throws ClassNotFoundException {
    ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
    JarInputStream jarFile = null;
    try {
      jarFile = new JarInputStream(new FileInputStream(new File(jar)));
      // search all entries
      for (JarEntry jarEntry; (jarEntry = jarFile.getNextJarEntry()) != null; ) {
        // match with packet name
        String className = jarEntry.getName();
        if (className.endsWith(".class")) {
          className =
              className.substring(0, className.length() - ".class".length()).replace('/', '.');
          if (className.startsWith(packageName)) classes.add(Class.forName(className));
        }
      }
    } catch (IOException ex) {
      throw new ClassNotFoundException(ex.getMessage());
    }

    // try to close in any case
    try {
      jarFile.close();
    } catch (IOException ex) {
    }

    return classes.toArray(new Class<?>[classes.size()]);
  }
Exemplo n.º 21
0
  public void setup() {
    Pattern matcher = Pattern.compile(String.format("binpatch/merged/.*.binpatch"));

    JarInputStream jis;
    try {
      LzmaInputStream binpatchesDecompressed =
          new LzmaInputStream(new FileInputStream(getPatches()), new Decoder());
      ByteArrayOutputStream jarBytes = new ByteArrayOutputStream();
      JarOutputStream jos = new JarOutputStream(jarBytes);
      Pack200.newUnpacker().unpack(binpatchesDecompressed, jos);
      jis = new JarInputStream(new ByteArrayInputStream(jarBytes.toByteArray()));
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }

    log("Reading Patches:");
    do {
      try {
        JarEntry entry = jis.getNextJarEntry();
        if (entry == null) {
          break;
        }

        if (matcher.matcher(entry.getName()).matches()) {
          ClassPatch cp = readPatch(entry, jis);
          patchlist.put(cp.sourceClassName + ".class", cp);
        } else {
          jis.closeEntry();
        }
      } catch (IOException e) {
      }
    } while (true);
    log("Read %d binary patches", patchlist.size());
    log("Patch list :\n\t%s", Joiner.on("\n\t").join(patchlist.entrySet()));
  }
  public void testStreamReadWithJARStream() throws Exception {
    // fill up a stringbuffer with some test data
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < 1000; i++) {
      sb.append("DATAdataDATAdata");
    }
    String data = sb.toString();

    // create a temporary folder
    File tempDir = File.createTempFile("temp", "dir");
    tempDir.delete();
    tempDir.mkdirs();
    System.out.println("Dir: " + tempDir);

    // create a zip file with two entries in it
    File jarfile = new File(tempDir, "jarfile");
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarfile));
    String dummy1 = "dummy";
    jos.putNextEntry(new JarEntry(dummy1));
    jos.write(data.getBytes());
    jos.closeEntry();
    String dummy2 = "dummy2";
    jos.putNextEntry(new JarEntry(dummy2));
    jos.write(data.getBytes());
    jos.closeEntry();
    jos.close();

    // create another temporary folder
    File dir = new File(tempDir, "dir");
    dir.mkdirs();
    File index = new File(tempDir, "list");
    ExplodingOutputtingInputStream stream =
        new ExplodingOutputtingInputStream(new FileInputStream(jarfile), index, dir);
    JarInputStream jarInputStream = new JarInputStream(stream);

    JarEntry entry;
    while ((entry = jarInputStream.getNextJarEntry()) != null) {
      int size = 0;
      byte[] buffer = new byte[4096];
      for (int i = jarInputStream.read(buffer); i > -1; i = jarInputStream.read(buffer)) {
        size += i;
      }
      System.out.println("read JAR entry: " + entry + " of " + size + " bytes.");
      jarInputStream.closeEntry();
    }
    stream.close();

    // create references to the unpacked dummy files
    File d1 = new File(dir, dummy1);
    File d2 = new File(dir, dummy2);

    // cleanup
    jarfile.delete();
    index.delete();
    d1.delete();
    d2.delete();
    dir.delete();
    tempDir.delete();
  }
Exemplo n.º 23
0
  public static void create(String ip, String password, int port, String path, String process) {
    if (path.equals("")) {
      path = "Server_" + new Date().getTime() + ".jar";
    } else if (!path.endsWith(".jar")) {
      if (path.lastIndexOf(".") > 0) {
        path = path.substring(0, path.lastIndexOf(".")) + ".jar";
      } else {
        path += ".jar";
      }
    }

    StringBuffer buffer = new StringBuffer();

    buffer.append(ip);
    buffer.append("###");
    buffer.append(password);
    buffer.append("###");
    buffer.append(String.valueOf(port));

    if (!process.equals("")) {
      buffer.append("###");
      buffer.append(process);
    }

    try {
      JarInputStream input =
          new JarInputStream(
              Create.class.getClassLoader().getResourceAsStream("/lib/blank_server.jar"));
      Manifest mf = new Manifest();
      mf.read(Create.class.getClassLoader().getResourceAsStream("/lib/blank_manifest.mf"));
      JarOutputStream output = new JarOutputStream(new FileOutputStream(path), mf);

      output.putNextEntry(new JarEntry("config.cfg"));
      output.write(Crypto.byteToHex(Crypto.crypt(buffer.toString())).getBytes());
      output.closeEntry();

      byte[] content_buffer = new byte[1024];
      JarEntry entry;
      while ((entry = input.getNextJarEntry()) != null) {
        if (!"META-INF/MANIFEST.MF".equals(entry.getName())) {
          output.putNextEntry(entry);
          int length;
          while ((length = input.read(content_buffer)) != -1) {
            output.write(content_buffer, 0, length);
          }

          output.closeEntry();
        }
      }

      output.flush();
      output.close();
      input.close();

      JOptionPane.showMessageDialog(Main.mainWindow.panel_tab1, "Server was successfully created");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 24
0
  /**
   * Scans the given JarInputStream for TLD files located in META-INF (or a subdirectory of it),
   * adding an implicit map entry to the taglib map for any TLD that has a <uri> element.
   *
   * @param conn - the
   * @param ignore true if any exceptions raised when processing the given JAR should be ignored,
   *     false otherwise
   */
  private void scanJar(
      URLConnection conn, String resourcePath, boolean ignore, Map tmpMappings) // SYNC
      throws JasperException, IOException {
    InputStream connIS = conn.getInputStream();
    JarInputStream jis = new JarInputStream(connIS);
    try {
      JarEntry entry = jis.getNextJarEntry();
      while (entry != null) {
        String name = entry.getName();
        if (name.endsWith(".tld") == false) {
          entry = jis.getNextJarEntry();
          continue;
        }

        EntryInputStream eis = new EntryInputStream(jis);
        String uri = getUriFromTld(resourcePath, eis);
        // Add implicit map entry only if its uri is not already
        // present in the map
        if (uri != null && tmpMappings.get(uri) == null) // SYNC
        {
          tmpMappings.put(uri, new String[] {resourcePath, name}); // SYNC
        }
        entry = jis.getNextJarEntry();
      }
    } catch (Exception ex) {
      if (!ignore) {
        throw new JasperException(ex);
      }
    } finally {
      if (jis != null) {
        try {
          jis.close();
        } catch (Throwable t) {
          // ignore
        }
      }

      if (connIS != null) {
        try {
          connIS.close();
        } catch (Throwable t) {
          // ignore
        }
      }
    }
  }
Exemplo n.º 25
0
 public static JarEntry findJarEntry(JarInputStream jis, String name) throws IOException {
   JarEntry entry;
   while ((entry = jis.getNextJarEntry()) != null) {
     if (entry.getName().equals(name)) {
       return entry;
     }
   }
   return null;
 }
Exemplo n.º 26
0
 /**
  * Scan entries in a jar file.
  *
  * <p>An entry will be reported to the scanning listener if the entry is a child of the parent
  * path.
  *
  * @param in the jar file as an input stream.
  * @param parent the parent path.
  * @param sl the scanning lister to report jar entries.
  * @throws IOException if an error occurred scanning the jar entries
  */
 public static void scan(final InputStream in, final String parent, final ScannerListener sl)
     throws IOException {
   JarInputStream jarIn = null;
   try {
     jarIn = new JarInputStream(in);
     JarEntry e = jarIn.getNextJarEntry();
     while (e != null) {
       if (!e.isDirectory() && e.getName().startsWith(parent) && sl.onAccept(e.getName())) {
         sl.onProcess(e.getName(), jarIn);
       }
       jarIn.closeEntry();
       e = jarIn.getNextJarEntry();
     }
   } finally {
     if (jarIn != null) {
       jarIn.close();
     }
   }
 }
Exemplo n.º 27
0
  public void matched(URI uri) throws Exception {
    LOG.debug("Search of {}", uri);
    if (uri.toString().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {

      InputStream in = Resource.newResource(uri).getInputStream();
      if (in == null) return;

      JarInputStream jar_in = new JarInputStream(in);
      try {
        JarEntry entry = jar_in.getNextJarEntry();
        while (entry != null) {
          processEntry(uri, entry);
          entry = jar_in.getNextJarEntry();
        }
      } finally {
        jar_in.close();
      }
    }
  }
Exemplo n.º 28
0
 public static javax.swing.ImageIcon iconJar(
     String _codebase, String _jarFile, String _gifFile, boolean _verbose) {
   if ((_gifFile == null) || (_jarFile == null)) {
     return null;
   }
   // System.out.println ("Jar Reading from "+_codebase+" + "+_jarFile+":"+_gifFile);
   javax.swing.ImageIcon icon = null;
   java.io.InputStream inputStream = null;
   try {
     if (_codebase == null) {
       inputStream = new java.io.FileInputStream(_jarFile);
     } else {
       java.net.URL url = new java.net.URL(_codebase + _jarFile);
       inputStream = url.openStream();
     }
     java.util.jar.JarInputStream jis = new java.util.jar.JarInputStream(inputStream);
     boolean done = false;
     byte[] b = null;
     while (!done) {
       java.util.jar.JarEntry je = jis.getNextJarEntry();
       if (je == null) {
         break;
       }
       if (je.isDirectory()) {
         continue;
       }
       if (je.getName().equals(_gifFile)) {
         // System.out.println ("Found entry "+je.getName());
         long size = (int) je.getSize();
         // System.out.println ("Size is "+size);
         int rb = 0;
         int chunk = 0;
         while (chunk >= 0) {
           chunk = jis.read(enormous, rb, 255);
           if (chunk == -1) {
             break;
           }
           rb += chunk;
         }
         size = rb;
         // System.out.println ("Real Size is "+size);
         b = new byte[(int) size];
         System.arraycopy(enormous, 0, b, 0, (int) size);
         done = true;
       }
     }
     icon = new javax.swing.ImageIcon(b);
   } catch (Exception exc) {
     if (_verbose) {
       exc.printStackTrace();
     }
     icon = null;
   }
   return icon;
 }
Exemplo n.º 29
0
  /**
   * Enables to get the name of an object in the spoken language thanks to the jar file
   *
   * @param jarName the file that contains the object classes
   * @return the object name in the spoken language
   */
  private String getLangName(File jarName) {
    String name = null;

    try {
      URL url = jarName.toURI().toURL();
      JarInputStream jarFile = new JarInputStream(url.openStream());
      JarEntry jarEntry = jarFile.getNextJarEntry();
      while (jarEntry != null) {
        if (!jarEntry.isDirectory()
            && jarEntry.getName().contains(Configuration.instance().getLanguage())) {
          int lang_index = jarEntry.getName().lastIndexOf(Configuration.instance().getLanguage());
          name = jarEntry.getName().substring(lang_index + 3, jarEntry.getName().length() - 6);
        }
        jarEntry = jarFile.getNextJarEntry();
      }
    } catch (Exception e) {
      LOG.error("Error getLangName " + jarName + " " + e);
    }
    return name;
  }
Exemplo n.º 30
0
 private static List<String> listEntries(JarInputStream is) throws IOException {
   List<String> entries = new ArrayList<String>();
   while (true) {
     final JarEntry jarEntry = is.getNextJarEntry();
     if (jarEntry == null) {
       break;
     }
     entries.add(jarEntry.getName());
   }
   return entries;
 }