Browse Source

DEC-16125 fix: resin和weblogic下存在joda时区加载不到的问题

release/10.0
Afly 4 years ago
parent
commit
dff97cfdc2
  1. 36
      fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java
  2. 35
      fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java

36
fine-joda/src/main/java/com/fr/third/joda/time/tz/ZoneInfoProvider.java

@ -15,6 +15,7 @@
*/ */
package com.fr.third.joda.time.tz; package com.fr.third.joda.time.tz;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -24,6 +25,7 @@ import java.lang.ref.SoftReference;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -52,6 +54,8 @@ public class ZoneInfoProvider implements Provider {
private final Map<String, Object> iZoneInfoMap; private final Map<String, Object> iZoneInfoMap;
/** Maps ids to strings or SoftReferences to DateTimeZones. */ /** Maps ids to strings or SoftReferences to DateTimeZones. */
private final Set<String> iZoneInfoKeys; private final Set<String> iZoneInfoKeys;
/** 内置可能加载不到的带加号的资源文件. */
private static Map<String, byte[]> GMTData = new HashMap();
/** /**
* Search the default classloader resource path for compiled data files. * Search the default classloader resource path for compiled data files.
@ -217,12 +221,18 @@ public class ZoneInfoProvider implements Provider {
} }
}); });
if (in == null) { if (in == null) {
StringBuilder buf = new StringBuilder(40) if (name.contains("+")) {
.append("Resource not found: \"") name = name.substring(name.indexOf("/") + 1);
.append(path) byte[] data = GMTData.get(name);
.append("\" ClassLoader: ") return new ByteArrayInputStream(data);
.append(iLoader != null ? iLoader.toString() : "system"); } else {
throw new IOException(buf.toString()); StringBuilder buf = new StringBuilder(40)
.append("Resource not found: \"")
.append(path)
.append("\" ClassLoader: ")
.append(iLoader != null ? iLoader.toString() : "system");
throw new IOException(buf.toString());
}
} }
} }
return in; return in;
@ -302,4 +312,18 @@ public class ZoneInfoProvider implements Provider {
} }
} }
static {
GMTData.put("GMT+1", new byte[]{70, 0, 3, 45, 48, 49, 62, 62});
GMTData.put("GMT+2", new byte[]{70, 0, 3, 45, 48, 50, 60, 60});
GMTData.put("GMT+3", new byte[]{70, 0, 3, 45, 48, 51, 58, 58});
GMTData.put("GMT+4", new byte[]{70, 0, 3, 45, 48, 52, 56, 56});
GMTData.put("GMT+5", new byte[]{70, 0, 3, 45, 48, 53, 54, 54});
GMTData.put("GMT+6", new byte[]{70, 0, 3, 45, 48, 54, 52, 52});
GMTData.put("GMT+7", new byte[]{70, 0, 3, 45, 48, 55, 50, 50});
GMTData.put("GMT+8", new byte[]{70, 0, 3, 45, 48, 56, 48, 48});
GMTData.put("GMT+9", new byte[]{70, 0, 3, 45, 48, 57, 46, 46});
GMTData.put("GMT+10", new byte[]{70, 0, 3, 45, 49, 48, 44, 44});
GMTData.put("GMT+11", new byte[]{70, 0, 3, 45, 49, 49, 42, 42});
}
} }

35
fine-joda/src/test/java/com/fr/third/joda/time/tz/ZoneInfoProviderTest.java

@ -0,0 +1,35 @@
package com.fr.third.joda.time.tz;
import org.junit.Test;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import static org.junit.Assert.*;
/**
* @author Afly
* created on 2020-12-16
*/
public class ZoneInfoProviderTest {
@Test
public void testGetResource() throws IOException, NoSuchMethodException {
ZoneInfoProvider zoneInfoProvider = new ZoneInfoProvider();
assertNotNull(zoneInfoProvider.getZone("Etc/GMT+8"));
Method openResource = zoneInfoProvider.getClass().getDeclaredMethod("openResource", String.class);
openResource.setAccessible(true);
try {
openResource.invoke(zoneInfoProvider, "Etc/Exception+8");
fail();
} catch (Exception ignored) {
}
try {
openResource.invoke(zoneInfoProvider, "Etc/Exception-8");
fail();
} catch (Exception ignored) {
}
}
}
Loading…
Cancel
Save