Пример #1
0
  public static void verifyMD5(File file, String originalMd5) throws Exception {
    log.info("M-READ file:" + file);
    MessageDigest md = MessageDigest.getInstance("MD5");

    BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));

    DigestInputStream dis = new DigestInputStream(in, md);
    try {
      DcmParser parser = DcmParserFactory.getInstance().newDcmParser(dis);
      parser.parseDcmFile(FileFormat.DICOM_FILE, Tags.PixelData);
      if ((parser.getReadTag() & 0xFFFFFFFFL) >= Tags.PixelData) {
        if (parser.getReadLength() == -1) {
          while (parser.parseHeader() == Tags.Item) {
            readOut(parser.getInputStream(), parser.getReadLength());
          }
        }
        readOut(parser.getInputStream(), parser.getReadLength());
        parser.parseDataset(parser.getDcmDecodeParam(), -1);
      }
    } finally {
      try {
        dis.close();
      } catch (IOException ignore) {
      }
    }
    byte[] md5 = md.digest();
    if (!Arrays.equals(md5, MD5.toBytes(originalMd5))) {
      log.error(
          "MD5 for "
              + file.getAbsolutePath()
              + " is different that expected.  Has the file been changed or corrupted?");
      throw new IllegalStateException("MD5 mismatch");
    }
  }
 private FileDTO getFileDTO() throws SQLException {
   FileDTO dto = new FileDTO();
   dto.setPk(rs.getLong(1));
   dto.setFilePath(rs.getString(2));
   dto.setFileMd5(MD5.toBytes(rs.getString(3)));
   dto.setFileStatus(rs.getInt(4));
   dto.setFileSystemGroupID(rs.getString(5));
   dto.setDirectoryPath(rs.getString(6));
   dto.setRetrieveAET(rs.getString(7));
   dto.setAvailability(rs.getInt(8));
   dto.setUserInfo(rs.getString(9));
   dto.setSopClassUID(rs.getString(10));
   dto.setSopInstanceUID(rs.getString(11));
   numberOfSeriesRelatedInstances = rs.getInt(12);
   dto.setExternalRetrieveAET(rs.getString(13));
   return dto;
 }