From 824d5a0d369d6927eb9c48e654f0db353973825f Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Sun, 26 Dec 2010 12:42:44 +0000
Subject: [PATCH] javadocs

---
 core/java/src/net/i2p/data/DataHelper.java          | 11 +++++++++++
 core/java/src/net/i2p/data/Destination.java         |  5 ++++-
 core/java/src/net/i2p/data/Payload.java             |  4 ++++
 core/java/src/net/i2p/util/FortunaRandomSource.java |  4 +++-
 core/java/src/net/i2p/util/RandomSource.java        | 13 +++++++++----
 5 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/core/java/src/net/i2p/data/DataHelper.java b/core/java/src/net/i2p/data/DataHelper.java
index 60ba86f1ca..bd6bf260d9 100644
--- a/core/java/src/net/i2p/data/DataHelper.java
+++ b/core/java/src/net/i2p/data/DataHelper.java
@@ -914,9 +914,20 @@ public class DataHelper {
         return c;
     }
 
+    /**
+     *  This is different than InputStream.read(target), in that it
+     *  does repeated reads until the full data is received.
+     */
     public static int read(InputStream in, byte target[]) throws IOException {
         return read(in, target, 0, target.length);
     }
+
+    /**
+     *  This is different than InputStream.read(target, offset, length), in that it
+     *  returns the new offset (== old offset + bytes read).
+     *  It also does repeated reads until the full data is received.
+     *  @return the new offset (== old offset + bytes read)
+     */
     public static int read(InputStream in, byte target[], int offset, int length) throws IOException {
         int cur = offset;
         while (cur < length) {
diff --git a/core/java/src/net/i2p/data/Destination.java b/core/java/src/net/i2p/data/Destination.java
index 41478275b8..a8c176df6a 100644
--- a/core/java/src/net/i2p/data/Destination.java
+++ b/core/java/src/net/i2p/data/Destination.java
@@ -28,7 +28,10 @@ public class Destination extends KeysAndCert {
         fromBase64(s);
     }
 
-    /** deprecated, used only by Packet.java in streaming */
+    /**
+     *  deprecated, used only by Packet.java in streaming
+     *  @return the written length (NOT the new offset)    
+     */    
     public int writeBytes(byte target[], int offset) {
         int cur = offset;
         System.arraycopy(_publicKey.getData(), 0, target, cur, PublicKey.KEYSIZE_BYTES);
diff --git a/core/java/src/net/i2p/data/Payload.java b/core/java/src/net/i2p/data/Payload.java
index 0371ed73f0..bdaac7d4c5 100644
--- a/core/java/src/net/i2p/data/Payload.java
+++ b/core/java/src/net/i2p/data/Payload.java
@@ -93,6 +93,10 @@ public class Payload extends DataStructureImpl {
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("wrote payload: " + _encryptedData.length);
     }
+
+    /**
+     *  @return the written length (NOT the new offset)    
+     */    
     public int writeBytes(byte target[], int offset) {
         if (_encryptedData == null) throw new IllegalStateException("Not yet encrypted.  Please set the encrypted data");
         DataHelper.toLong(target, offset, 4, _encryptedData.length);
diff --git a/core/java/src/net/i2p/util/FortunaRandomSource.java b/core/java/src/net/i2p/util/FortunaRandomSource.java
index 8f499935b9..9061d3a570 100644
--- a/core/java/src/net/i2p/util/FortunaRandomSource.java
+++ b/core/java/src/net/i2p/util/FortunaRandomSource.java
@@ -23,7 +23,7 @@ import net.i2p.crypto.EntropyHarvester;
  *
  */
 public class FortunaRandomSource extends RandomSource implements EntropyHarvester {
-    private AsyncFortunaStandalone _fortuna;
+    private final AsyncFortunaStandalone _fortuna;
     private double _nextGaussian;
     private boolean _haveNextGaussian;
 
@@ -210,6 +210,7 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
         _fortuna.addRandomBytes(data, offset, len);
     }
     
+/*****
     public static void main(String args[]) {
         try {
             RandomSource rand = I2PAppContext.getGlobalContext().random();
@@ -231,4 +232,5 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
             System.out.println("Compressed size of 1MB: " + compressed.length);
         } catch (Exception e) { e.printStackTrace(); }
     }
+*****/
 }
diff --git a/core/java/src/net/i2p/util/RandomSource.java b/core/java/src/net/i2p/util/RandomSource.java
index c37c581dcb..c7c87239c9 100644
--- a/core/java/src/net/i2p/util/RandomSource.java
+++ b/core/java/src/net/i2p/util/RandomSource.java
@@ -25,18 +25,23 @@ import net.i2p.data.Base64;
  * @author jrandom
  */
 public class RandomSource extends SecureRandom implements EntropyHarvester {
-    private Log _log;
-    private EntropyHarvester _entropyHarvester;
-    protected I2PAppContext _context;
+    private final EntropyHarvester _entropyHarvester;
+    protected final I2PAppContext _context;
 
     public RandomSource(I2PAppContext context) {
         super();
         _context = context;
-        _log = context.logManager().getLog(RandomSource.class);
         // when we replace to have hooks for fortuna (etc), replace with
         // a factory (or just a factory method)
         _entropyHarvester = this;
     }
+
+    /**
+     * Singleton for whatever PRNG i2p uses.  
+     * Same as I2PAppContext.getGlobalContext().random();
+     * use context.random() if you have a context already.
+     * @return I2PAppContext.getGlobalContext().random()
+     */
     public static RandomSource getInstance() {
         return I2PAppContext.getGlobalContext().random();
     }
-- 
GitLab