其他分享
首页 > 其他分享> > ZoneInfoFile

ZoneInfoFile

作者:互联网

ZoneInfoFile

 

package sun.util.calendar;

import java.io.ByteArrayInputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.StreamCorruptedException;
import java.security.AccessController;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import sun.security.action.GetPropertyAction;
import sun.util.calendar.ZoneInfo;
import sun.util.calendar.ZoneInfoFile.1;
import sun.util.calendar.ZoneInfoFile.Checksum;
import sun.util.calendar.ZoneInfoFile.ZoneOffsetTransitionRule;

public final class ZoneInfoFile {
	private static String versionId;
	private static final Map<String, ZoneInfo> zones = new ConcurrentHashMap();
	private static Map<String, String> aliases = new HashMap();
	private static byte[][] ruleArray;
	private static String[] regions;
	private static int[] indices;
	private static final boolean USE_OLDMAPPING;
	private static String[][] oldMappings = new String[][]{{"ACT", "Australia/Darwin"}, {"AET", "Australia/Sydney"},
			{"AGT", "America/Argentina/Buenos_Aires"}, {"ART", "Africa/Cairo"}, {"AST", "America/Anchorage"},
			{"BET", "America/Sao_Paulo"}, {"BST", "Asia/Dhaka"}, {"CAT", "Africa/Harare"}, {"CNT", "America/St_Johns"},
			{"CST", "America/Chicago"}, {"CTT", "Asia/Shanghai"}, {"EAT", "Africa/Addis_Ababa"},
			{"ECT", "Europe/Paris"}, {"IET", "America/Indiana/Indianapolis"}, {"IST", "Asia/Kolkata"},
			{"JST", "Asia/Tokyo"}, {"MIT", "Pacific/Apia"}, {"NET", "Asia/Yerevan"}, {"NST", "Pacific/Auckland"},
			{"PLT", "Asia/Karachi"}, {"PNT", "America/Phoenix"}, {"PRT", "America/Puerto_Rico"},
			{"PST", "America/Los_Angeles"}, {"SST", "Pacific/Guadalcanal"}, {"VST", "Asia/Ho_Chi_Minh"}};
	private static final long UTC1900 = -2208988800L;
	private static final long UTC2037 = 2145916799L;
	private static final long LDT2037 = 2114380800L;
	private static final long CURRT;
	static final int SECONDS_PER_DAY = 86400;
	static final int DAYS_PER_CYCLE = 146097;
	static final long DAYS_0000_TO_1970 = 719528L;
	private static final int[] toCalendarDOW;
	private static final int[] toSTZTime;
	private static final long OFFSET_MASK = 15L;
	private static final long DST_MASK = 240L;
	private static final int DST_NSHIFT = 4;
	private static final int TRANSITION_NSHIFT = 12;
	private static final int LASTYEAR = 2037;

	public static String[] getZoneIds() {
		int arg = regions.length + oldMappings.length;
		if (!USE_OLDMAPPING) {
			arg += 3;
		}

		String[] arg0 = (String[]) Arrays.copyOf(regions, arg);
		int arg1 = regions.length;
		if (!USE_OLDMAPPING) {
			arg0[arg1++] = "EST";
			arg0[arg1++] = "HST";
			arg0[arg1++] = "MST";
		}

		for (int arg2 = 0; arg2 < oldMappings.length; ++arg2) {
			arg0[arg1++] = oldMappings[arg2][0];
		}

		return arg0;
	}

	public static String[] getZoneIds(int arg) {
		ArrayList arg0 = new ArrayList();
		String[] arg1 = getZoneIds();
		int arg2 = arg1.length;

		for (int arg3 = 0; arg3 < arg2; ++arg3) {
			String arg4 = arg1[arg3];
			ZoneInfo arg5 = getZoneInfo(arg4);
			if (arg5.getRawOffset() == arg) {
				arg0.add(arg4);
			}
		}

		arg1 = (String[]) arg0.toArray(new String[arg0.size()]);
		Arrays.sort(arg1);
		return arg1;
	}

	public static ZoneInfo getZoneInfo(String arg) {
		if (arg == null) {
			return null;
		} else {
			ZoneInfo arg0 = getZoneInfo0(arg);
			if (arg0 != null) {
				arg0 = (ZoneInfo) arg0.clone();
				arg0.setID(arg);
			}

			return arg0;
		}
	}

