diff --git a/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazStore.java b/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazStore.java index 7496312..96519fe 100644 --- a/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazStore.java +++ b/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazStore.java @@ -28,10 +28,8 @@ import java.io.Serializable; -import com.jpetrak.gate.stringannotation.extendedgazetteer.State; - - import gate.FeatureMap; +import java.net.URL; /** * A GazStore represents a loaded gazetteer plus all the methods for loading, caching, @@ -101,7 +99,7 @@ public Iterator match(String toMatch) { public abstract void save(File whereTo) throws FileNotFoundException, IOException; - public abstract GazStore load(File whereFrom) throws IOException; + public abstract GazStore load(URL whereFrom) throws IOException; public int refcount = 0; diff --git a/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazetteerBase.java b/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazetteerBase.java index 5edeb4a..188136e 100644 --- a/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazetteerBase.java +++ b/src/com/jpetrak/gate/stringannotation/extendedgazetteer/GazetteerBase.java @@ -49,9 +49,11 @@ import org.apache.log4j.Logger; import com.jpetrak.gate.stringannotation.extendedgazetteer.trie.GazStoreTrie3; +import com.jpetrak.gate.stringannotation.utils.UrlUtils; import gate.GateConstants; import gate.creole.metadata.Optional; import gate.gui.ActionsPublisher; +import gate.util.Files; import java.awt.event.ActionEvent; import java.io.InputStreamReader; import java.util.zip.GZIPInputStream; @@ -75,6 +77,7 @@ public abstract class GazetteerBase extends AbstractLanguageAnalyser implements */ @CreoleParameter(comment = "The URL to the gazetteer configuration file", suffixes = "def;defyaml", defaultValue = "") public void setConfigFileURL(java.net.URL theURL) { + System.err.println("DEBUG: setting config file to "+theURL); configFileURL = theURL; } @@ -86,6 +89,7 @@ public java.net.URL getConfigFileURL() { @CreoleParameter(comment = "Should this gazetteer differentiate on case", defaultValue = "true") public void setCaseSensitive(Boolean yesno) { + System.err.println("DEBUG: setting case sensitive to "+yesno); caseSensitive = yesno; } @@ -97,6 +101,7 @@ public Boolean getCaseSensitive() { @CreoleParameter(comment = "For case insensitive matches, the locale to use for normalizing case", defaultValue = "en") public void setCaseConversionLanguage(String val) { + System.err.println("DEBUG: case conversion language set to "+val); caseConversionLanguage = val; caseConversionLocale = new Locale(val); } @@ -162,7 +167,7 @@ public String getGazetteerFeatureSeparator() { ; private static final String ws_class = "[" + ws_chars + "]"; private static final String ws_patternstring = ws_class + "+"; - private static final String encoding = "UTF-8"; + private static final String UTF8 = "UTF-8"; public GazetteerBase() { logger = Logger.getLogger(this.getClass().getName()); @@ -173,12 +178,14 @@ public Resource init() throws ResourceInstantiationException { // precompile the pattern used to replace all unicode whitespace in gazetteer // entries with a single space. ws_pattern = Pattern.compile(ws_patternstring); + System.err.println("DEBUG: running init(), caseConversionLanguage is "+caseConversionLanguage); incrementGazStore(); return this; } protected static Map loadedGazStores = new HashMap(); private synchronized void incrementGazStore() throws ResourceInstantiationException { + System.err.println("DEBUG running incrementGazStore"); String uniqueGazStoreKey = genUniqueGazStoreKey(); logger.info("Creating gazetteer for " + getConfigFileURL()); System.gc(); @@ -191,6 +198,7 @@ private synchronized void incrementGazStore() throws ResourceInstantiationExcept gazStore = gs; gazStore.refcount++; logger.info("Reusing already generated GazStore for " + uniqueGazStoreKey); + System.err.println("Reusing already generated gaz store for "+uniqueGazStoreKey); } else { try { loadData(); @@ -198,8 +206,10 @@ private synchronized void incrementGazStore() throws ResourceInstantiationExcept } catch (Exception ex) { throw new ResourceInstantiationException("Could not load gazetteer", ex); } + gazStore.refcount++; loadedGazStores.put(uniqueGazStoreKey, gazStore); + System.err.println("DEBUG addeed new gaz store with key "+uniqueGazStoreKey); logger.info("New GazStore loaded for " + uniqueGazStoreKey); } long endTime = System.currentTimeMillis(); @@ -238,27 +248,36 @@ private synchronized void replaceGazStore() throws ResourceInstantiationExceptio private synchronized void decrementGazStore() { + System.err.println("DEBUG: running decrementGazStore, map contains: "+loadedGazStores.keySet()); String key = genUniqueGazStoreKey(); + System.err.println("DEBUG: key for finding the gaz store: "+key); GazStore gs = loadedGazStores.get(key); + System.err.println("DEBUG got a gaz store: "+gs); gs.refcount--; if (gs.refcount == 0) { + System.err.println("DEBUG: removing gaz store key"); loadedGazStores.remove(key); logger.info("Removing GazStore for " + key); } } private synchronized void removeGazStore() { + System.err.println("DEBUG: running removeGazStore()"); String key = genUniqueGazStoreKey(); + System.err.println("DEBUG: removing gazstore key: "+key); loadedGazStores.remove(key); logger.info("reInit(): force-removing GazStore for " + key); } protected String genUniqueGazStoreKey() { - return " cs=" + caseSensitive + " url=" + configFileURL + " lang=" + caseConversionLanguage; + String key = " cs=" + caseSensitive + " url=" + configFileURL + " lang=" + caseConversionLanguage; + System.err.println("DEBUG: generating the gaz store key: "+key); + return key; } @Override public void cleanup() { + System.err.println("DEBUG: running cleanup()"); decrementGazStore(); } @@ -272,17 +291,18 @@ public void save(File whereTo) throws IOException { public void reInit() throws ResourceInstantiationException { //removeGazStore(); //init(); + System.err.println("DEBUG: running reInit()"); replaceGazStore(); } protected void loadData() throws UnsupportedEncodingException, IOException, ResourceInstantiationException { // if we find the cache file, load it, else load the original files and create the cache file - File configFile = gate.util.Files.fileFromURL(configFileURL); + //!File configFile = gate.util.Files.fileFromURL(configFileURL); // check the extension and determine if we have an old format .def file or // a new format .defyaml file - String name = configFile.getName(); + String name = UrlUtils.getName(configFileURL); int i = name.lastIndexOf('.') + 1; if (i < 0) { throw new GateRuntimeException("Config file must have a .def or .defyaml extension"); @@ -292,86 +312,90 @@ protected void loadData() throws UnsupportedEncodingException, IOException, Reso throw new GateRuntimeException("Config file must have a .def or .defyaml extension"); } if (ext.equals("def")) { - loadDataFromDef(configFile); + loadDataFromDef(configFileURL); } else { - loadDataFromYaml(configFile); + loadDataFromYaml(configFileURL); } } - protected void loadDataFromDef(File configFile) throws IOException { - String configFileName = configFile.getAbsolutePath(); + protected void loadDataFromDef(URL configFileURL) throws IOException { + String configFileName = configFileURL.toExternalForm(); String gazbinFileName = configFileName.replaceAll("\\.def$", ".gazbin"); if (configFileName.equals(gazbinFileName)) { - throw new GateRuntimeException("Config file must have def or defyaml extension"); + throw new GateRuntimeException("Config file must have def or defyaml extension, not "+configFileURL); } - File gazbinFile = new File(gazbinFileName); + URL gazbinURL = new URL(gazbinFileName); - if (gazbinFile.exists()) { + if (UrlUtils.exists(gazbinURL)) { gazStore = new GazStoreTrie3(); - gazStore = gazStore.load(gazbinFile); + gazStore = gazStore.load(gazbinURL); } else { gazStore = new GazStoreTrie3(); - BufferedReader defReader = - new BomStrippingInputStreamReader((configFileURL).openStream(), encoding); - String line; - //logger.info("Loading data"); - while (null != (line = defReader.readLine())) { - String[] fields = line.split(":"); - if (fields.length == 0) { - System.err.println("Empty line in file " + configFileURL); - } else { - String listFileName = ""; - String majorType = ""; - String minorType = ""; - String languages = ""; - String annotationType = ANNIEConstants.LOOKUP_ANNOTATION_TYPE; - listFileName = fields[0]; - if (fields.length > 1) { - majorType = fields[1]; - } - if (fields.length > 2) { - minorType = fields[2]; - } - if (fields.length > 3) { - languages = fields[3]; - } - if (fields.length > 4) { - annotationType = fields[4]; - } - if (fields.length > 5) { - defReader.close(); - throw new GateRuntimeException("Line has more that 5 fields in def file " + configFileURL); + try (BufferedReader defReader = new BomStrippingInputStreamReader((configFileURL).openStream(), UTF8)) { + String line; + //logger.info("Loading data"); + while (null != (line = defReader.readLine())) { + String[] fields = line.split(":"); + if (fields.length == 0) { + System.err.println("Empty line in file " + configFileURL); + } else { + String listFileName = ""; + String majorType = ""; + String minorType = ""; + String languages = ""; + String annotationType = ANNIEConstants.LOOKUP_ANNOTATION_TYPE; + listFileName = fields[0]; + if (fields.length > 1) { + majorType = fields[1]; + } + if (fields.length > 2) { + minorType = fields[2]; + } + if (fields.length > 3) { + languages = fields[3]; + } + if (fields.length > 4) { + annotationType = fields[4]; + } + if (fields.length > 5) { + defReader.close(); + throw new GateRuntimeException("Line has more that 5 fields in def file " + configFileURL); + } + logger.debug("Reading from " + listFileName + ", " + majorType + "/" + minorType + "/" + languages + "/" + annotationType); + //logger.info("DEBUG: loading data from "+listFileName); + loadListFile(listFileName, majorType, minorType, languages, annotationType); } - logger.debug("Reading from " + listFileName + ", " + majorType + "/" + minorType + "/" + languages + "/" + annotationType); - //logger.info("DEBUG: loading data from "+listFileName); - loadListFile(listFileName, majorType, minorType, languages, annotationType); - } - } //while - defReader.close(); + } //while + } // try gazStore.compact(); logger.info("Gazetteer loaded from list files"); - gazStore.save(gazbinFile); + // only write the cache if we loaded the def file from an actual file, not + // some other URL + if(UrlUtils.isFile(gazbinURL)) { + File gazbinFile = Files.fileFromURL(gazbinURL); + gazStore.save(gazbinFile); + } } // gazbinFile exists ... else } - protected void loadDataFromYaml(File configFile) throws IOException { - String configFileName = configFile.getAbsolutePath(); + protected void loadDataFromYaml(URL configFileURL) throws IOException { + String configFileName = configFileURL.toExternalForm(); String gazbinFileName = configFileName.replaceAll("\\.defyaml$", ".gazbin"); if (configFileName.equals(gazbinFileName)) { throw new GateRuntimeException("Config file must have def or defyaml extension"); } - File gazbinFile = new File(gazbinFileName); + URL gazbinURL = new URL(gazbinFileName); - String gazbinDir = gazbinFile.getParent(); - String gazbinName = gazbinFile.getName(); + String gazbinDir = UrlUtils.getParent(gazbinURL); + String gazbinName = UrlUtils.getName(gazbinURL); // Always read the yaml file so we can get any special location of the cache // file or figure out that we should not try to load the cache file Yaml yaml = new Yaml(); BufferedReader yamlReader = - new BomStrippingInputStreamReader((configFileURL).openStream(), encoding); + new BomStrippingInputStreamReader((configFileURL).openStream(), UTF8); Object configObject = yaml.load(yamlReader); List configListFiles = null; @@ -385,7 +409,7 @@ protected void loadDataFromYaml(File configFile) throws IOException { if (configCacheFileName != null) { gazbinName = configCacheFileName; } - gazbinFile = new File(new File(gazbinDir), gazbinName); + gazbinURL = UrlUtils.newURL(new URL(gazbinDir), gazbinName); configListFiles = (List) configMap.get("listFiles"); } else if (configObject instanceof List) { configListFiles = (List) configObject; @@ -394,9 +418,9 @@ protected void loadDataFromYaml(File configFile) throws IOException { } // if we want to load the cache and it exists, load it - if (gazbinFile.exists()) { + if (UrlUtils.exists(gazbinURL)) { gazStore = new GazStoreTrie3(); - gazStore = gazStore.load(gazbinFile); + gazStore = gazStore.load(gazbinURL); } else { gazStore = new GazStoreTrie3(); // go through all the list and tsv files to load and load them @@ -409,8 +433,11 @@ protected void loadDataFromYaml(File configFile) throws IOException { gazStore.compact(); logger.info("Gazetteer loaded from list files"); - gazStore.save(gazbinFile); - } // gazbinFile exists ... else + if(UrlUtils.isFile(gazbinURL)) { + File gazbinFile = Files.fileFromURL(gazbinURL); + gazStore.save(gazbinFile); + } + } } void loadListFile(String listFileName, String majorType, String minorType, @@ -430,9 +457,9 @@ void loadListFile(String listFileName, String majorType, String minorType, // languages, annotationType); BufferedReader listReader = null; if (listFileName.endsWith(".gz")) { - listReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(lurl.openStream()), encoding)); + listReader = new BufferedReader(new InputStreamReader(new GZIPInputStream(lurl.openStream()), UTF8)); } else { - listReader = new BomStrippingInputStreamReader(lurl.openStream(), encoding); + listReader = new BomStrippingInputStreamReader(lurl.openStream(), UTF8); } String line; int lines = 0; diff --git a/src/com/jpetrak/gate/stringannotation/extendedgazetteer/trie/GazStoreTrie3.java b/src/com/jpetrak/gate/stringannotation/extendedgazetteer/trie/GazStoreTrie3.java index a1d1b74..4261aff 100644 --- a/src/com/jpetrak/gate/stringannotation/extendedgazetteer/trie/GazStoreTrie3.java +++ b/src/com/jpetrak/gate/stringannotation/extendedgazetteer/trie/GazStoreTrie3.java @@ -47,6 +47,7 @@ import com.jpetrak.gate.stringannotation.extendedgazetteer.ListInfo; import com.jpetrak.gate.stringannotation.extendedgazetteer.Lookup; import com.jpetrak.gate.stringannotation.extendedgazetteer.Visitor; +import java.net.URL; public class GazStoreTrie3 extends GazStore { @@ -518,19 +519,18 @@ public void save(File whereTo) throws IOException { } @Override - public GazStore load(File whereFrom) throws IOException { + public GazStore load(URL whereFrom) throws IOException { System.out.println("Loading cache file from "+whereFrom); long start = System.currentTimeMillis(); - InputStream input = new FileInputStream(whereFrom); - input = new GZIPInputStream(input); - ObjectInputStream inputobject = new ObjectInputStream(input); Object object = null; - try { - object = inputobject.readObject(); - inputobject.close(); - } catch (ClassNotFoundException e) { - throw new GateRuntimeException("Could not re-load gazstore object: class error"+e); + try (InputStream ins = whereFrom.openStream(); + GZIPInputStream ing = new GZIPInputStream(ins); + ObjectInputStream ino = new ObjectInputStream(ing)) { + object = ino.readObject(); + } catch (Exception ex) { + throw new GateRuntimeException("Could not re-load gazstore object from"+whereFrom,ex); } + if(object == null) throw new GateRuntimeException("Still null: Could not re-load gazstore object from "+whereFrom); GazStoreTrie3 gs = null; if(object instanceof GazStoreTrie3) { gs = (GazStoreTrie3)object; diff --git a/src/com/jpetrak/gate/stringannotation/tests/Tests1.java b/src/com/jpetrak/gate/stringannotation/tests/Tests1.java index a3de871..9e190b2 100644 --- a/src/com/jpetrak/gate/stringannotation/tests/Tests1.java +++ b/src/com/jpetrak/gate/stringannotation/tests/Tests1.java @@ -423,7 +423,7 @@ public void testGazStoreTrie3() throws IOException { } GazStoreTrie3 gs2 = new GazStoreTrie3(); try { - gs2 = (GazStoreTrie3)gs2.load(someFile); + gs2 = (GazStoreTrie3)gs2.load(someFile.toURI().toURL()); } catch (FileNotFoundException e) { e.printStackTrace(); assertTrue("could not load trie",false); diff --git a/src/com/jpetrak/gate/stringannotation/tests/Tests2.java b/src/com/jpetrak/gate/stringannotation/tests/Tests2.java index b798e89..82bad1d 100644 --- a/src/com/jpetrak/gate/stringannotation/tests/Tests2.java +++ b/src/com/jpetrak/gate/stringannotation/tests/Tests2.java @@ -100,7 +100,7 @@ public void testGazetteerApplicationBig_BE3() before = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); startTime = System.currentTimeMillis(); GazStoreTrie3 gs = new GazStoreTrie3(); - gs = (GazStoreTrie3)gs.load(save); + gs = (GazStoreTrie3)gs.load(save.toURI().toURL()); endTime = System.currentTimeMillis(); after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); System.out.println("Loading completed"); diff --git a/src/com/jpetrak/gate/stringannotation/tests/Tests3.java b/src/com/jpetrak/gate/stringannotation/tests/Tests3.java index 7316e87..8977d61 100644 --- a/src/com/jpetrak/gate/stringannotation/tests/Tests3.java +++ b/src/com/jpetrak/gate/stringannotation/tests/Tests3.java @@ -157,7 +157,7 @@ public void testPersistenceBig1() before = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); startTime = System.currentTimeMillis(); GazStoreTrie3 gs = new GazStoreTrie3(); - gs = (GazStoreTrie3)gs.load(save); + gs = (GazStoreTrie3)gs.load(save.toURI().toURL()); endTime = System.currentTimeMillis(); after = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); System.out.println("Loading from GAZBIN completed"); diff --git a/src/com/jpetrak/gate/stringannotation/utils/StoreArrayOfCharArrays.java b/src/com/jpetrak/gate/stringannotation/utils/StoreArrayOfCharArrays.java index 707124c..9acc687 100644 --- a/src/com/jpetrak/gate/stringannotation/utils/StoreArrayOfCharArrays.java +++ b/src/com/jpetrak/gate/stringannotation/utils/StoreArrayOfCharArrays.java @@ -2,8 +2,8 @@ * Copyright (c) 2010- Austrian Research Institute for Artificial Intelligence (OFAI). * Copyright (C) 2014-2016 The University of Sheffield. * - * This file is part of gateplugin-ModularPipelines - * (see https://github.com/johann-petrak/gateplugin-ModularPipelines) + * This file is part of gateplugin-StringAnnotation + * (see https://github.com/johann-petrak/gateplugin-StringAnnotation) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License diff --git a/src/com/jpetrak/gate/stringannotation/utils/TextChunk.java b/src/com/jpetrak/gate/stringannotation/utils/TextChunk.java index ec1f822..5aa56fb 100644 --- a/src/com/jpetrak/gate/stringannotation/utils/TextChunk.java +++ b/src/com/jpetrak/gate/stringannotation/utils/TextChunk.java @@ -2,8 +2,8 @@ * Copyright (c) 2010- Austrian Research Institute for Artificial Intelligence (OFAI). * Copyright (C) 2014-2016 The University of Sheffield. * - * This file is part of gateplugin-ModularPipelines - * (see https://github.com/johann-petrak/gateplugin-ModularPipelines) + * This file is part of gateplugin-StringAnnotation + * (see https://github.com/johann-petrak/gateplugin-StringAnnotation) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License diff --git a/src/com/jpetrak/gate/stringannotation/utils/UrlUtils.java b/src/com/jpetrak/gate/stringannotation/utils/UrlUtils.java new file mode 100644 index 0000000..5473209 --- /dev/null +++ b/src/com/jpetrak/gate/stringannotation/utils/UrlUtils.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2010- Austrian Research Institute for Artificial Intelligence (OFAI). + * Copyright (C) 2014-2016 The University of Sheffield. + * + * This file is part of gateplugin-StringAnnotation + * (see https://github.com/johann-petrak/gateplugin-StringAnnotation) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software. If not, see . + */ +package com.jpetrak.gate.stringannotation.utils; + +import gate.util.GateRuntimeException; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +/** + * Class with utility methods for handling URLs. + * + * @author Johann Petrak + */ +public class UrlUtils { + + /** + * Create a URL from the String. + * If the String does not have a protocol/scheme, file:// is prepended. + * @param str + * @return + */ + public static URL newURL(String str) { + try { + if(new URI(str).getScheme() == null) { + str = "file://"+str; + } + return new URL(str); + } catch (Exception ex) { + throw new GateRuntimeException("Cannot create URL from string "+str,ex); + } + } + + /** + * Equivalent of creating a new file from a directory file and name string. + * + * This tries to roughly provide the equivalent of "new File(dirFile, nameString)" + * for a URL and a name String. The catch is that in order for this to work, + * the given dir URL must end in a slash. This method adds the slash if necessary + * and returns the URL of the combined paths. + * + * @param dir + * @param file + */ + public static URL newURL(URL dirURL, String fileName) { + String s = dirURL.toExternalForm(); + if(!s.endsWith("/")) { + try { + dirURL = new URL(s+"/"); + } catch (MalformedURLException ex) { + throw new GateRuntimeException("Could not create URL for "+s+"/",ex); + } + } + try { + URL ret = new URL(dirURL,fileName); + return ret; + } catch (MalformedURLException ex) { + throw new GateRuntimeException("Could not create URL for "+dirURL+"fileName"); + } + } + + /** + * Return the last path component of a hierarchical path of URL. + * This assumes a URL which ends in a hierarchical path, without a query + * or anchor or anything else following the path. + * If there is nothing that looks like it could be the last path component, + * the empty string is returned. + * NOTE: if the URL ends with a slash, then the last component without a trailing + * slash is returned. + *

+ * This is made intentionally to work similar to the someFile.getName() method. + * @param url + * @return + */ + public static String getName(URL url) { + String p; + try { + p = url.toURI().getPath(); + } catch (URISyntaxException ex) { + throw new GateRuntimeException("Cannot convert URL to URI: "+url,ex); + } + // remove any trailing slash + if(p.endsWith("/")) { + p=p.substring(0,p.length()-1); + } + int i = p.lastIndexOf("/"); + if(i<0) return ""; // no slash at all, we do not have a path + return p.substring(i+1); + } + + /** + * Return the parent path for a URL. + * This is the path, with the last component of the path removed, i.e. + * with that part removed that is returned by the getName() method. + *

+ * This returns null if the path is a slash or something without a slash. + * + */ + public static String getParent(URL url) { + String p; + try { + p = url.toURI().getPath(); + } catch (URISyntaxException ex) { + throw new GateRuntimeException("Cannot convert URL to URI: "+url,ex); + } + if(p.equals("/")) return null; + // NOTE: we ignore odd cases where the path is just several slashes in succession + + // .. not just a lone slash, remove any trailing slash + if(p.endsWith("/")) { + p=p.substring(0,p.length()-1); + } + int i = p.lastIndexOf("/"); + if(i<0) return null; // no slash at all + + // we found the slash that separates the last name part from the rest + // the parent is whatever comes before that + return p.substring(0,i); + } + + + /** + * Returns true if the URL can be opened for reading. + * + * @param url + * @return + */ + public static boolean exists(URL url) { + boolean ret = true; + try (InputStream is = url.openStream()) { + // do nothing, we only want to check the opening + } catch (IOException ex) { + ret = false; + } + return ret; + } + + /** + * Return truen if the URL is a file URL. + * @param url + * @return + */ + public static boolean isFile(URL url) { + return "file".equals(url.getProtocol()); + } + + +} diff --git a/tests/testJavaRegexpAnn.xgapp b/tests/testJavaRegexpAnn.xgapp index ef7a827..dd86cf8 100644 --- a/tests/testJavaRegexpAnn.xgapp +++ b/tests/testJavaRegexpAnn.xgapp @@ -2,7 +2,7 @@ - $relpath$../../gateplugin-stringannotation/ + $relpath$../ java.util.ArrayList @@ -239,4 +239,4 @@ - \ No newline at end of file +