Revision 6323
Added by ben leinfelder over 13 years ago
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
427 | 427 |
allowed = isAuthorized(session, pid, Permission.READ); |
428 | 428 |
|
429 | 429 |
// if the person is authorized, perform the read |
430 |
if ( allowed ) { |
|
431 |
|
|
432 |
// get the object bytes |
|
433 |
// TODO: stream to file to stream conversion throughout Metacat needs to |
|
434 |
// be resolved |
|
435 |
File tmpDir; |
|
436 |
try |
|
437 |
{ |
|
438 |
tmpDir = new File(PropertyService.getProperty("application.tempDir")); |
|
439 |
} |
|
440 |
catch(PropertyNotFoundException pnfe) |
|
441 |
{ |
|
442 |
logMetacat.error("D1NodeService.get(): " + |
|
443 |
"application.tmpDir not found. Using /tmp instead."); |
|
444 |
tmpDir = new File("/tmp"); |
|
445 |
} |
|
446 |
|
|
447 |
Date d = new Date(); |
|
448 |
final File outputFile = new File(tmpDir, "metacat.output." + d.getTime()); |
|
449 |
FileOutputStream dataSink; |
|
430 |
if (allowed) { |
|
450 | 431 |
try { |
451 |
dataSink = new FileOutputStream(outputFile); |
|
452 |
handler.read(localId); |
|
453 |
|
|
454 |
} catch (FileNotFoundException e) { |
|
432 |
inputStream = handler.read(localId); |
|
433 |
} catch (Exception e) { |
|
455 | 434 |
throw new ServiceFailure("1020", "The object specified by " + |
456 | 435 |
pid.getValue() + |
457 |
"could not be returned due to a file read error: " +
|
|
436 |
"could not be returned due to error: " + |
|
458 | 437 |
e.getMessage()); |
459 |
|
|
460 |
} catch (PropertyNotFoundException e) { |
|
461 |
throw new ServiceFailure("1020", "The object specified by " + |
|
462 |
pid.getValue() + |
|
463 |
"could not be returned due to an internal error: " + |
|
464 |
e.getMessage()); |
|
465 |
|
|
466 |
} catch (ClassNotFoundException e) { |
|
467 |
throw new ServiceFailure("1020", "The object specified by " + |
|
468 |
pid.getValue() + |
|
469 |
"could not be returned due to an internal error: " + |
|
470 |
e.getMessage()); |
|
471 |
|
|
472 |
} catch (IOException e) { |
|
473 |
throw new ServiceFailure("1020", "The object specified by " + |
|
474 |
pid.getValue() + |
|
475 |
"could not be returned due to a file read error: " + |
|
476 |
e.getMessage()); |
|
477 |
|
|
478 |
} catch (SQLException e) { |
|
479 |
throw new ServiceFailure("1020", "The object specified by " + |
|
480 |
pid.getValue() + |
|
481 |
"could not be returned due to a database error: " + |
|
482 |
e.getMessage()); |
|
483 |
|
|
484 |
} catch (McdbException e) { |
|
485 |
throw new ServiceFailure("1020", "The object specified by " + |
|
486 |
pid.getValue() + |
|
487 |
"could not be returned due to database error: " + |
|
488 |
e.getMessage()); |
|
489 |
|
|
490 |
} catch (ParseLSIDException e) { |
|
491 |
throw new ServiceFailure("1020", "The object specified by " + |
|
492 |
pid.getValue() + |
|
493 |
"could not be returned due to a parse error: " + |
|
494 |
e.getMessage()); |
|
495 |
|
|
496 | 438 |
} |
497 |
|
|
498 |
//set a timer to clean up the temp files |
|
499 |
Timer t = new Timer(); |
|
500 |
TimerTask tt = new TimerTask() { |
|
501 |
@Override |
|
502 |
public void run() |
|
503 |
{ |
|
504 |
outputFile.delete(); |
|
505 |
} |
|
506 |
}; |
|
507 |
t.schedule(tt, 20000); //schedule after 20 secs |
|
508 |
|
|
509 |
try { |
|
510 |
inputStream = new FileInputStream(outputFile); |
|
511 |
} catch (FileNotFoundException e) { |
|
512 |
throw new ServiceFailure("1020", "The object specified by " + |
|
513 |
pid.getValue() + |
|
514 |
"could not be returned due to a file read error: " + |
|
515 |
e.getMessage()); |
|
516 |
|
|
517 |
} |
|
518 |
|
|
519 | 439 |
} |
520 | 440 |
|
521 | 441 |
// if we fail to set the input stream |
Also available in: Unified diff
simplify the get() method -- no need to use temp files for this operation