	private static ZoneInfo getZoneInfo0(String arg) {
		try {
			ZoneInfo arg0 = (ZoneInfo) zones.get(arg);
			if (arg0 != null) {
				return arg0;
			} else {
				String arg1 = arg;
				if (aliases.containsKey(arg)) {
					arg1 = (String) aliases.get(arg);
				}

				int arg2 = Arrays.binarySearch(regions, arg1);
				if (arg2 < 0) {
					return null;
				} else {
					byte[] arg3 = ruleArray[indices[arg2]];
					DataInputStream arg4 = new DataInputStream(new ByteArrayInputStream(arg3));
					arg0 = getZoneInfo(arg4, arg1);
					zones.put(arg, arg0);
					return arg0;
				}
			}
		} catch (Exception arg5) {
			throw new RuntimeException("Invalid binary time-zone data: TZDB:" + arg + ", version: " + versionId, arg5);
		}
	}

	public static Map<String, String> getAliasMap() {
		return Collections.unmodifiableMap(aliases);
	}

	public static String getVersion() {
		return versionId;
	}

	public static ZoneInfo getCustomTimeZone(String arg, int arg0) {
		String arg1 = toCustomID(arg0);
		return new ZoneInfo(arg1, arg0);
	}

	public static String toCustomID(int arg) {
		int arg1 = arg / '';
		char arg0;
		if (arg1 >= 0) {
			arg0 = 43;
		} else {
			arg0 = 45;
			arg1 = -arg1;
		}

		int arg2 = arg1 / 60;
		int arg3 = arg1 % 60;
		char[] arg4 = new char[]{'G', 'M', 'T', arg0, '0', '0', ':', '0', '0'};
		if (arg2 >= 10) {
			arg4[4] = (char) (arg4[4] + arg2 / 10);
		}

		arg4[5] = (char) (arg4[5] + arg2 % 10);
		if (arg3 != 0) {
			arg4[7] = (char) (arg4[7] + arg3 / 10);
			arg4[8] = (char) (arg4[8] + arg3 % 10);
		}

		return new String(arg4);
	}

	private static void addOldMapping() {
		String[][] arg = oldMappings;
		int arg0 = arg.length;

		for (int arg1 = 0; arg1 < arg0; ++arg1) {
			String[] arg2 = arg[arg1];
			aliases.put(arg2[0], arg2[1]);
		}

		if (USE_OLDMAPPING) {
			aliases.put("EST", "America/New_York");
			aliases.put("MST", "America/Denver");
			aliases.put("HST", "Pacific/Honolulu");
		} else {
			zones.put("EST", new ZoneInfo("EST", -18000000));
			zones.put("MST", new ZoneInfo("MST", -25200000));
			zones.put("HST", new ZoneInfo("HST", -36000000));
		}

	}

	public static boolean useOldMapping() {
		return USE_OLDMAPPING;
	}

	private static void load(DataInputStream arg) throws ClassNotFoundException, IOException {
		if (arg.readByte() != 1) {
			throw new StreamCorruptedException("File format not recognised");
		} else {
			String arg0 = arg.readUTF();
			if (!"TZDB".equals(arg0)) {
				throw new StreamCorruptedException("File format not recognised");
			} else {
				short arg1 = arg.readShort();

				for (int arg2 = 0; arg2 < arg1; ++arg2) {
					versionId = arg.readUTF();
				}

				short arg10 = arg.readShort();
				String[] arg3 = new String[arg10];

				for (int arg4 = 0; arg4 < arg10; ++arg4) {
					arg3[arg4] = arg.readUTF();
				}

				short arg11 = arg.readShort();
				ruleArray = new byte[arg11][];

				int arg5;
				for (arg5 = 0; arg5 < arg11; ++arg5) {
					byte[] arg6 = new byte[arg.readShort()];
					arg.readFully(arg6);
					ruleArray[arg5] = arg6;
				}

				for (arg5 = 0; arg5 < arg1; ++arg5) {
					arg10 = arg.readShort();
					regions = new String[arg10];
					indices = new int[arg10];

					for (int arg12 = 0; arg12 < arg10; ++arg12) {
						regions[arg12] = arg3[arg.readShort()];
						indices[arg12] = arg.readShort();
					}
				}

				zones.remove("ROC");

				for (arg5 = 0; arg5 < arg1; ++arg5) {
					short arg13 = arg.readShort();
					aliases.clear();

					for (int arg7 = 0; arg7 < arg13; ++arg7) {
						String arg8 = arg3[arg.readShort()];
						String arg9 = arg3[arg.readShort()];
						aliases.put(arg8, arg9);
					}
				}

				addOldMapping();
			}
		}
	}

