use of org.hl7.fhir.r4b.formats.IParser in project org.hl7.fhir.core by hapifhir.
the class ResourceTest method test.
public Resource test() throws FHIRFormatError, FileNotFoundException, IOException {
IParser p;
if (isJson())
p = new JsonParser();
else
p = new XmlParser(false);
Resource rf = p.parse(new FileInputStream(source));
FileOutputStream out = new FileOutputStream(source.getAbsoluteFile() + ".out.json");
JsonParser json1 = new JsonParser();
json1.setOutputStyle(OutputStyle.PRETTY);
json1.compose(out, rf);
out.close();
JsonParser json = new JsonParser();
rf = json.parse(new FileInputStream(source.getAbsoluteFile() + ".out.json"));
out = new FileOutputStream(source.getAbsoluteFile() + ".out.xml");
XmlParser atom = new XmlParser();
atom.setOutputStyle(OutputStyle.PRETTY);
atom.compose(out, rf, true);
out.close();
return rf;
}
use of org.hl7.fhir.r4b.formats.IParser in project org.hl7.fhir.core by hapifhir.
the class ResourceTest method test.
public Resource test() throws FHIRFormatError, FileNotFoundException, IOException {
IParser p;
if (isJson())
p = new JsonParser();
else
p = new XmlParser(false);
Resource rf = p.parse(new FileInputStream(source));
FileOutputStream out = new FileOutputStream(source.getAbsoluteFile() + ".out.json");
JsonParser json1 = new JsonParser();
json1.setOutputStyle(OutputStyle.PRETTY);
json1.compose(out, rf);
out.close();
JsonParser json = new JsonParser();
rf = json.parse(new FileInputStream(source.getAbsoluteFile() + ".out.json"));
out = new FileOutputStream(source.getAbsoluteFile() + ".out.xml");
XmlParser atom = new XmlParser();
atom.setOutputStyle(OutputStyle.PRETTY);
atom.compose(out, rf, true);
out.close();
return rf;
}
use of org.hl7.fhir.r4b.formats.IParser in project org.hl7.fhir.core by hapifhir.
the class ResourceRoundTripTests method testBundle.
@Test
public void testBundle() throws FHIRException, IOException {
// Create new Atom Feed
Bundle feed = new Bundle();
// Serialize Atom Feed
IParser comp = new JsonParser();
ByteArrayOutputStream os = new ByteArrayOutputStream();
comp.compose(os, feed);
os.close();
String json = os.toString();
// Deserialize Atom Feed
JsonParser parser = new JsonParser();
InputStream is = new ByteArrayInputStream(json.getBytes("UTF-8"));
Resource result = parser.parse(is);
if (result == null)
throw new FHIRException("Bundle was null");
}
use of org.hl7.fhir.r4b.formats.IParser in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method LoadZipFile.
private static void LoadZipFile(String server, String file, IParser p, int size, int start, int end) throws IOException, Exception {
System.out.println("Load Zip file " + file);
Bundle b = new Bundle();
b.setType(BundleType.COLLECTION);
b.setId(UUID.randomUUID().toString().toLowerCase());
ZipInputStream zip = new ZipInputStream(new FileInputStream(file));
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
try {
Resource r = p.parse(zip);
b.addEntry().setResource(r);
} catch (Exception e) {
throw new Exception("Error parsing " + entry.getName() + ": " + e.getMessage(), e);
}
}
loadBundle(server, b, size, start, end);
}
use of org.hl7.fhir.r4b.formats.IParser in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method main.
public static void main(String[] args) throws IOException, Exception {
if (args.length < 4) {
System.out.println("Batch uploader takes 4 parameters in order: server base url, file/folder to upload, xml/json, and batch size");
} else {
String server = args[0];
String file = args[1];
// args[2].equals("json") ? new JsonParser() : new XmlParser();
IParser p = new JsonParser();
int size = Integer.parseInt(args[3]);
size = 500;
if (file.endsWith(".xml")) {
throw new FHIRException("Unimplemented file type " + file);
} else if (file.endsWith(".json")) {
throw new FHIRException("Unimplemented file type " + file);
} else if (file.endsWith(".zip")) {
LoadZipFile(server, file, p, size, 0, -1);
} else if (new File(file).isDirectory()) {
LoadDirectory(server, file, p, size);
} else
throw new FHIRException("Unknown file type " + file);
}
}
Aggregations