Пример #1
0
 private long getLastModified(String scriptName) throws ResourceException {
   URLConnection conn = rc.getResourceConnection(scriptName);
   long lastMod = 0;
   try {
     // getLastModified() truncates up to 999 ms from the true modification time, let's fix that
     lastMod = ((conn.getLastModified() / 1000) + 1) * 1000 - 1;
   } finally {
     // getResourceConnection() opening the inputstream, let's ensure all streams are closed
     forceClose(conn);
   }
   return lastMod;
 }
Пример #2
0
 /**
  * Get the class of the scriptName in question, so that you can instantiate Groovy objects with
  * caching and reloading.
  *
  * @param scriptName resource name pointing to the script
  * @return the loaded scriptName as a compiled class
  * @throws ResourceException if there is a problem accessing the script
  * @throws ScriptException if there is a problem parsing the script
  */
 public Class loadScriptByName(String scriptName) throws ResourceException, ScriptException {
   URLConnection conn = rc.getResourceConnection(scriptName);
   String path = conn.getURL().toExternalForm();
   ScriptCacheEntry entry = scriptCache.get(path);
   Class clazz = null;
   if (entry != null) clazz = entry.scriptClass;
   try {
     if (isSourceNewer(entry)) {
       try {
         String encoding = conn.getContentEncoding() != null ? conn.getContentEncoding() : "UTF-8";
         clazz =
             groovyLoader.parseClass(
                 IOGroovyMethods.getText(conn.getInputStream(), encoding), path);
       } catch (IOException e) {
         throw new ResourceException(e);
       }
     }
   } finally {
     forceClose(conn);
   }
   return clazz;
 }