	public static ZoneInfo getZoneInfo(DataInput arg, String arg0) throws Exception {
		byte arg1 = arg.readByte();
		int arg2 = arg.readInt();
		long[] arg3 = new long[arg2];

		for (int arg4 = 0; arg4 < arg2; ++arg4) {
			arg3[arg4] = readEpochSec(arg);
		}

		int[] arg11 = new int[arg2 + 1];

		int arg5;
		for (arg5 = 0; arg5 < arg11.length; ++arg5) {
			arg11[arg5] = readOffset(arg);
		}

		arg5 = arg.readInt();
		long[] arg6 = new long[arg5];

		for (int arg7 = 0; arg7 < arg5; ++arg7) {
			arg6[arg7] = readEpochSec(arg);
		}

		int[] arg12 = new int[arg5 + 1];

		for (int arg8 = 0; arg8 < arg12.length; ++arg8) {
			arg12[arg8] = readOffset(arg);
		}

		byte arg13 = arg.readByte();
		ZoneOffsetTransitionRule[] arg9 = new ZoneOffsetTransitionRule[arg13];

		for (int arg10 = 0; arg10 < arg13; ++arg10) {
			arg9[arg10] = new ZoneOffsetTransitionRule(arg);
		}

		return getZoneInfo(arg0, arg3, arg11, arg6, arg12, arg9);
	}

	public static int readOffset(DataInput arg) throws IOException {
		byte arg0 = arg.readByte();
		return arg0 == 127 ? arg.readInt() : arg0 * 900;
	}

	static long readEpochSec(DataInput arg) throws IOException {
		int arg0 = arg.readByte() & 255;
		if (arg0 == 255) {
			return arg.readLong();
		} else {
			int arg1 = arg.readByte() & 255;
			int arg2 = arg.readByte() & 255;
			long arg3 = (long) ((arg0 << 16) + (arg1 << 8) + arg2);
			return arg3 * 900L - 4575744000L;
		}
	}

