487 * instance we actually use. It opens the entropy gathering device 488 * which will supply the randomness. 489 */ 490 491 URLSeedGenerator(String egdurl) throws IOException { 492 if (egdurl == null) { 493 throw new IOException("No random source specified"); 494 } 495 deviceName = egdurl; 496 init(); 497 } 498 499 private void init() throws IOException { 500 final URL device = new URL(deviceName); 501 try { 502 seedStream = java.security.AccessController.doPrivileged 503 (new java.security.PrivilegedExceptionAction<InputStream>() { 504 @Override 505 public InputStream run() throws IOException { 506 /* 507 * return a FileInputStream for file URLs and 508 * avoid buffering. The openStream() call wraps 509 * InputStream in a BufferedInputStream which 510 * can buffer up to 8K bytes. This read is a 511 * performance issue for entropy sources which 512 * can be slow to replenish. 513 */ 514 if (device.getProtocol().equalsIgnoreCase("file")) { 515 File deviceFile = 516 SunEntries.getDeviceFile(device); 517 return new FileInputStream(deviceFile); 518 } else { 519 return device.openStream(); 520 } 521 } 522 }); 523 } catch (Exception e) { 524 throw new IOException( 525 "Failed to open " + deviceName, e.getCause()); 526 } 527 } 528 529 @Override 530 void getSeedBytes(byte[] result) { 531 int len = result.length; 532 int read = 0; 533 try { 534 while (read < len) { 535 int count = seedStream.read(result, read, len - read); 536 // /dev/random blocks - should never have EOF 537 if (count < 0) { | 487 * instance we actually use. It opens the entropy gathering device 488 * which will supply the randomness. 489 */ 490 491 URLSeedGenerator(String egdurl) throws IOException { 492 if (egdurl == null) { 493 throw new IOException("No random source specified"); 494 } 495 deviceName = egdurl; 496 init(); 497 } 498 499 private void init() throws IOException { 500 final URL device = new URL(deviceName); 501 try { 502 seedStream = java.security.AccessController.doPrivileged 503 (new java.security.PrivilegedExceptionAction<InputStream>() { 504 @Override 505 public InputStream run() throws IOException { 506 /* 507 * return a shared InputStream from FileInputStreamPool 508 * for file URLs and avoid buffering. 509 * The URL.openStream() call wraps 510 * InputStream in a BufferedInputStream which 511 * can buffer up to 8K bytes. This read is a 512 * performance issue for entropy sources which 513 * can be slow to replenish. 514 */ 515 if (device.getProtocol().equalsIgnoreCase("file")) { 516 File deviceFile = 517 SunEntries.getDeviceFile(device); 518 return FileInputStreamPool.getInputStream(deviceFile); 519 } else { 520 return device.openStream(); 521 } 522 } 523 }); 524 } catch (Exception e) { 525 throw new IOException( 526 "Failed to open " + deviceName, e.getCause()); 527 } 528 } 529 530 @Override 531 void getSeedBytes(byte[] result) { 532 int len = result.length; 533 int read = 0; 534 try { 535 while (read < len) { 536 int count = seedStream.read(result, read, len - read); 537 // /dev/random blocks - should never have EOF 538 if (count < 0) { |