-
Notifications
You must be signed in to change notification settings - Fork 146
/
EnhancedTurtleWriter.java
64 lines (52 loc) · 2.19 KB
/
EnhancedTurtleWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
A copy of the License is located at
http://www.apache.org/licenses/LICENSE-2.0
or in the "license" file accompanying this file. This file is distributed
on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing
permissions and limitations under the License.
*/
package com.amazonaws.services.neptune.rdf.io;
import com.amazonaws.services.neptune.io.Status;
import com.amazonaws.services.neptune.io.OutputWriter;
import com.amazonaws.services.neptune.io.StatusOutputFormat;
import com.amazonaws.services.neptune.rdf.Prefixes;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.turtle.TurtleWriter;
import java.io.IOException;
public class EnhancedTurtleWriter extends TurtleWriter {
private final OutputWriter writer;
private final Prefixes prefixes;
private final Status status = new Status(StatusOutputFormat.Description, "statements");
public EnhancedTurtleWriter(OutputWriter writer, Prefixes prefixes) {
super(writer.writer());
this.writer = writer;
this.prefixes = prefixes;
}
@Override
public void handleStatement(Statement statement) throws RDFHandlerException {
prefixes.parse(statement.getSubject().stringValue(), this);
prefixes.parse(statement.getPredicate().toString(), this);
prefixes.parse(statement.getObject().stringValue(), this);
Resource context = statement.getContext();
if (context != null){
prefixes.parse(context.stringValue(), this);
}
writer.startCommit();
super.handleStatement(statement);
writer.endCommit();
status.update();
}
@Override
protected void writeNamespace(String prefix, String name)
throws IOException {
writer.startCommit();
super.writeNamespace(prefix, name);
writer.endCommit();
}
}