2017-03-01 2 views
0

현재 Dicom XML 데이터를 받고 SAXParser를 사용하여 데이터를 구문 분석하고 구문 분석 된 데이터를 특성 개체 (https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/Attributes.java)로 저장 한 다음 특성 개체를 특성 목록에 추가하는 프로젝트를 진행하고 있습니다.DICOM 특성을 만들 때의 JSON 용 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 
    } 
} 

감사합니다!

답변

0

기본적으로 하나도 없으므로 직접 작성해야합니다.

하지만 데이터가 기록되는 방식을 볼 수 DICOM의 JSON 형식을 기반으로 사양 here

를보십시오.

더 자세히 살펴보면이 구문을 기반으로 구문 분석하여 구문 분석이 사양에 부합하는지 확인할 수 있습니다.