Revision: 15215
          http://gate.svn.sourceforge.net/gate/?rev=15215&view=rev
Author:   valyt
Date:     2012-01-25 14:45:08 +0000 (Wed, 25 Jan 2012)
Log Message:
-----------
All reads and writes now use UTF-8 as their encoding (used to be the 'platform 
default', which meant that files were not portable, and carried the wrong XML 
preamble on platforms that don't use UTF-8).

Modified Paths:
--------------
    
gate/trunk/plugins/Ontology/src/gate/creole/ontology/impl/sesame/AbstractOntologyImplSesame.java

Modified: 
gate/trunk/plugins/Ontology/src/gate/creole/ontology/impl/sesame/AbstractOntologyImplSesame.java
===================================================================
--- 
gate/trunk/plugins/Ontology/src/gate/creole/ontology/impl/sesame/AbstractOntologyImplSesame.java
    2012-01-25 14:18:15 UTC (rev 15214)
+++ 
gate/trunk/plugins/Ontology/src/gate/creole/ontology/impl/sesame/AbstractOntologyImplSesame.java
    2012-01-25 14:45:08 UTC (rev 15215)
@@ -24,12 +24,17 @@
 import gate.creole.ontology.impl.AbstractOntologyImpl;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
 import java.util.Set;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLInputFactory;
@@ -57,9 +62,9 @@
 
   public void readOntologyData(java.net.URL theURL, String baseURI,
       OConstants.OntologyFormat format, boolean asImport) {
-    InputStream is;
+    Reader input;
     try {
-      is = theURL.openStream();
+      input = new InputStreamReader(theURL.openStream(), "UTF-8");
     } catch (IOException ex) {
       throw new GateOntologyException("Problem reading from URL " + theURL, 
ex);
     }
@@ -68,10 +73,11 @@
       isBaseURIset = false;
       baseURI = OConstants.ONTOLOGY_DEFAULT_BASE_URI;
     }
-    ((OntologyServiceImplSesame) ontologyService).readOntologyData(is,
+    ((OntologyServiceImplSesame) ontologyService).readOntologyData(
+        input,
         baseURI, format, asImport);
     try {
-      is.close();
+      input.close();
     } catch (IOException ex) {
       throw new GateOntologyException("Problem closing stream from URL " + 
theURL, ex);
     }
@@ -89,12 +95,19 @@
 
   public void readOntologyData(File selectedFile, String baseURI,
       OConstants.OntologyFormat format, boolean asImport) {
+    Reader input;
+    try {
+      input = new InputStreamReader(new FileInputStream(selectedFile), 
"UTF-8");
+    } catch (IOException ex) {
+      throw new GateOntologyException("Problem reading from file " + 
+          selectedFile, ex);
+    }
     boolean isBaseURIset = true;
     if(baseURI == null || baseURI.length() == 0) {
       isBaseURIset = false;
       baseURI = OConstants.ONTOLOGY_DEFAULT_BASE_URI;
     }
-   ((OntologyServiceImplSesame) ontologyService).readOntologyData(selectedFile,
+   ((OntologyServiceImplSesame) ontologyService).readOntologyData(input,
         baseURI, format, asImport);
     if(!asImport) {
       if(isBaseURIset && getDefaultNameSpace() == null) {
@@ -128,12 +141,18 @@
 
   public void readOntologyData(InputStream in, String baseURI,
       OntologyFormat format, boolean asImport) {
+    Reader input;
+    try {
+      input = new InputStreamReader(in, "UTF-8");
+    } catch (IOException ex) {
+      throw new GateOntologyException("Problem reading the input stream.", ex);
+    }
     boolean isBaseURIset = true;
     if(baseURI == null || baseURI.length() == 0) {
       isBaseURIset = false;
       baseURI = OConstants.ONTOLOGY_DEFAULT_BASE_URI;
     }
-    ((OntologyServiceImplSesame) ontologyService).readOntologyData(in,
+    ((OntologyServiceImplSesame) ontologyService).readOntologyData(input,
         baseURI, format, asImport);
     if(!asImport) {
       if(isBaseURIset && getDefaultNameSpace() == null) {
@@ -252,20 +271,27 @@
 
   public void writeOntologyData(File selectedFile,
       OConstants.OntologyFormat format, boolean includeImports) {
-    FileWriter fw;
+    Writer writer;
     try {
-      fw = new FileWriter(selectedFile);
+      writer = new OutputStreamWriter(new FileOutputStream(selectedFile), 
+          "UTF-8");
     } catch (IOException ex) {
       throw new GateOntologyException("Could not open writer for file " +
           selectedFile.getAbsolutePath(), ex);
     }
-    ((OntologyServiceImplSesame) ontologyService).writeOntologyData(fw,
+    ((OntologyServiceImplSesame) ontologyService).writeOntologyData(writer,
         format, includeImports);
   }
 
   public void writeOntologyData(OutputStream out, OntologyFormat format,
       boolean includeImports) {
-    ((OntologyServiceImplSesame) ontologyService).writeOntologyData(out,
+    Writer writer;
+    try {
+      writer = new OutputStreamWriter(out, "UTF-8");
+    } catch (IOException ex) {
+      throw new GateOntologyException("Could not open writer", ex);
+    }
+    ((OntologyServiceImplSesame) ontologyService).writeOntologyData(writer,
         format, includeImports);
   }
 

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


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to