	private static ZoneInfo getZoneInfo(String arg, long[] arg0, int[] arg1, long[] arg2, int[] arg3, ZoneOffsetTransitionRule[] arg4) {
      boolean arg5 = false;
      int arg6 = 0;
      int arg7 = 0;
      int[] arg8 = null;
      boolean arg9 = false;
      int arg31;
      if(arg0.length > 0) {
         arg31 = arg1[arg1.length - 1] * 1000;
         arg9 = arg0[arg0.length - 1] > CURRT;
      } else {
         arg31 = arg1[0] * 1000;
      }

      long[] arg10 = null;
      int[] arg11 = null;
      int arg12 = 0;
      int arg13 = 0;
      if(arg2.length != 0) {
         arg10 = new long[250];
         arg11 = new int[100];
         int arg14 = getYear(arg2[arg2.length - 1], arg3[arg2.length - 1]);
         int arg15 = 0;

         int arg16;
         for(arg16 = 1; arg15 < arg2.length && arg2[arg15] < -2208988800L; ++arg15) {
            ;
         }

         if(arg15 < arg2.length) {
            if(arg15 < arg2.length) {
               arg11[0] = arg1[arg1.length - 1] * 1000;
               arg12 = 1;
            }

            arg12 = addTrans(arg10, arg13++, arg11, arg12, -2208988800L, arg3[arg15], getStandardOffset(arg0, arg1, -2208988800L));
         }

         long arg17;
         while(arg15 < arg2.length) {
            arg17 = arg2[arg15];
            if(arg17 > 2145916799L) {
               arg14 = 2037;
               break;
            }

            for(; arg16 < arg0.length; ++arg16) {
               long arg19 = arg0[arg16];
               if(arg19 >= -2208988800L) {
                  if(arg19 > arg17) {
                     break;
                  }

                  if(arg19 < arg17) {
                     if(arg12 + 2 >= arg11.length) {
                        arg11 = Arrays.copyOf(arg11, arg11.length + 100);
                     }

                     if(arg13 + 1 >= arg10.length) {
                        arg10 = Arrays.copyOf(arg10, arg10.length + 100);
                     }

                     arg12 = addTrans(arg10, arg13++, arg11, arg12, arg19, arg3[arg15], arg1[arg16 + 1]);
                  }
               }
            }

            if(arg12 + 2 >= arg11.length) {
               arg11 = Arrays.copyOf(arg11, arg11.length + 100);
            }

            if(arg13 + 1 >= arg10.length) {
               arg10 = Arrays.copyOf(arg10, arg10.length + 100);
            }

            arg12 = addTrans(arg10, arg13++, arg11, arg12, arg17, arg3[arg15 + 1], getStandardOffset(arg0, arg1, arg17));
            ++arg15;
         }

         int arg20;
         int arg35;
         for(; arg16 < arg0.length; ++arg16) {
            arg17 = arg0[arg16];
            if(arg17 >= -2208988800L) {
               arg35 = arg3[arg15];
               arg20 = indexOf(arg11, 0, arg12, arg35);
               if(arg20 == arg12) {
                  ++arg12;
               }

               arg10[arg13++] = arg17 * 1000L << 12 | (long)arg20 & 15L;
            }
         }

         long arg37;
         if(arg4.length <= 1) {
            if(arg13 > 0) {
               if(arg14 < 2037) {
                  arg17 = 2114380800L - (long)(arg31 / 1000);
                  arg35 = indexOf(arg11, 0, arg12, arg31 / 1000);
                  if(arg35 == arg12) {
                     ++arg12;
                  }

                  arg10[arg13++] = arg17 * 1000L << 12 | (long)arg35 & 15L;
               } else if(arg2.length > 2) {
                  int arg36 = arg2.length;
                  arg37 = arg2[arg36 - 2];
                  arg20 = arg3[arg36 - 2 + 1];
                  int arg42 = getStandardOffset(arg0, arg1, arg37);
                  long arg22 = arg2[arg36 - 1];
                  int arg24 = arg3[arg36 - 1 + 1];
                  int arg25 = getStandardOffset(arg0, arg1, arg22);
                  if(arg20 > arg42 && arg24 == arg25) {
                     arg36 = arg2.length - 2;
                     ZoneOffset arg26 = ZoneOffset.ofTotalSeconds(arg3[arg36]);
                     ZoneOffset arg27 = ZoneOffset.ofTotalSeconds(arg3[arg36 + 1]);
                     LocalDateTime arg28 = LocalDateTime.ofEpochSecond(arg2[arg36], 0, arg26);
                     LocalDateTime arg29;
                     if(arg27.getTotalSeconds() > arg26.getTotalSeconds()) {
                        arg29 = arg28;
                     } else {
                        arg29 = arg28.plusSeconds((long)(arg3[arg36 + 1] - arg3[arg36]));
                     }

                     arg36 = arg2.length - 1;
                     arg26 = ZoneOffset.ofTotalSeconds(arg3[arg36]);
                     arg27 = ZoneOffset.ofTotalSeconds(arg3[arg36 + 1]);
                     arg28 = LocalDateTime.ofEpochSecond(arg2[arg36], 0, arg26);
                     LocalDateTime arg30;
                     if(arg27.getTotalSeconds() > arg26.getTotalSeconds()) {
                        arg30 = arg28.plusSeconds((long)(arg3[arg36 + 1] - arg3[arg36]));
                     } else {
                        arg30 = arg28;
                     }

                     arg8 = new int[]{arg29.getMonthValue() - 1, arg29.getDayOfMonth(), 0, arg29.toLocalTime().toSecondOfDay() * 1000, 0, arg30.getMonthValue() - 1, arg30.getDayOfMonth(), 0, arg30.toLocalTime().toSecondOfDay() * 1000, 0};
                     arg6 = (arg20 - arg42) * 1000;
                  }
               }
            }
         } else {
            while(true) {
               if(arg14++ >= 2037) {
                  ZoneOffsetTransitionRule arg33 = arg4[arg4.length - 2];
                  ZoneOffsetTransitionRule arg34 = arg4[arg4.length - 1];
                  arg8 = new int[10];
                  if(ZoneOffsetTransitionRule.access$100(arg33) - ZoneOffsetTransitionRule.access$300(arg33) < 0 && ZoneOffsetTransitionRule.access$100(arg34) - ZoneOffsetTransitionRule.access$300(arg34) > 0) {
                     ZoneOffsetTransitionRule arg38 = arg33;
                     arg33 = arg34;
                     arg34 = arg38;
                  }

                  arg8[0] = ZoneOffsetTransitionRule.access$400(arg33) - 1;
                  byte arg41 = ZoneOffsetTransitionRule.access$500(arg33);
                  arg20 = ZoneOffsetTransitionRule.access$600(arg33);
                  if(arg20 == -1) {
                     arg8[1] = arg41;
                     arg8[2] = 0;
                  } else if(arg41 >= 0 && arg41 < 24) {
                     arg8[1] = arg41;
                     arg8[2] = -toCalendarDOW[arg20];
                  } else {
                     arg8[1] = -1;
                     arg8[2] = toCalendarDOW[arg20];
                  }

                  arg8[3] = ZoneOffsetTransitionRule.access$700(arg33) * 1000;
                  arg8[4] = toSTZTime[ZoneOffsetTransitionRule.access$800(arg33)];
                  arg8[5] = ZoneOffsetTransitionRule.access$400(arg34) - 1;
                  arg41 = ZoneOffsetTransitionRule.access$500(arg34);
                  arg20 = ZoneOffsetTransitionRule.access$600(arg34);
                  if(arg20 == -1) {
                     arg8[6] = arg41;
                     arg8[7] = 0;
                  } else if(arg41 >= 0 && arg41 < 24) {
                     arg8[6] = arg41;
                     arg8[7] = -toCalendarDOW[arg20];
                  } else {
                     arg8[6] = -1;
                     arg8[7] = toCalendarDOW[arg20];
                  }

                  arg8[8] = ZoneOffsetTransitionRule.access$700(arg34) * 1000;
                  arg8[9] = toSTZTime[ZoneOffsetTransitionRule.access$800(arg34)];
                  arg6 = (ZoneOffsetTransitionRule.access$100(arg33) - ZoneOffsetTransitionRule.access$300(arg33)) * 1000;
                  if(arg8[2] == 6 && arg8[3] == 0 && (arg.equals("Asia/Amman") || arg.equals("Asia/Gaza") || arg.equals("Asia/Hebron"))) {
                     arg8[2] = 5;
                     arg8[3] = 86400000;
                  }

                  if(arg8[2] == 7 && arg8[3] == 0 && (arg.equals("Asia/Amman") || arg.equals("Asia/Gaza") || arg.equals("Asia/Hebron"))) {
                     arg8[2] = 6;
                     arg8[3] = 86400000;
                  }

                  if(arg8[7] == 6 && arg8[8] == 0 && arg.equals("Africa/Cairo")) {
                     arg8[7] = 5;
                     arg8[8] = 86400000;
                  }
                  break;
               }

               ZoneOffsetTransitionRule[] arg32 = arg4;
               int arg18 = arg4.length;

               for(arg35 = 0; arg35 < arg18; ++arg35) {
                  ZoneOffsetTransitionRule arg39 = arg32[arg35];
                  long arg21 = arg39.getTransitionEpochSecond(arg14);
                  if(arg12 + 2 >= arg11.length) {
                     arg11 = Arrays.copyOf(arg11, arg11.length + 100);
                  }

                  if(arg13 + 1 >= arg10.length) {
                     arg10 = Arrays.copyOf(arg10, arg10.length + 100);
                  }

                  arg12 = addTrans(arg10, arg13++, arg11, arg12, arg21, ZoneOffsetTransitionRule.access$100(arg39), ZoneOffsetTransitionRule.access$200(arg39));
               }
            }
         }

         if(arg10 != null && arg10.length != arg13) {
            if(arg13 == 0) {
               arg10 = null;
            } else {
               arg10 = Arrays.copyOf(arg10, arg13);
            }
         }

         if(arg11 != null && arg11.length != arg12) {
            if(arg12 == 0) {
               arg11 = null;
            } else {
               arg11 = Arrays.copyOf(arg11, arg12);
            }
         }

         if(arg10 != null) {
            Checksum arg40 = new Checksum((1)null);

            for(arg15 = 0; arg15 < arg10.length; ++arg15) {
               arg37 = arg10[arg15];
               arg20 = (int)(arg37 >>> 4 & 15L);
               int arg9999;
               if(arg20 == 0) {
                  boolean arg45 = false;
               } else {
                  arg9999 = arg11[arg20];
               }

               int arg43 = (int)(arg37 & 15L);
               arg9999 = arg11[arg43];
               long arg44 = arg37 >> 12;
               arg40.update(arg44 + (long)arg43);
               arg40.update(arg43);
               arg40.update(arg20 == 0?-1:arg20);
            }

            arg7 = (int)arg40.getValue();
         }
      }

      return new ZoneInfo(arg, arg31, arg6, arg7, arg10, arg11, arg8, arg9);
   }

