JSONReader reader = new JSONReader(new InputStreamReader(con.getInputStream()));
private Object readItemOrPersonName() { if (next() != JsonParser.Event.KEY_NAME) return null; return (getString().length() == 8) ? doReadDataset(new Attributes()) : readPersonName(); }
private void readAttribute(Attributes attrs) { int tag = (int) Long.parseLong(getString(), 16); if (TagUtils.isFileMetaInformation(tag)) { if (fmi == null) next(); expect(Event.START_OBJECT); Element el = new Element(); while (next() == JsonParser.Event.KEY_NAME) { switch (getString()) { case "vr": try { el.vr = VR.valueOf(valueString()); } catch (IllegalArgumentException e) { throw new JsonParsingException("Invalid vr: " + getString(), parser.getLocation()); el.values = readValues(); break; case "InlineBinary": el.bytes = readInlineBinary(); break; case "BulkDataURI": el.bulkDataURI = valueString(); break; case "DataFragment": el.values = readDataFragments(); break; default: throw new JsonParsingException("Unexpected \"" + getString() + "\", expected \"Value\" or \"InlineBinary\""
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 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); } }
@Override boolean readBody(final QidoRS qidors, InputStream in) throws IOException, ParserConfigurationException, SAXException { if(qidors.isRunningModeTest()) { try { JSONReader reader = new JSONReader( Json.createParser(new InputStreamReader(in, "UTF-8"))); reader.readDatasets(new Callback() { @Override public void onDataset(Attributes fmi, Attributes dataset) { if(qidors.getTimeFirst() == 0) qidors.setTimeFirst(System.currentTimeMillis()); qidors.responseAttrs.add(dataset); qidors.numMatches++; } }); } finally { if (in != System.in) SafeClose.close(in); } } else { Files.copy(in, new File(qidors.outDir, qidors.outFileName).toPath() , StandardCopyOption.REPLACE_EXISTING); } return true; } };
private Attributes doReadDataset(Attributes attrs) { while (event == JsonParser.Event.KEY_NAME) { readAttribute(attrs); next(); } expect(JsonParser.Event.END_OBJECT); attrs.trimToSize(); return attrs; }
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; }
Group key; try { key = PersonName.Group.valueOf(getString()); } catch (IllegalArgumentException e) { throw new JsonParsingException("Unexpected \"" + getString() + "\", expected \"Alphabetic\" or \"Ideographic\"" + " or \"Phonetic\"", parser.getLocation()); pnGroups.put(key, valueString()); next(); expect(JsonParser.Event.END_OBJECT); String s = pnGroups.get(PersonName.Group.Alphabetic); if (s != null && pnGroups.size() == 1)
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 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; }