From ea22c73a73fa6a9f1a5a50d784c14eecafc214fa Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Thu, 20 Oct 2005 08:56:39 +0000
Subject: [PATCH] 2005-10-20  jrandom     * Workaround a bug in GCJ's Calendar
 implementation     * Propery throw an exception in the streaming lib if we
 try to write to a       closed stream.  This will hopefully help clear some
 I2Phex bugs (thanks       GregorK!)

---
 .../src/net/i2p/client/streaming/MessageOutputStream.java | 1 +
 core/java/src/net/i2p/data/RoutingKeyGenerator.java       | 8 ++++++--
 history.txt                                               | 8 +++++++-
 router/java/src/net/i2p/router/Router.java                | 4 +++-
 router/java/src/net/i2p/router/RouterVersion.java         | 4 ++--
 5 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java
index 9e8a47b736..64a7bb6cc2 100644
--- a/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java
+++ b/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java
@@ -77,6 +77,7 @@ public class MessageOutputStream extends OutputStream {
     }
     
     public void write(byte b[], int off, int len) throws IOException {
+        if (_closed) throw new IOException("Already closed");
         if (_log.shouldLog(Log.DEBUG))
             _log.debug("write(b[], " + off + ", " + len + ") ");
         int cur = off;
diff --git a/core/java/src/net/i2p/data/RoutingKeyGenerator.java b/core/java/src/net/i2p/data/RoutingKeyGenerator.java
index 76cdacfb06..5589d589e1 100644
--- a/core/java/src/net/i2p/data/RoutingKeyGenerator.java
+++ b/core/java/src/net/i2p/data/RoutingKeyGenerator.java
@@ -71,14 +71,18 @@ public class RoutingKeyGenerator {
      */
     public void generateDateBasedModData() {
         Date today = null;
+        long now = _context.clock().now();
         synchronized (_cal) {
-            _cal.setTime(new Date(_context.clock().now()));
+            _cal.setTime(new Date(now));
+            _cal.set(Calendar.YEAR, _cal.get(Calendar.YEAR));               // gcj <= 4.0 workaround
+            _cal.set(Calendar.DAY_OF_YEAR, _cal.get(Calendar.DAY_OF_YEAR)); // gcj <= 4.0 workaround
             _cal.set(Calendar.HOUR_OF_DAY, 0);
             _cal.set(Calendar.MINUTE, 0);
             _cal.set(Calendar.SECOND, 0);
             _cal.set(Calendar.MILLISECOND, 0);
             today = _cal.getTime();
         }
+        
         byte mod[] = null;
         String modVal = null;
         synchronized (_fmt) {
@@ -91,7 +95,7 @@ public class RoutingKeyGenerator {
             _log.info("Routing modifier generated: " + modVal);
         setModData(mod);
     }
-
+    
     /**
      * Generate a modified (yet consistent) hash from the origKey by generating the
      * SHA256 of the targetKey with the current modData appended to it, *then* 
diff --git a/history.txt b/history.txt
index e5bbf8ae1d..16c9bbb0d4 100644
--- a/history.txt
+++ b/history.txt
@@ -1,4 +1,10 @@
-$Id: history.txt,v 1.301 2005/10/19 00:15:15 jrandom Exp $
+$Id: history.txt,v 1.302 2005/10/19 17:38:46 jrandom Exp $
+
+2005-10-20  jrandom
+    * Workaround a bug in GCJ's Calendar implementation
+    * Propery throw an exception in the streaming lib if we try to write to a
+      closed stream.  This will hopefully help clear some I2Phex bugs (thanks
+      GregorK!)
 
 2005-10-19  jrandom
     * Ported the snark bittorrent client to I2P such that it is compatible
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 1702f89b83..ece9cc54f2 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -460,6 +460,8 @@ public class Router {
         private long getTimeTillMidnight() {
             long now = Router.this._context.clock().now();
             _cal.setTime(new Date(now));
+            _cal.set(Calendar.YEAR, _cal.get(Calendar.YEAR));               // gcj <= 4.0 workaround
+            _cal.set(Calendar.DAY_OF_YEAR, _cal.get(Calendar.DAY_OF_YEAR)); // gcj <= 4.0 workaround
             _cal.add(Calendar.DATE, 1);
             _cal.set(Calendar.HOUR_OF_DAY, 0);
             _cal.set(Calendar.MINUTE, 0);
@@ -468,7 +470,7 @@ public class Router {
             long then = _cal.getTime().getTime();
             long howLong = then - now;
             if (howLong < 0) // hi kaffe
-                howLong = 24*60*60*1000 + howLong;
+                howLong = 24*60*60*1000l + howLong;
             if (_log.shouldLog(Log.DEBUG))
                 _log.debug("Time till midnight: " + howLong + "ms");
             return howLong;
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index 19ad9dc712..32215ee5dc 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
  *
  */
 public class RouterVersion {
-    public final static String ID = "$Revision: 1.272 $ $Date: 2005/10/19 00:15:15 $";
+    public final static String ID = "$Revision: 1.273 $ $Date: 2005/10/19 17:38:45 $";
     public final static String VERSION = "0.6.1.3";
-    public final static long BUILD = 3;
+    public final static long BUILD = 4;
     public static void main(String args[]) {
         System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
         System.out.println("Router ID: " + RouterVersion.ID);
-- 
GitLab