	private static int getStandardOffset(long[] arg, int[] arg0, long arg1) {
		int arg3;
		for (arg3 = 0; arg3 < arg.length && arg1 >= arg[arg3]; ++arg3) {
			;
		}

		return arg0[arg3];
	}

	private static int getYear(long arg, int arg1) {
		long arg2 = arg + (long) arg1;
		long arg4 = Math.floorDiv(arg2, 86400L);
		long arg6 = arg4 + 719528L;
		arg6 -= 60L;
		long arg8 = 0L;
		long arg10;
		if (arg6 < 0L) {
			arg10 = (arg6 + 1L) / 146097L - 1L;
			arg8 = arg10 * 400L;
			arg6 += -arg10 * 146097L;
		}

		arg10 = (400L * arg6 + 591L) / 146097L;
		long arg12 = arg6 - (365L * arg10 + arg10 / 4L - arg10 / 100L + arg10 / 400L);
		if (arg12 < 0L) {
			--arg10;
			arg12 = arg6 - (365L * arg10 + arg10 / 4L - arg10 / 100L + arg10 / 400L);
		}

		arg10 += arg8;
		int arg14 = (int) arg12;
		int arg15 = (arg14 * 5 + 2) / 153;
		int arg16 = (arg15 + 2) % 12 + 1;
		int arg17 = arg14 - (arg15 * 306 + 5) / 10 + 1;
		arg10 += (long) (arg15 / 10);
		return (int) arg10;
	}

