Package eu.planets_project.services.fixity

Examples of eu.planets_project.services.fixity.FixityResult


   */
  public FixityResult calculateChecksum(DigitalObject digitalObject,
      List<Parameter> parameters) {

    // The returned FixityResult & ServiceReport
    FixityResult retResult = null;
    ServiceReport retReport = null;
    try {
      // Let's get the requested message digest from the params (or default)
      URI requestedAlgId = this.getDigestIdFromParameters(parameters);

      // OK let's try to get the digest algorithm
      MessageDigest messDigest =
        MessageDigest.getInstance(JavaDigestUtils.getJavaAlgorithmName(requestedAlgId));
     
      // Now calc the result, we need the bytes from the object
      // so let's get the stream
      InputStream inStream = digitalObject.getContent().getInputStream();

      // Catch the special case of no data in the file
      if (this.addStreamBytesToDigest(messDigest,
          inStream,
          JavaDigest.DEFAULT_CHUNK_SIZE) < 1) {
        // log it, and create a new service report
        JavaDigest.log.severe(JavaDigest.NO_DATA_MESSAGE);
        retResult = this.createErrorResult(ServiceReport.Status.TOOL_ERROR, JavaDigest.NO_DATA_MESSAGE);

        // Return the result
        return retResult;
      }

      // OK, success so create the result
      retReport = new ServiceReport(ServiceReport.Type.INFO,
          ServiceReport.Status.SUCCESS,
          JavaDigest.SUCCESS_MESSAGE);

      // And wrap it in the result
      retResult = new FixityResult(JavaDigestUtils.getDefaultAlgorithmId().toString(),
                      messDigest.getProvider().getName(),
                     messDigest.digest(),
                     null,
                     retReport);

View Full Code Here


  private FixityResult createErrorResult(ServiceReport.Status status, String message) {
    ServiceReport retReport = new ServiceReport(ServiceReport.Type.ERROR,
                            status,
                          message);
    // And wrap it in the result
    return new FixityResult(retReport);
  }
View Full Code Here

        System.out.println("Recieved service description: " + desc.toXmlFormatted());
  }

  private void testDefaultDigest(TestFile testFile, Fixity fixity) {
    // Ok let's make the call to test
        FixityResult fixityResult = fixity.calculateChecksum(
                new DigitalObject.Builder(Content.byReference(new File(testFile
                        .getLocation()))).build(), null);
       
        // Check the result against an "independent" MD5 hash implementation
        try {
          // Use the apache codec MD5 algorithm
          File theFile = new File(testFile.getLocation());
          InputStream inStream = new FileInputStream(theFile);
      byte[] hash = DigestUtils.md5(inStream);
      inStream.close();

      // Assert that the hashes are equal
      assertTrue("Expecting Fast MD5 and Java MD5 byte hashes to be equal",
          Arrays.equals(hash, fixityResult.getDigestValue()));
     
      // Check the hex string value of the hash
      InputStream newStream = new FileInputStream(theFile);
      String hexhash = DigestUtils.md5Hex(newStream);
     
      // Assert that the string hashes are equal
      assertEquals("Expecting Fast MD5 and Java MD5 string hashes to be equal",
          hexhash,
          fixityResult.getHexDigestValue());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      fail("Failure reading TestFile " + testFile.getLocation());
    }
       
        this.checkResult(fixityResult);
       
        System.out.println("File " + testFile.toString() +
                   " gave digest " + fixityResult.getHexDigestValue());
  }
View Full Code Here

TOP

Related Classes of eu.planets_project.services.fixity.FixityResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.