Skip to content

Commit 5582d5b

Browse files
committed
Restore previous APIs for Writer
1 parent b3a4d08 commit 5582d5b

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

buildNumber.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#maven.buildNumber.plugin properties file
2-
#Sun Jun 08 17:31:20 CEST 2025
3-
buildNumber0=375
2+
#Sun Jun 08 18:28:21 CEST 2025
3+
buildNumber0=378

src/main/java/be/ugent/rml/store/QuadStore.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,20 @@ public abstract class QuadStore {
127127
public abstract void read(InputStream is, String base, RDFFormat format) throws Exception;
128128

129129
/**
130-
* Write out the QuadStore in given format
130+
* Write out the QuadStore in given format.
131+
* Deprecated, use write(OutputStream out, String format) instead.
132+
* TODO remove this method in future versions, use write(OutputStream out, String format) instead.
133+
*
134+
* @param out Writer output location
135+
* @param format QuadStore format (.TTL)
136+
* @throws Exception
137+
*/
138+
@Deprecated
139+
public abstract void write(Writer out, String format) throws Exception;
140+
141+
/**
142+
* Write out the QuadStore in given format, using a binary output stream.
143+
* Override this method if you want to support binary formats like Jelly.
131144
* TODO use class or enum for output format
132145
*
133146
* @param out OutputStream to write to
@@ -138,7 +151,18 @@ public abstract class QuadStore {
138151

139152
// END OF ABSTRACT METHODS
140153

141-
// following final methods use the abstract metho`ds to provide additional functionality or helper functions
154+
// following final methods use the abstract methods to provide additional functionality or helper functions
155+
/**
156+
* Helper function
157+
*
158+
* @param out
159+
* @param format
160+
* @throws Exception
161+
*/
162+
public final void write(PrintStream out, String format) throws Exception {
163+
write(new PrintWriter(out), format);
164+
}
165+
142166
/**
143167
* Helper function
144168
*

src/main/java/be/ugent/rml/store/RDF4JStore.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

21-
import java.io.InputStream;
22-
import java.io.OutputStream;
23-
import java.io.Writer;
21+
import java.io.*;
2422
import java.util.ArrayList;
2523
import java.util.List;
2624
import java.util.Optional;
@@ -153,7 +151,7 @@ public void read(InputStream is, String base, RDFFormat format) throws Exception
153151
}
154152

155153
@Override
156-
public void write(OutputStream out, String format) throws Exception {
154+
public void write(Writer out, String format) throws Exception {
157155
switch (format) {
158156
case "turtle":
159157
Rio.write(model, out, RDFFormat.TURTLE);
@@ -177,16 +175,28 @@ public void write(OutputStream out, String format) throws Exception {
177175
Rio.write(model, out, RDFFormat.NTRIPLES);
178176
break;
179177
case "jelly":
180-
var settings = JellyWriterSettings.empty();
181-
// Mark RDF-star as not used
182-
settings.setJellyOptions(JellyOptions.BIG_STRICT);
183-
Rio.write(model, out, JellyFormat.JELLY, settings);
184-
break;
178+
throw new UnsupportedOperationException(
179+
"Writing Jelly format to a Writer is not supported. Use OutputStream instead."
180+
);
185181
default:
186182
throw new Exception("Serialization " + format + " not supported");
187183
}
188184
}
189185

186+
@Override
187+
public void write(OutputStream out, String format) throws Exception {
188+
// Jelly is the only format that requires a binary output stream
189+
if (format.equals("jelly")) {
190+
var settings = JellyWriterSettings.empty();
191+
// Mark RDF-star as not used
192+
settings.setJellyOptions(JellyOptions.BIG_STRICT);
193+
Rio.write(model, out, JellyFormat.JELLY, settings);
194+
} else {
195+
// For all other formats, fall back to using the Writer
196+
write(new BufferedWriter(new OutputStreamWriter(out)), format);
197+
}
198+
}
199+
190200
public String getBase() {
191201
Optional<Namespace> base = model.getNamespace("");
192202
if (base.isPresent()) {

src/main/java/be/ugent/rml/store/SimpleQuadStore.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,21 @@ public void read(InputStream is, String base, RDFFormat format) {
108108
}
109109

110110
@Override
111-
public void write(OutputStream out, String format) throws IOException {
111+
public void write(Writer out, String format) throws IOException {
112112
switch (format) {
113113
case "nquads":
114-
toNQuads(new BufferedWriter(new OutputStreamWriter(out)));
114+
toNQuads(out);
115115
break;
116116
default:
117117
throw new Error("Serialization " + format + " not supported");
118118
}
119119
}
120120

121+
@Override
122+
public void write(OutputStream out, String format) throws IOException {
123+
write(new BufferedWriter(new OutputStreamWriter(out)), format);
124+
}
125+
121126
@Override
122127
public boolean equals(Object o) {
123128
throw new UnsupportedOperationException("Method not implemented.");

0 commit comments

Comments
 (0)