	private static int indexOf(int[] arg, int arg0, int arg1, int arg2) {
		for (arg2 *= 1000; arg0 < arg1; ++arg0) {
			if (arg[arg0] == arg2) {
				return arg0;
			}
		}

		arg[arg0] = arg2;
		return arg0;
	}

	private static int addTrans(long[] arg, int arg0, int[] arg1, int arg2, long arg3, int arg5, int arg6) {
		int arg7 = indexOf(arg1, 0, arg2, arg5);
		if (arg7 == arg2) {
			++arg2;
		}

		int arg8 = 0;
		if (arg5 != arg6) {
			arg8 = indexOf(arg1, 1, arg2, arg5 - arg6);
			if (arg8 == arg2) {
				++arg2;
			}
		}

		arg[arg0] = arg3 * 1000L << 12 | (long) (arg8 << 4) & 240L | (long) arg7 & 15L;
		return arg2;
	}

	static {
      String arg = ((String)AccessController.doPrivileged(new GetPropertyAction("sun.timezone.ids.oldmapping", "false"))).toLowerCase(Locale.ROOT);
      USE_OLDMAPPING = arg.equals("yes") || arg.equals("true");
      AccessController.doPrivileged(new 1());
      CURRT = System.currentTimeMillis() / 1000L;
      toCalendarDOW = new int[]{-1, 2, 3, 4, 5, 6, 7, 1};
      toSTZTime = new int[]{2, 0, 1};
   }
}

  

 

######################

标签:int,arg1,arg2,ZoneInfoFile,arg0,arg10,arg
来源: https://www.cnblogs.com/herd/p/16268374.html