Project

General

Profile

« Previous | Next » 

Revision 6228

Implement MNRead.getChecksum() in MNodeService.

View differences:

MNodeService.java
23 23

  
24 24
package edu.ucsb.nceas.metacat.dataone;
25 25

  
26
import java.io.IOException;
26 27
import java.io.InputStream;
28
import java.security.NoSuchAlgorithmException;
27 29
import java.util.Date;
28 30

  
29 31
import org.apache.log4j.Logger;
......
45 47
import org.dataone.service.mn.tier4.MNReplication;
46 48
import org.dataone.service.types.AccessPolicy;
47 49
import org.dataone.service.types.Checksum;
50
import org.dataone.service.types.ChecksumAlgorithm;
48 51
import org.dataone.service.types.DescribeResponse;
49 52
import org.dataone.service.types.Event;
50 53
import org.dataone.service.types.Identifier;
......
58 61
import org.dataone.service.types.Session;
59 62
import org.dataone.service.types.Subject;
60 63
import org.dataone.service.types.SystemMetadata;
64
import org.dataone.service.types.util.ServiceTypeUtil;
61 65

  
62 66
/**
63 67
 * Represents Metacat's implementation of the DataONE Member Node 
......
272 276
	 * @param algorithm -  the name of an algorithm that will be used to compute 
273 277
	 *                     a checksum of the bytes of the object
274 278
	 * 
275
	 * @return inputStream - the input stream of the given object
279
	 * @return checksum - the checksum of the given object
276 280
	 * 
277 281
	 * @throws InvalidToken
278 282
	 * @throws ServiceFailure
......
286 290
	  throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
287 291
	  InvalidRequest, NotImplemented {
288 292

  
289
		return null;
293
  	Checksum checksum = null;
294
  	
295
  	InputStream inputStream = get(session, pid);
296
  	
297
  	try {
298
	    checksum = 
299
	    	ServiceTypeUtil.checksum(inputStream, ChecksumAlgorithm.convert(algorithm));
300
    
301
  	} catch (NoSuchAlgorithmException e) {
302
      throw new ServiceFailure("1410", "The checksum for the object specified by " + 
303
        pid.getValue() +
304
        "could not be returned due to an internal error: " +
305
        e.getMessage());
306
      
307
    } catch (IOException e) {
308
      throw new ServiceFailure("1410", "The checksum for the object specified by " + 
309
        pid.getValue() +
310
        "could not be returned due to an internal error: " +
311
        e.getMessage());
312
      
313
    }
314
  	
315
    if ( checksum == null ) {
316
      throw new ServiceFailure("1410", "The checksum for the object specified by " + 
317
        pid.getValue() +
318
        "could not be returned.");
319
      
320
    }
321
    
322
		return checksum;
290 323
	}
291 324

  
292 325
	/**

Also available in: Unified diff