private static JsonObject toAttributesObject(Attributes targetSeriesAttrs) { StringWriter strWriter = new StringWriter(); JsonGenerator gen = Json.createGenerator(strWriter); JSONWriter writer = new JSONWriter(gen); writer.write(targetSeriesAttrs); gen.flush(); gen.close(); return Json.createReader(new StringReader(strWriter.toString())) .readObject(); }
case UR: case UT: writeStringValues(vr, val, bigEndian, cs); break; case FL: case FD: writeDoubleValues(vr, val, bigEndian); break; case SL: case SS: case US: writeIntValues(vr, val, bigEndian); break; case UL: writeUIntValues(vr, val, bigEndian); break; case OB: case OW: case UN: writeInlineBinary(vr, (byte[]) val, bigEndian, preserve); break; case SQ:
private Object readDataFragment() { byte[] bytes = null; String bulkDataURI = null; while (next() == Event.KEY_NAME) { switch (getString()) { case "BulkDataURI": bulkDataURI = valueString(); break; case "InlineBinary": bytes = readInlineBinary(); break; default: throw new JsonParsingException("Unexpected \"" + getString() + "\", expected \"InlineBinary\"" + " or \"BulkDataURI\"", parser.getLocation()); } } expect(Event.END_OBJECT); return bulkDataURI != null && !skipBulkDataURI ? new BulkData(null, bulkDataURI, false) : bytes; }
private Object readItemOrPersonName() { if (next() != JsonParser.Event.KEY_NAME) return null; return (getString().length() == 8) ? doReadDataset(new Attributes()) : readPersonName(); }
private static JSONReader parseJSON(String fname, Attributes attrs) throws IOException { @SuppressWarnings("resource") InputStream in = fname.equals("-") ? System.in : new FileInputStream(fname); try { JSONReader reader = new JSONReader( Json.createParser(new InputStreamReader(in, "UTF-8"))); reader.readDataset(attrs); return reader; } finally { if (in != System.in) SafeClose.close(in); } }
public void parse(DicomInputStream dis) throws IOException { dis.setIncludeBulkData(includeBulkData); dis.setBulkDataDescriptor(bulkDataDescriptor); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); JsonGenerator jsonGen = createGenerator(System.out); JSONWriter jsonWriter = new JSONWriter(jsonGen); dis.setDicomInputHandler(jsonWriter); dis.readDataset(-1, -1); jsonGen.flush(); }
private Attributes doReadDataset(Attributes attrs) { while (event == JsonParser.Event.KEY_NAME) { readAttribute(attrs); next(); } expect(JsonParser.Event.END_OBJECT); attrs.trimToSize(); return attrs; }
JSONReader reader = new JSONReader(new InputStreamReader(con.getInputStream()));
private List<Object> readDataFragments() { ArrayList<Object> list = new ArrayList<>(); next(); expect(Event.START_ARRAY); while (next() != Event.END_ARRAY) { switch (event) { case START_OBJECT: list.add(readDataFragment()); break; case VALUE_NULL: list.add(null); break; default: throw new JsonParsingException("Unexpected " + event, parser.getLocation()); } } return list; }
private List<Object> readValues() { ArrayList<Object> list = new ArrayList<>(); next(); expect(Event.START_ARRAY); while (next() != Event.END_ARRAY) { switch (event) { case START_OBJECT: list.add(readItemOrPersonName()); break; case VALUE_STRING: list.add(parser.getString()); break; case VALUE_NUMBER: list.add(parser.getBigDecimal()); break; case VALUE_NULL: list.add(null); break; default: throw new JsonParsingException("Unexpected " + event, parser.getLocation()); } } return list; }
public void mergeJSON(String fname) throws Exception { if (dataset == null) dataset = new Attributes(); JSONReader reader = parseJSON(fname, dataset); Attributes fmi2 = reader.getFileMetaInformation(); if (fmi2 != null) fmi = fmi2; }
private void writePersonName(String s) { PersonName pn = new PersonName(s, true); gen.writeStartObject(); writePNGroup("Alphabetic", pn, PersonName.Group.Alphabetic); writePNGroup("Ideographic", pn, PersonName.Group.Ideographic); writePNGroup("Phonetic", pn, PersonName.Group.Phonetic); gen.writeEnd(); }
private byte[] readInlineBinary() { char[] base64 = valueString().toCharArray(); bout.reset(); try { Base64.decode(base64, 0, base64.length, bout); } catch (IOException e) { throw new RuntimeException(e); } return bout.toByteArray(); }
private void writeInlineBinary(VR vr, byte[] b, boolean bigEndian, boolean preserve) { if (bigEndian) b = vr.toggleEndian(b, preserve); gen.write("InlineBinary", encodeBase64(b)); }
private void writeAttribute(int tag, VR vr, Object value, SpecificCharacterSet cs, Attributes attrs) { if (TagUtils.isGroupLength(tag)) return; gen.writeStartObject(TagUtils.toHexString(tag)); gen.write("vr", vr.name()); if (value instanceof Value) writeValue((Value) value, attrs.bigEndian()); else writeValue(vr, value, attrs.bigEndian(), attrs.getSpecificCharacterSet(vr), true); gen.writeEnd(); }
public void parse(DicomInputStream dis) throws IOException { dis.setIncludeBulkData(includeBulkData); dis.setBulkDataDescriptor(bulkDataDescriptor); dis.setBulkDataDirectory(blkDirectory); dis.setBulkDataFilePrefix(blkFilePrefix); dis.setBulkDataFileSuffix(blkFileSuffix); dis.setConcatenateBulkDataFiles(catBlkFiles); JsonGenerator jsonGen = createGenerator(System.out); JSONWriter jsonWriter = new JSONWriter(jsonGen); dis.setDicomInputHandler(jsonWriter); dis.readDataset(-1, -1); jsonGen.flush(); }
public void mergeJSON(String fname) throws Exception { if (dataset == null) dataset = new Attributes(); JSONReader reader = parseJSON(fname, dataset); Attributes fmi2 = reader.getFileMetaInformation(); if (fmi2 != null) fmi = fmi2; }