--- /dev/null
+import "Simantics/DB"
+import "File"
+
+
+importJava "org.simantics.graphfile.util.GraphFileUtil" where
+ "Writes contents of a file to DB, including the timestamp"
+ @JavaName writeDataToGraphSCLhack
+ writeDataToGraph:: File -> Resource -> <WriteGraph>()
+
+ "Writes contents of a byte array to DB"
+ @JavaName writeDataToGraph
+ writeDataToGraphBytes:: ByteArray -> Resource -> <WriteGraph>()
+
+ "Creates a temp file of a GraphFile resource"
+ @JavaName toTempFileSCLhack
+ toTempFile :: Resource -> <ReadGraph> File
+
+ "Writes contents of a GraphFile into a regular File"
+ @JavaName writeDataToFileSCLhack
+ writeDataToFile :: Resource -> File -> <ReadGraph>()
+
+ "Writes contents of a file to DB, including the filename and timestamp"
+ @JavaName toGraphSCLhack
+ toGraphWithPath :: String -> Resource -> <WriteGraph>()
+
+ "Writes contents of a file to DB, including the filename and timestamp"
+ @JavaName toGraph
+ toGraph :: File -> Resource -> <WriteGraph>()
+
+ "Returns contents of a GraphFile as a byte array"
+ @JavaName getData
+ getData :: Resource -> <ReadGraph> ByteArray
+
+ "Returns contents of a GraphFile as a String"
+ @JavaName getDataAsString
+ getDataAsString :: Resource -> <ReadGraph> String
+
+
+
+
+
\ No newline at end of file
package org.simantics.graphfile.util;
import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.common.request.WriteResultRequest;
import org.simantics.db.common.utils.LiteralFileUtil;
+import org.simantics.db.common.utils.Logger;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.exception.DoesNotContainValueException;
import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
import org.simantics.db.exception.ServiceException;
import org.simantics.db.request.Read;
import org.simantics.db.service.ClusteringSupport;
+import org.simantics.db.service.TransferableGraphSupport;
import org.simantics.graphfile.ontology.GraphFileResource;
import org.simantics.layer0.Layer0;
}
});
}
+
+ /**
+ * SCL java binding cannot make difference between methods that have two versions, one with Read/WriteGraph, and one without.
+ * Hence we have to introduce a set of methods which have no alternate versions.
+ */
+
+
+ public static void writeDataToGraphSCLhack(WriteGraph graph, File file, Resource graphFile) throws IOException, DatabaseException{
+ writeDataToGraph(graph, file, graphFile);
+
+ }
+
+ public static File toTempFileSCLhack(ReadGraph graph, Resource res)throws DatabaseException {
+ return toTempFile(graph, res);
+ }
+
+ public static void writeDataToFileSCLhack(ReadGraph graph, Resource res, File file) throws DatabaseException, IOException {
+ writeDataToFile(graph, res, file);
+ }
+
+ public static void toGraphSCLhack(WriteGraph graph, String filename, Resource graphFile) throws DatabaseException, IOException {
+ toGraph(graph, filename, graphFile);
+ }
+
+
+ public static byte[] getData(ReadGraph graph, Resource graphFile) throws DatabaseException{
+ GraphFileResource GF = GraphFileResource.getInstance(graph);
+ Resource fileData = graph.getSingleObject(graphFile, GF.HasFiledata);
+ TransferableGraphSupport tgs = graph.getService(TransferableGraphSupport.class);
+ InputStream input = tgs.getValueStream(graph, fileData);
+ DataInputStream di = new DataInputStream(input);
+ try {
+ int length = di.readInt();
+ byte[] content = new byte[length];
+ di.read(content);
+ return content;
+ } catch (IOException e) {
+ Logger.defaultLogError(e);
+ }
+ return null;
+ }
+
+ public static String getDataAsString(ReadGraph graph, Resource graphFile) throws DatabaseException{
+ byte[] content = getData(graph, graphFile);
+ String s = new String(content);
+ return s;
+ }
+
}