Revision: 19988
          http://sourceforge.net/p/gate/code/19988
Author:   markagreenwood
Date:     2017-01-25 14:48:20 +0000 (Wed, 25 Jan 2017)
Log Message:
-----------
ooh some test driven development of a new GATE feature, whatever next!

Added Paths:
-----------
    
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
    
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java

Added: 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
                           (rev 0)
+++ 
gate/branches/sawdust2/gate-core/src/main/java/gate/creole/ResourceReference.java
   2017-01-25 14:48:20 UTC (rev 19988)
@@ -0,0 +1,42 @@
+/*
+ *  ResourceReference.java
+ *
+ *  Copyright (c) 2017, The University of Sheffield. See the file
+ *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ *  This file is part of GATE (see http://gate.ac.uk/), and is free
+ *  software, licenced under the GNU Library General Public License,
+ *  Version 3, June 2007 (in the distribution as file licence.html,
+ *  and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ *  Mark A. Greenwood, 25th January 2017
+ */
+
+package gate.creole;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+
+public class ResourceReference {
+       
+       private URL actualURL;
+       
+       public ResourceReference(URL url) throws IOException {
+               actualURL = url;
+       }
+       
+       public ResourceReference(Plugin plugin, String path) throws IOException 
{
+               actualURL = new URL(plugin.getBaseURL(), path);
+       }
+
+       public InputStream openStream() throws IOException {
+               return actualURL.openStream();
+       }
+
+       public URLConnection openConnection() throws IOException {
+               return actualURL.openConnection();
+       }
+}

Added: 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
===================================================================
--- 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
                               (rev 0)
+++ 
gate/branches/sawdust2/gate-core/src/test/java/gate/creole/TestResourceReference.java
       2017-01-25 14:48:20 UTC (rev 19988)
@@ -0,0 +1,23 @@
+package gate.creole;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+
+import junit.framework.TestCase;
+
+public class TestResourceReference extends TestCase {
+
+       public void testReadFromURL() throws Exception {
+               
+               URL url = 
getClass().getClassLoader().getResource("gate/resources/gate.ac.uk/creole/creole.xml");
+               ResourceReference rr = new ResourceReference(url);
+               
+               try (InputStream in = rr.openStream()) {
+                       String contents = IOUtils.toString(rr.openStream());
+                       
+                       assertEquals("Length of data read not as expected", 98, 
contents.length());
+               }
+       }
+}

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to