public static void connectAndCstore()

in util/src/main/java/com/google/cloud/healthcare/imaging/dicomadapter/DicomClient.java [73:113]


  public static void connectAndCstore(
      String sopClassUid,
      String sopInstanceUid,
      InputStream in,
      ApplicationEntity applicationEntity,
      String dimsePeerAet,
      String dimsePeerHost,
      int dimsePeerPort) throws IOException, InterruptedException {
    DicomInputStream din = new DicomInputStream(in);
    din.readFileMetaInformation();

    PresentationContext pc = new PresentationContext(1, sopClassUid, din.getTransferSyntax());
    DicomClient dicomClient;
    try {
      dicomClient = DicomClient.associatePeer(applicationEntity,
          dimsePeerAet, dimsePeerHost, dimsePeerPort, pc);
    } catch (IOException | IncompatibleConnectionException | GeneralSecurityException e) {
      // calling code doesn't need to distinguish these
      throw new IOException(e);
    }

    Association association = dicomClient.getAssociation();
    try {
      FutureDimseRSP handler = new FutureDimseRSP(association.nextMessageID());
      dicomClient.cstore(
          sopClassUid, sopInstanceUid, din.getTransferSyntax(), din, handler);
      handler.next();
      int dimseStatus = handler.getCommand().getInt(Tag.Status, /* default status */ -1);
      if (dimseStatus != Status.Success) {
        throw new IllegalArgumentException("C-STORE failed with status code: " + dimseStatus);
      }
    } finally {
      try {
        association.release();
        association.waitForSocketClose();
      } catch (Exception e) {
        System.err.println("Send C-STORE successfully, but failed to close association");
        e.printStackTrace();
      }
    }
  }