現在、私はDicom XMLデータを受け取ってSAXParserを使用してデータを解析し、解析されたデータを属性オブジェクト(https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/Attributes.java)として保存し、attributesオブジェクトに属性リストを追加します。DICOM属性作成時のSAXParser
私がXMLに使用するパーサーはSAXParserです。また、SAXParserFactoryを使用してXMLパーサーインスタンスを作成します。
Acceptヘッダーを変更した後で、XMLではなくJSONで同じDICOMデータを受信するようになりました。同じ目的のために使用できるJSONパーサとパーサーファクトリはありますか?もしそうなら、現在のコードをどのように変更すればよいですか?
私の現在の解析コード:
public void bodyPart(int i, MultipartInputStream partInputStream) throws IOException {
try {
partInputStream.readHeaderParams();
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
Attributes dicomAttributes = new Attributes();
parser.parse(new AttributesList.NonClosingInputSteam(partInputStream), new ContentHandlerAdapter(dicomAttributes));
attributesList.add(dicomAttributes);
}
catch (ParserConfigurationException | SAXException e) {
// This should never happen unless the server returns invalid content. Log and return.
log.error("Error parsing!", e);
e.printStackTrace();
}
}
private static class NonClosingInputSteam extends FilterInputStream {
/**
* Creates a new NonClosingInputStream that wraps another input stream.
*
* @param in the input stream to be wrapped
*/
NonClosingInputSteam(InputStream in) {
super(in);
}
/**
* Overrides the default implementation of the input stream's close() method. This implementation
* does nothing.
*/
@Override
public void close() {
// Do nothing
}
}
ありがとう!