提交 c46e4b46 编写于 作者: L lana

Merge

......@@ -60,3 +60,6 @@ e6a5d095c356a547cf5b3c8885885aca5e91e09b jdk7-b77
9027c6b9d7e2c9ca04a1add691b5b50d0f22b1aa jdk7-b83
7cb9388bb1a16365fa5118c5efa38b1cd58be40d jdk7-b84
b396584a3e64988839cca21ea1f7fbdcc9248783 jdk7-b85
eae6e9ab26064d9ba0e7665dd646a1fd2506fcc1 jdk7-b86
2cafbbe9825e911a6ca6c17d9a18eb1f0bf0873c jdk7-b87
b3c69282f6d3c90ec21056cd1ab70dc0c895b069 jdk7-b88
......@@ -42,8 +42,6 @@ FILES_src = \
sun/io/ByteToCharBig5_Solaris.java \
sun/io/ByteToCharBig5_HKSCS.java \
sun/io/ByteToCharMS950_HKSCS.java \
sun/io/ByteToCharHKSCS.java \
sun/io/ByteToCharHKSCS_2001.java \
sun/io/ByteToCharGB18030.java \
sun/io/ByteToCharGB18030DB.java \
sun/io/ByteToCharCp037.java \
......@@ -173,8 +171,6 @@ FILES_src = \
sun/io/CharToByteBig5.java \
sun/io/CharToByteBig5_Solaris.java \
sun/io/CharToByteBig5_HKSCS.java \
sun/io/CharToByteHKSCS.java \
sun/io/CharToByteHKSCS_2001.java \
sun/io/CharToByteMS950_HKSCS.java \
sun/io/CharToByteGB18030.java \
sun/io/CharToByteCp037.java \
......@@ -374,6 +370,9 @@ FILES_gen_extcs = \
sun/nio/cs/ext/MacUkraine.java \
sun/nio/cs/ext/TIS_620.java \
sun/nio/cs/ext/EUC_TWMapping.java \
sun/nio/cs/ext/HKSCSMapping.java \
sun/nio/cs/ext/HKSCS2001Mapping.java \
sun/nio/cs/ext/HKSCS_XPMapping.java \
sun/nio/cs/ext/IBM1381.java \
sun/nio/cs/ext/IBM1383.java \
sun/nio/cs/ext/IBM930.java \
......@@ -394,7 +393,8 @@ FILES_gen_extcs = \
sun/nio/cs/ext/MS936.java \
sun/nio/cs/ext/MS949.java \
sun/nio/cs/ext/MS950.java \
sun/nio/cs/ext/GBK.java
sun/nio/cs/ext/GBK.java \
sun/nio/cs/ext/Big5.java
FILES_java = $(FILES_src) $(FILES_gen_extcs)
......@@ -93,7 +93,9 @@ $(FILES_genout_extcs): \
$(MKDIR) -p $(GENCSEXT)
$(BOOT_JAVA_CMD) -jar $(CHARSETMAPPING_JARFILE) $(GENCSDATASRC) $(GENCSEXT) extsbcs
$(BOOT_JAVA_CMD) -jar $(CHARSETMAPPING_JARFILE) $(GENCSDATASRC) $(GENCSEXT) euctw \
$(GENCSSRCDIR)/GenerateEUC_TW.java
$(GENCSSRCDIR)/EUC_TW.java
$(BOOT_JAVA_CMD) -jar $(CHARSETMAPPING_JARFILE) $(GENCSDATASRC) $(GENCSEXT) hkscs \
$(GENCSSRCDIR)/HKSCS.java
$(BOOT_JAVA_CMD) -jar $(CHARSETMAPPING_JARFILE) $(GENCSDATASRC) $(GENCSEXT) dbcs
$(CLASSDESTDIR)/$(SERVICE_DESCRIPTION_PATH): \
......
#Add the following 5 characters which are duplicated
#or have conflicts with other characters.
0xA1C4 0xFF3F #REGWARN Fallback 0xA1C4 SPACING UNDERSCORE
0xA2AC 0x2571 #REGWARN Fallback 0xA2AC LT DIAG UP RIGHT TO LOW LEFT
0xA2AD 0x2572 #REGWARN Fallback 0xA2AD LT DIAG UP LEFT TO LOW RIGHT
0xA451 0x5341 #REGWARN Fallback 0xA451 HANGZHOU NUMERAL TEN
0xA4CA 0x5345 #REGWARN Fallback 0xA4CA HANGZHOU NUMERAL THIRTY
#
此差异已折叠。
0xA15A 0xFF3F #SPACING UNDERSCORE
0xA1FE 0x2571 #LT DIAG UP RIGHT TO LOW LEFT
0xA240 0x2572 #LT DIAG UP LEFT TO LOW RIGHTG
0xA2CC 0x5341 #HANGHZOU NUMERAL TEN
0xA2CE 0x5345 #HANGZHOU NUMERAL THIRTY
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
# Generated from HKSCS.Encoder
#
0xFA45 0xE005
0xFA48 0xE008
0xFA68 0xE028
0xFA6B 0xE02B
0xFAA5 0xE043
0xFACC 0xE06A
0xFACD 0xE06B
0xFAD0 0xE06E
0xFAE0 0xE07E
0xFAE8 0xE086
0xFAFA 0xE098
0xFAFD 0xE09B
0xFB43 0xE0A0
0xFB4B 0xE0A8
0xFB5E 0xE0BB
0xFB65 0xE0C2
0xFB70 0xE0CD
0xFB7A 0xE0D7
0xFB7D 0xE0DA
0xFBB6 0xE0F1
0xFBB9 0xE0F4
0xFBBF 0xE0FA
0xFBC1 0xE0FC
0xFBC9 0xE104
0xFBCA 0xE105
0xFBD3 0xE10E
0xFBDC 0xE117
0xFBEA 0xE125
0xFBEF 0xE12A
0xFBF0 0xE12B
0xFC42 0xE13C
0xFC49 0xE143
0xFC4A 0xE144
0xFC59 0xE153
0xFC64 0xE15E
0xFC65 0xE15F
0xFC66 0xE160
0xFC6A 0xE164
0xFCA6 0xE17E
0xFCB4 0xE18C
0xFCC2 0xE19A
0xFCC4 0xE19C
0xFCCF 0xE1A7
0xFCD1 0xE1A9
0xFCEE 0xE1C6
0xFCF7 0xE1CF
0xFD49 0xE1E0
0xFD4A 0xE1E1
0xFD4C 0xE1E3
0xFD50 0xE1E7
0xFD53 0xE1EA
0xFD5D 0xE1F4
0xFD61 0xE1F8
0xFD6C 0xE203
0xFD7A 0xE211
0xFDA2 0xE217
0xFDA3 0xE218
0xFDC4 0xE239
0xFDCA 0xE23F
0xFDCE 0xE243
0xFDD1 0xE246
0xFDE8 0xE25D
0xFDE9 0xE25E
0xFE4D 0xE281
0xFE56 0xE28A
0xFE64 0xE298
0xFE6E 0xE2A2
0xFE78 0xE2AC
0xFE7D 0xE2B1
0xFEB6 0xE2C8
0xFEC5 0xE2D7
0xFEFB 0xE30D
0x8E45 0xE316
0x8E55 0xE326
0x8E59 0xE32A
0x8E6B 0xE33C
0x8EA2 0xE351
0x8EAF 0xE35E
0x8EB9 0xE368
0x8EC7 0xE376
0x8EC9 0xE378
0x8ED8 0xE387
0x8EED 0xE39C
0x8EFE 0xE3AD
0x8F45 0xE3B3
0x8F50 0xE3BE
0x8F54 0xE3C2
0x8F59 0xE3C7
0x8F5D 0xE3CB
0x8F63 0xE3D1
0x8F64 0xE3D2
0x8F70 0xE3DE
0x8F74 0xE3E2
0x8F76 0xE3E4
0x8F7A 0xE3E8
0x8F7C 0xE3EA
0x8FA9 0xE3F5
0x8FAB 0xE3F7
0x8FBA 0xE406
0x8FC2 0xE40E
0x8FDB 0xE427
0x8FEB 0xE437
0x8FF1 0xE43D
0x8FFD 0xE449
0x9044 0xE44F
0x9055 0xE460
0x9060 0xE46B
0x906F 0xE47A
0x90AA 0xE493
0x90B7 0xE4A0
0x90BC 0xE4A5
0x90C0 0xE4A9
0x90C9 0xE4B2
0x90D5 0xE4BE
0x90D6 0xE4BF
0x90D7 0xE4C0
0x90F5 0xE4DE
0x90FA 0xE4E3
0x90FC 0xE4E5
0x9145 0xE4ED
0x914F 0xE4F7
0x9158 0xE500
0x915F 0xE507
0x9166 0xE50E
0x91AE 0xE534
0x91B3 0xE539
0x91B4 0xE53A
0x91B5 0xE53B
0x91B7 0xE53D
0x91BB 0xE541
0x91CD 0xE553
0x91E3 0xE569
0x91EE 0xE574
0x91F2 0xE578
0x91F5 0xE57B
0x91F9 0xE57F
0x924C 0xE591
0x9251 0xE596
0x9252 0xE597
0x9253 0xE598
0x9257 0xE59C
0x9269 0xE5AE
0x9274 0xE5B9
0x9277 0xE5BC
0x92BD 0xE5E0
0x92C9 0xE5EC
0x92D2 0xE5F5
0x92D7 0xE5FA
0x92DB 0xE5FE
0x92E9 0xE60C
0x92FA 0xE61D
0x9347 0xE629
0x934B 0xE62D
0x9357 0xE639
0x9359 0xE63B
0x935B 0xE63D
0x936F 0xE651
0x93A4 0xE664
0x93B5 0xE675
0x93C1 0xE681
0x93C2 0xE682
0x93CD 0xE68D
0x93D4 0xE694
0x93DD 0xE69D
0x93E0 0xE6A0
0x93E4 0xE6A4
0x93E9 0xE6A9
0x93EB 0xE6AB
0x93F6 0xE6B6
0x9449 0xE6C8
0x9463 0xE6E2
0x9464 0xE6E3
0x9469 0xE6E8
0x946E 0xE6ED
0x9470 0xE6EF
0x9472 0xE6F1
0x9475 0xE6F4
0x9479 0xE6F8
0x947E 0xE6FD
0x94A1 0xE6FE
0x94A3 0xE700
0x94B5 0xE712
0x94B9 0xE716
0x94BC 0xE719
0x94C9 0xE726
0x94D1 0xE72E
0x94D3 0xE730
0x94DB 0xE738
0x94DD 0xE73A
0x94DE 0xE73B
0x94EC 0xE749
0x94EF 0xE74C
0x9544 0xE760
0x955A 0xE776
0x9562 0xE77E
0x9564 0xE780
0x9573 0xE78F
0x95B0 0xE7AA
0x95B2 0xE7AC
0x95B3 0xE7AD
0x95B4 0xE7AE
0x95C6 0xE7C0
0x95C7 0xE7C1
0x95CD 0xE7C7
0x95D1 0xE7CB
0x95D6 0xE7D0
0x95DB 0xE7D5
0x95DF 0xE7D9
0x95EC 0xE7E6
0x95F0 0xE7EA
0x95F6 0xE7F0
0x95FC 0xE7F6
0x9641 0xE7FA
0x964D 0xE806
0x965C 0xE815
0x9662 0xE81B
0x9664 0xE81D
0x9669 0xE822
0x966B 0xE824
0x9675 0xE82E
0x9678 0xE831
0x9679 0xE832
0x96A6 0xE83D
0x96A8 0xE83F
0x96B9 0xE850
0x96BC 0xE853
0x96C8 0xE85F
0x96D4 0xE86B
0x96D6 0xE86D
0x96DF 0xE876
0x96E9 0xE880
0x96F7 0xE88E
0x9743 0xE899
0x9745 0xE89B
0x9746 0xE89C
0x975D 0xE8B3
0x9761 0xE8B7
0x9766 0xE8BC
0x977C 0xE8D2
0x97AE 0xE8E2
0x97B0 0xE8E4
0x97B8 0xE8EC
0x97BA 0xE8EE
0x97C0 0xE8F4
0x97C2 0xE8F6
0x97C3 0xE8F7
0x97C5 0xE8F9
0x97C6 0xE8FA
0x97C9 0xE8FD
0x97CD 0xE901
0x97D2 0xE906
0x97D7 0xE90B
0x97DA 0xE90E
0x97DB 0xE90F
0x97DC 0xE910
0x97DD 0xE911
0x97DE 0xE912
0x97E1 0xE915
0x97E7 0xE91B
0x97FD 0xE931
0x97FE 0xE932
0x9853 0xE946
0x9856 0xE949
0x9872 0xE965
0x9879 0xE96C
0x98A8 0xE979
0x98BC 0xE98D
0x98C3 0xE994
0x98C5 0xE996
0x98CB 0xE99C
0x98CC 0xE99D
0x98CD 0xE99E
0x98CE 0xE99F
0x98D0 0xE9A1
0x98D1 0xE9A2
0x98D6 0xE9A7
0x98D9 0xE9AA
0x98DB 0xE9AC
0x98DD 0xE9AE
0x98E4 0xE9B5
0x98E6 0xE9B7
0x98E8 0xE9B9
0x98E9 0xE9BA
0x98EB 0xE9BC
0x98EC 0xE9BD
0x98F4 0xE9C5
0x98FE 0xE9CF
0x9940 0xE9D0
0x9946 0xE9D6
0x9948 0xE9D8
0x994B 0xE9DB
0x994E 0xE9DE
0x9955 0xE9E5
0x9956 0xE9E6
0x9959 0xE9E9
0x995B 0xE9EB
0x9967 0xE9F7
0x996E 0xE9FE
0x9973 0xEA03
0x997A 0xEA0A
0x997B 0xEA0B
0x99A1 0xEA0F
0x99A5 0xEA13
0x99A7 0xEA15
0x99AD 0xEA1B
0x99B3 0xEA21
0x99BC 0xEA2A
0x99C3 0xEA31
0x99C7 0xEA35
0x99CE 0xEA3C
0x99CF 0xEA3D
0x99DE 0xEA4C
0x99E1 0xEA4F
0x99E9 0xEA57
0x99F5 0xEA63
0x99F8 0xEA66
0x9A48 0xEA75
0x9A49 0xEA76
0x9A50 0xEA7D
0x9A55 0xEA82
0x9A58 0xEA85
0x9A5A 0xEA87
0x9A5C 0xEA89
0x9A60 0xEA8D
0x9A63 0xEA90
0x9A6E 0xEA9B
0x9A70 0xEA9D
0x9A79 0xEAA6
0x9A7B 0xEAA8
0x9ABD 0xEAC8
0x9AEC 0xEAF7
0x9B4D 0xEB17
0x9BA9 0xEB51
0x9BAA 0xEB52
0x9BB8 0xEB60
0x9BBE 0xEB66
0x9BC2 0xEB6A
0x9BDF 0xEB87
0x9BE3 0xEB8B
0x9BEA 0xEB92
0x9BEE 0xEB96
0x9C4A 0xEBB1
0x9C5C 0xEBC3
0x9C6F 0xEBD6
0x9C79 0xEBE0
0x9CA1 0xEBE6
0x9CA5 0xEBEA
0x9CBA 0xEBFF
0x9CBB 0xEC00
0x9CBE 0xEC03
0x9CC6 0xEC0B
0x9CC8 0xEC0D
0x9CD1 0xEC16
0x9CF8 0xEC3D
0x9D46 0xEC4A
0x9D49 0xEC4D
0x9D4F 0xEC53
0x9D51 0xEC55
0x9D5D 0xEC61
0x9D73 0xEC77
0x9D78 0xEC7C
0x9D7B 0xEC7F
0x9DA5 0xEC87
0x9DAA 0xEC8C
0x9DAD 0xEC8F
0x9DB5 0xEC97
0x9DCC 0xECAE
0x9DCE 0xECB0
0x9DEE 0xECD0
0x9DF3 0xECD5
0x9E53 0xECF4
0x9E64 0xED05
0x9E7A 0xED1B
0x9E7E 0xED1F
0x9EA4 0xED23
0x9EB4 0xED33
0x9EB8 0xED37
0x9EB9 0xED38
0x9EBB 0xED3A
0x9EC5 0xED44
0x9EC9 0xED48
0x9ECD 0xED4C
0x9EDA 0xED59
0x9EDD 0xED5C
0x9EDE 0xED5D
0x9EDF 0xED5E
0x9EE5 0xED64
0x9EE7 0xED66
0x9EEE 0xED6D
0x9EF0 0xED6F
0x9EFC 0xED7B
0x9F70 0xEDAE
0x9FA5 0xEDC1
0x9FD7 0xEDF3
0x9FD9 0xEDF5
0xA053 0xEE2E
0xA068 0xEE43
0xA06A 0xEE45
0xA06F 0xEE4A
0xA078 0xEE53
0xA07E 0xEE59
0xA0AC 0xEE65
0xA0D0 0xEE89
0xA0DA 0xEE93
0xA0DE 0xEE97
0xA0E6 0xEE9F
0xA0F9 0xEEB2
0x89B7 0xF3F5
0x89BA 0xF3F8
0x89BF 0xF3FD
0x89C5 0xF403
0x89D5 0xF413
0x89D7 0xF415
0x89DA 0xF418
0x89DB 0xF419
0x89DC 0xF41A
0x89E6 0xF424
0x89E8 0xF426
0x89EA 0xF428
0x89ED 0xF42B
0x89EE 0xF42C
0x89EF 0xF42D
0x89F9 0xF437
0x89FB 0xF439
0x89FC 0xF43A
0x89FE 0xF43C
0x8A48 0xF445
0x8A4D 0xF44A
0x8A51 0xF44E
0x8A52 0xF44F
0x8A67 0xF464
0x8A6B 0xF468
0x8A6D 0xF46A
0x8A6E 0xF46B
0x8A76 0xF473
0x8A7D 0xF47A
0x8AAC 0xF487
0x8AAE 0xF489
0x8AB8 0xF493
0x8AB9 0xF494
0x8ABB 0xF496
0x8AC2 0xF49D
0x8AC7 0xF4A2
0x8AD0 0xF4AB
0x8AD1 0xF4AC
0x8AD3 0xF4AE
0x8ADA 0xF4B5
0x8AEB 0xF4C6
0x8AF0 0xF4CB
0x8AFB 0xF4D6
0x8B47 0xF4E1
0x8B60 0xF4FA
0x8B68 0xF502
0x8B6A 0xF504
0x8BA6 0xF51E
0x8BB1 0xF529
0x8BB5 0xF52D
0x8BB6 0xF52E
0x8BB8 0xF530
0x8BBE 0xF536
0x8BC8 0xF540
0x8BCC 0xF544
0x8BDC 0xF554
0x8D63 0xF637
0x8D64 0xF638
0x8D67 0xF63B
0x8D68 0xF63C
0x8D6D 0xF641
0x8D6E 0xF642
0x8D6F 0xF643
0x8D70 0xF644
0x8D74 0xF648
0x8D78 0xF64C
0x8D7D 0xF651
0x8DA1 0xF653
0x8DA6 0xF658
0x8DAB 0xF65D
0x8DAD 0xF65F
0x8DB0 0xF662
0x8DB2 0xF664
0x8DB4 0xF666
0x8DB7 0xF669
0x8DBA 0xF66C
0x8DBB 0xF66D
0x8DBC 0xF66E
0x8DC3 0xF675
0x8DC5 0xF677
0x8DCA 0xF67C
0x8DCC 0xF67E
0x8DD6 0xF688
0x8DDB 0xF68D
0x8DEB 0xF69D
0x8DEF 0xF6A1
0x8DF0 0xF6A2
0x8DF3 0xF6A5
0x8DF5 0xF6A7
0x8DFC 0xF6AE
0x8DFD 0xF6AF
0xC6CD 0xF6DD
0xC8D6 0xF820
0xC8D7 0xF821
0xC8D8 0xF822
0xC8D9 0xF823
0xC8DA 0xF824
0xC8DB 0xF825
0xC8DC 0xF826
0xC8DD 0xF827
0xC8DE 0xF828
0xC8DF 0xF829
0xC8E0 0xF82A
0xC8E1 0xF82B
0xC8E2 0xF82C
0xC8E3 0xF82D
0xC8E4 0xF82E
0xC8E5 0xF82F
0xC8E6 0xF830
0xC8E7 0xF831
0xC8E8 0xF832
0xC8E9 0xF833
0xC8EA 0xF834
0xC8EB 0xF835
0xC8EC 0xF836
0xC8ED 0xF837
0xC8EE 0xF838
0xC8EF 0xF839
0xC8F0 0xF83A
0xC8F1 0xF83B
此差异已折叠。
#
#clzName csName hisName dbtype pkg ascii b1min b1max b2min b2max
#
Big5 Big5 Big5 basic sun.nio.cs.ext true 0xa1 0xf9 0x40 0xfe
Johab x-Johab x-Johab basic sun.nio.cs.ext true 0x84 0xf9 0x31 0xfe
EUC_CN GB2312 EUC_CN basic sun.nio.cs.ext true 0xa1 0xf7 0xa1 0xfe
EUC_KR EUC-KR EUC_KR basic sun.nio.cs.ext true 0xa1 0xfd 0xa1 0xfe
......
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -31,12 +31,13 @@ import java.util.Scanner;
import java.util.Formatter;
import java.util.regex.*;
import java.nio.charset.*;
import static build.tools.charsetmapping.CharsetMapping.*;
import static build.tools.charsetmapping.Utils.*;
public class GenerateDBCS {
public class DBCS {
// pattern used by this class to read in mapping table
static Pattern mPattern = Pattern.compile("(?:0x)?(\\p{XDigit}++)\\s++(?:0x)?(\\p{XDigit}++)(?:\\s++#.*)?");
public static void genDBCS(String args[]) throws Exception {
public static void genClass(String args[]) throws Exception {
Scanner s = new Scanner(new File(args[0], args[2]));
while (s.hasNextLine()) {
......@@ -63,81 +64,29 @@ public class GenerateDBCS {
int b2Min = toInteger(fields[8]);
int b2Max = toInteger(fields[9]);
System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName);
genClass(args[0], args[1], "DoubleByte-X.java.template",
genClass0(args[0], args[1], "DoubleByte-X.java.template",
clzName, csName, hisName, pkgName,
isASCII, type,
b1Min, b1Max, b2Min, b2Max);
}
}
private static int toInteger(String s) {
static int toInteger(String s) {
if (s.startsWith("0x") || s.startsWith("0X"))
return Integer.valueOf(s.substring(2), 16);
else
return Integer.valueOf(s);
}
private static void outString(Formatter out,
char[] cc, int off, int end,
String closure)
{
while (off < end) {
out.format(" \"");
for (int j = 0; j < 8; j++) {
if (off == end)
break;
char c = cc[off++];
switch (c) {
case '\b':
out.format("\\b"); break;
case '\t':
out.format("\\t"); break;
case '\n':
out.format("\\n"); break;
case '\f':
out.format("\\f"); break;
case '\r':
out.format("\\r"); break;
case '\"':
out.format("\\\""); break;
case '\'':
out.format("\\'"); break;
case '\\':
out.format("\\\\"); break;
default:
out.format("\\u%04X", c & 0xffff);
}
}
if (off == end)
out.format("\" %s%n", closure);
else
out.format("\" + %n");
}
}
private static void outString(Formatter out,
char[] db,
int b1,
int b2Min, int b2Max,
String closure)
{
char[] cc = new char[b2Max - b2Min + 1];
int off = 0;
for (int b2 = b2Min; b2 <= b2Max; b2++) {
cc[off++] = db[(b1 << 8) | b2];
}
outString(out, cc, 0, cc.length, closure);
}
private static void genClass(String srcDir, String dstDir, String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII,
String type,
int b1Min, int b1Max,
int b2Min, int b2Max)
private static void genClass0(String srcDir, String dstDir, String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII,
String type,
int b1Min, int b1Max,
int b2Min, int b2Max)
throws Exception
{
......@@ -172,21 +121,21 @@ public class GenerateDBCS {
c2bIndex[e.cp>>8] = 1;
}
}
Formatter fm = new Formatter(b2cSB);
fm.format("%n static final String b2cSBStr =%n");
outString(fm, db, 0x00, 0x100, ";");
Output out = new Output(new Formatter(b2cSB));
out.format("%n static final String b2cSBStr =%n");
out.format(db, 0x00, 0x100, ";");
fm.format("%n static final String[] b2cStr = {%n");
out.format("%n static final String[] b2cStr = {%n");
for (int i = 0; i < 0x100; i++) {
if (b2cIndex[i] == UNMAPPABLE_DECODING) {
fm.format(" null,%n"); //unmappable segments
out.format(" null,%n"); //unmappable segments
} else {
outString(fm, db, i, b2Min, b2Max, ",");
out.format(db, i, b2Min, b2Max, ",");
}
}
fm.format(" };%n");
fm.close();
out.format(" };%n");
out.close();
// (2)now parse the .nr file which includes "b->c" non-roundtrip entries
File f = new File(srcDir, clzName + ".nr");
......@@ -201,10 +150,10 @@ public class GenerateDBCS {
sb.append((char)e.cp);
}
char[] nr = sb.toString().toCharArray();
fm = new Formatter(b2cNRSB);
fm.format("String b2cNR =%n");
outString(fm, nr, 0, nr.length, ";");
fm.close();
out = new Output(new Formatter(b2cNRSB));
out.format("String b2cNR =%n");
out.format(nr, 0, nr.length, ";");
out.close();
} else {
b2cNRSB.append("String b2cNR = null;");
}
......@@ -226,10 +175,10 @@ public class GenerateDBCS {
sb.append((char)e.cp);
}
char[] nr = sb.toString().toCharArray();
fm = new Formatter(c2bNRSB);
fm.format("String c2bNR =%n");
outString(fm, nr, 0, nr.length, ";");
fm.close();
out = new Output(new Formatter(c2bNRSB));
out.format("String c2bNR =%n");
out.format(nr, 0, nr.length, ";");
out.close();
} else {
c2bNRSB.append("String c2bNR = null;");
}
......@@ -240,15 +189,15 @@ public class GenerateDBCS {
String c2bNR = c2bNRSB.toString();
Scanner s = new Scanner(new File(srcDir, template));
PrintStream out = new PrintStream(new FileOutputStream(
new File(dstDir, clzName + ".java")));
PrintStream ops = new PrintStream(new FileOutputStream(
new File(dstDir, clzName + ".java")));
if (hisName == null)
hisName = "";
while (s.hasNextLine()) {
String line = s.nextLine();
if (line.indexOf("$") == -1) {
out.println(line);
ops.println(line);
continue;
}
line = line.replace("$PACKAGE$" , pkgName)
......@@ -280,8 +229,8 @@ public class GenerateDBCS {
.replace("$NONROUNDTRIP_B2C$", b2cNR)
.replace("$NONROUNDTRIP_C2B$", c2bNR);
out.println(line);
ops.println(line);
}
out.close();
ops.close();
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -31,33 +31,13 @@ import java.util.Scanner;
import java.util.Formatter;
import java.util.regex.*;
import java.nio.charset.*;
import static build.tools.charsetmapping.CharsetMapping.*;
import static build.tools.charsetmapping.Utils.*;
public class GenerateEUC_TW {
public class EUC_TW {
public static void genEUC_TW(String args[]) throws Exception {
genClass(new FileInputStream(new File(args[0], "euc_tw.map")),
new PrintStream(new File(args[1], "EUC_TWMapping.java"), "ISO-8859-1"),
getCopyright(new File(args[3])));
}
private static String getCopyright(File f) throws IOException {
Scanner s = new Scanner(f, "ISO-8859-1");
StringBuilder sb = new StringBuilder();
while (s.hasNextLine()) {
String ln = s.nextLine();
sb.append(ln + "\n");
// assume we have the copyright as the first comment
if (ln.matches("^\\s\\*\\/$"))
break;
}
s.close();
return sb.toString();
}
private static char[] toCharArray(int[] db,
int b1Min, int b1Max,
int b2Min, int b2Max)
static char[] toCharArray(int[] db,
int b1Min, int b1Max,
int b2Min, int b2Max)
{
char[] ca = new char[(b1Max - b1Min + 1) * (b2Max - b2Min + 1)];
int off = 0;
......@@ -69,48 +49,9 @@ public class GenerateEUC_TW {
return ca;
}
private static void toChar(Formatter out, String fmt, char c) {
switch (c) {
case '\b':
out.format("\\b"); break;
case '\t':
out.format("\\t"); break;
case '\n':
out.format("\\n"); break;
case '\f':
out.format("\\f"); break;
case '\r':
out.format("\\r"); break;
case '\"':
out.format("\\\""); break;
case '\'':
out.format("\\'"); break;
case '\\':
out.format("\\\\"); break;
default:
out.format(fmt, c & 0xffff);
}
}
private static void toString(Formatter out, char[] date, String endStr)
{
int off = 0;
int end = date.length;
while (off < end) {
out.format(" \"");
for (int j = 0; j < 8 && off < end; j++) {
toChar(out, "\\u%04X", date[off++]);
}
if (off == end)
out.format("\"%s%n", endStr);
else
out.format("\" +%n");
}
}
private static char[] toCharArray(byte[] ba,
int b1Min, int b1Max,
int b2Min, int b2Max)
static char[] toCharArray(byte[] ba,
int b1Min, int b1Max,
int b2Min, int b2Max)
{
char[] ca = new char[(b1Max - b1Min + 1) * (b2Max - b2Min + 1)];
int off = 0;
......@@ -124,18 +65,6 @@ public class GenerateEUC_TW {
return ca;
}
private static void toCharArray(Formatter out, char[] date) {
int off = 0;
int end = date.length;
while (off < end) {
out.format(" ");
for (int j = 0; j < 8 && off < end; j++) {
toChar(out, "'\\u%04X',", date[off++]);
}
out.format("%n");
}
}
private static int initC2BIndex(char[] index) {
int off = 0;
for (int i = 0; i < index.length; i++) {
......@@ -143,7 +72,7 @@ public class GenerateEUC_TW {
index[i] = (char)off;
off += 0x100;
} else {
index[i] = CharsetMapping.UNMAPPABLE_ENCODING;
index[i] = UNMAPPABLE_ENCODING;
}
}
return off;
......@@ -151,9 +80,14 @@ public class GenerateEUC_TW {
private static Pattern euctw = Pattern.compile("(?:8ea)?(\\p{XDigit}++)\\s++(\\p{XDigit}++)?\\s*+.*");
private static void genClass(InputStream is, PrintStream ps, String copyright)
throws Exception
static void genClass(String args[]) throws Exception
{
InputStream is = new FileInputStream(new File(args[0], "euc_tw.map"));
PrintStream ps = new PrintStream(new File(args[1], "EUC_TWMapping.java"),
"ISO-8859-1");
String copyright = getCopyright(new File(args[3]));
// ranges of byte1 and byte2, something should come from a "config" file
int b1Min = 0xa1;
int b1Max = 0xfe;
......@@ -168,10 +102,10 @@ public class GenerateEUC_TW {
for (int i = 0; i < 8; i++)
for (int j = 0; j < 0x10000; j++)
db[i][j] = CharsetMapping.UNMAPPABLE_DECODING;
db[i][j] = UNMAPPABLE_DECODING;
CharsetMapping.Parser p = new CharsetMapping.Parser(is, euctw);
CharsetMapping.Entry e = null;
Parser p = new Parser(is, euctw);
Entry e = null;
while ((e = p.next()) != null) {
int plane = 0;
if (e.bs >= 0x10000) {
......@@ -189,55 +123,52 @@ public class GenerateEUC_TW {
}
}
StringBuilder out = new StringBuilder();
Formatter fm = new Formatter(out);
StringBuilder sb = new StringBuilder();
Output out = new Output(new Formatter(sb));
fm.format(copyright);
fm.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");
fm.format("package sun.nio.cs.ext;%n%n");
fm.format("class EUC_TWMapping {%n%n");
out.format(copyright);
out.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");
out.format("package sun.nio.cs.ext;%n%n");
out.format("class EUC_TWMapping {%n%n");
// boundaries
fm.format(" final static int b1Min = 0x%x;%n", b1Min);
fm.format(" final static int b1Max = 0x%x;%n", b1Max);
fm.format(" final static int b2Min = 0x%x;%n", b2Min);
fm.format(" final static int b2Max = 0x%x;%n", b2Max);
out.format(" final static int b1Min = 0x%x;%n", b1Min);
out.format(" final static int b1Max = 0x%x;%n", b1Max);
out.format(" final static int b2Min = 0x%x;%n", b2Min);
out.format(" final static int b2Max = 0x%x;%n", b2Max);
// b2c tables
fm.format("%n final static String[] b2c = {%n");
out.format("%n final static String[] b2c = {%n");
for (int plane = 0; plane < 8; plane++) {
fm.format(" // Plane %d%n", plane);
toString(fm, toCharArray(db[plane],
b1Min, b1Max, b2Min, b2Max),
",");
fm.format("%n");
out.format(" // Plane %d%n", plane);
out.format(toCharArray(db[plane], b1Min, b1Max, b2Min, b2Max),
",");
out.format("%n");
}
fm.format(" };%n");
out.format(" };%n");
// c2bIndex
fm.format("%n static final int C2BSIZE = 0x%x;%n",
initC2BIndex(indexC2B));
fm.format("%n static char[] c2bIndex = new char[] {%n");
toCharArray(fm, indexC2B);
fm.format(" };%n");
out.format("%n static final int C2BSIZE = 0x%x;%n",
initC2BIndex(indexC2B));
out.format("%n static char[] c2bIndex = new char[] {%n");
out.format(indexC2B);
out.format(" };%n");
// c2bIndexSupp
fm.format("%n static final int C2BSUPPSIZE = 0x%x;%n",
initC2BIndex(indexC2BSupp));
fm.format("%n static char[] c2bSuppIndex = new char[] {%n");
toCharArray(fm, indexC2BSupp);
fm.format(" };%n");
out.format("%n static final int C2BSUPPSIZE = 0x%x;%n",
initC2BIndex(indexC2BSupp));
out.format("%n static char[] c2bSuppIndex = new char[] {%n");
out.format(indexC2BSupp);
out.format(" };%n");
// suppFlags
fm.format("%n static String b2cIsSuppStr =%n");
toString(fm, toCharArray(suppFlag,
b1Min, b1Max, b2Min, b2Max),
";");
fm.format("}");
fm.close();
out.format("%n static String b2cIsSuppStr =%n");
out.format(toCharArray(suppFlag, b1Min, b1Max, b2Min, b2Max),
";");
out.format("}");
out.close();
ps.println(out.toString());
ps.println(sb.toString());
ps.close();
} catch (Exception x) {
x.printStackTrace();
......
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package build.tools.charsetmapping;
import java.io.*;
import java.util.regex.*;
import static build.tools.charsetmapping.CharsetMapping.*;
public class GenerateMapping {
public static void genMapping(String argv[]) throws IOException {
genDataJIS0213(new FileInputStream(argv[0]),
new FileOutputStream(argv[1]));
}
// regex pattern to parse the "jis0213.map" file
static Pattern sjis0213 = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(?:\\+(\\p{XDigit}++))?\\s++#.*");
private static void genDataJIS0213(InputStream in, OutputStream out)
{
int[] sb = new int[0x100]; // singlebyte
int[] db = new int[0x10000]; // doublebyte
int[] indexC2B = new int[256];
Entry[] supp = new Entry[0x10000];
Entry[] comp = new Entry[0x100];
int suppTotal = 0;
int compTotal = 0;
int b1Min1 = 0x81;
int b1Max1 = 0x9f;
int b1Min2 = 0xe0;
int b1Max2 = 0xfc;
int b2Min = 0x40;
int b2Max = 0xfe;
//init
for (int i = 0; i < 0x80; i++) sb[i] = i;
for (int i = 0x80; i < 0x100; i++) sb[i] = UNMAPPABLE_DECODING;
for (int i = 0; i < 0x10000; i++) db[i] = UNMAPPABLE_DECODING;
try {
Parser p = new Parser(in, sjis0213);
Entry e = null;
while ((e = p.next()) != null) {
if (e.cp2 != 0) {
comp[compTotal++] = e;
} else {
if (e.cp <= 0xffff) {
if (e.bs <= 0xff)
sb[e.bs] = e.cp;
else
db[e.bs] = e.cp;
indexC2B[e.cp>>8] = 1;
} else {
supp[suppTotal++] = e;
}
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// c2b Index Table, always the first one
writeINDEXC2B(baos, indexC2B);
writeSINGLEBYTE(baos, sb);
writeDOUBLEBYTE1(baos, db, b1Min1, b1Max1, b2Min, b2Max);
writeDOUBLEBYTE2(baos, db, b1Min2, b1Max2, b2Min, b2Max);
writeSUPPLEMENT(baos, supp, suppTotal);
writeCOMPOSITE(baos, comp, compTotal);
writeSIZE(out, baos.size());
baos.writeTo(out);
out.close();
} catch (Exception x) {
x.printStackTrace();
}
}
}
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package build.tools.charsetmapping;
import java.io.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Formatter;
import java.util.regex.*;
import java.nio.charset.*;
import static build.tools.charsetmapping.Utils.*;
public class HKSCS {
// HKSCS2001.map has the third column for "UnicodeAlternate", which
// is for c->b non-roundtrip mapping.
// For HKSCS2008, those non-roundtrip mappings are in .nr file
private static Pattern hkscs =
Pattern.compile("(?:0x)?+(\\p{XDigit}++)\\s++(?:0x|U\\+)?+(\\p{XDigit}++)?\\s*+(?:0x|U\\+)?(\\p{XDigit}++)?\\s*+.*");
static void genClass(String args[]) throws Exception {
// hkscs2008
genClass0(new FileInputStream(new File(args[0], "HKSCS2008.map")),
new FileInputStream(new File(args[0], "HKSCS2008.c2b")),
new PrintStream(new File(args[1], "HKSCSMapping.java"),
"ISO-8859-1"),
"HKSCSMapping",
getCopyright(new File(args[3])));
// xp2001
genClass0(new FileInputStream(new File(args[0], "HKSCS_XP.map")),
null,
new PrintStream(new File(args[1], "HKSCS_XPMapping.java"),
"ISO-8859-1"),
"HKSCS_XPMapping",
getCopyright(new File(args[3])));
// hkscs2001
genClass0(new FileInputStream(new File(args[0], "HKSCS2001.map")),
new FileInputStream(new File(args[0], "HKSCS2001.c2b")),
new PrintStream(new File(args[1], "HKSCS2001Mapping.java"),
"ISO-8859-1"),
"HKSCS2001Mapping",
getCopyright(new File(args[3])));
}
static void genClass0(InputStream isB2C,
InputStream isC2B,
PrintStream ps,
String clzName,
String copyright)
throws Exception
{
// ranges of byte1 and byte2, something should come from a "config" file
int b1Min = 0x87;
int b1Max = 0xfe;
int b2Min = 0x40;
int b2Max = 0xfe;
try {
char[] bmp = new char[0x10000];
char[] supp = new char[0x10000];
boolean[] b2cBmp = new boolean[0x100];
boolean[] b2cSupp = new boolean[0x100];
// pua should be in range of e000-f8ff. Expand
// it to 0xf93b becase the hkscs2001.c2b has
// the f920-f93b filled
//char[] pua = new char[0xF8FF - 0xE000 + 1];
char[] pua = new char[0xF93b - 0xE000 + 1];
boolean hasSupp = false;
boolean hasPua = false;
Arrays.fill(bmp, UNMAPPABLE_DECODING);
Arrays.fill(supp, UNMAPPABLE_DECODING);
Arrays.fill(pua, UNMAPPABLE_DECODING);
Parser p = new Parser(isB2C, hkscs);
Entry e = null;
while ((e = p.next()) != null) {
if (e.cp >= 0x10000) {
supp[e.bs] = (char)e.cp;
b2cSupp[e.bs>>8] = true;
hasSupp = true;
} else {
bmp[e.bs] = (char)e.cp;
b2cBmp[e.bs>>8] = true;
}
if (e.cp2 != 0 && e.cp2 >= 0xe000 && e.cp2 <= 0xf8ff) {
hasPua = true;
pua[e.cp2 - 0xE000] = (char)e.bs;
}
}
if (isC2B != null) {
p = new Parser(isC2B, hkscs);
e = null;
while ((e = p.next()) != null) {
pua[e.cp - 0xE000] = (char)e.bs;
}
hasPua = true;
}
StringBuilder sb = new StringBuilder();
Output out = new Output(new Formatter(sb));
out.format(copyright);
out.format("%n// -- This file was mechanically generated: Do not edit! -- //%n");
out.format("package sun.nio.cs.ext;%n%n");
out.format("class %s {%n%n", clzName);
/* hardcoded in sun.nio.cs.ext.HKSCS.java
out.format(" final static int b1Min = 0x%x;%n", b1Min);
out.format(" final static int b1Max = 0x%x;%n", b1Max);
out.format(" final static int b2Min = 0x%x;%n", b2Min);
out.format(" final static int b2Max = 0x%x;%n", b2Max);
*/
// bmp tables
out.format("%n static final String[] b2cBmpStr = new String[] {%n");
for (int i = 0; i < 0x100; i++) {
if (b2cBmp[i])
out.format(bmp, i, b2Min, b2Max, ",");
else
out.format(" null,%n"); //unmappable segments
}
out.format(" };%n");
// supp tables
out.format("%n static final String[] b2cSuppStr =");
if (hasSupp) {
out.format(" new String[] {%n");
for (int i = 0; i < 0x100; i++) {
if (b2cSupp[i])
out.format(supp, i, b2Min, b2Max, ",");
else
out.format(" null,%n"); //unmappable segments
}
out.format(" };%n");
} else {
out.format(" null;%n");
}
// private area tables
out.format("%n final static String pua =");
if (hasPua) {
out.format("%n");
out.format(pua, 0, pua.length, ";");
} else {
out.format(" null;%n");
}
out.format("%n");
out.format("}");
out.close();
ps.println(sb.toString());
ps.close();
} catch (Exception x) {
x.printStackTrace();
}
}
}
......@@ -25,29 +25,71 @@
package build.tools.charsetmapping;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.util.regex.*;
import java.util.*;
import static build.tools.charsetmapping.Utils.*;
public class CharsetMapping {
public final static char UNMAPPABLE_DECODING = '\uFFFD';
public final static int UNMAPPABLE_ENCODING = 0xFFFD;
public class JIS0213 {
public static class Entry {
public int bs; //byte sequence reps
public int cp; //Unicode codepoint
public int cp2; //CC of composite
// regex pattern to parse the "jis0213.map" file
static Pattern sjis0213 = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(?:\\+(\\p{XDigit}++))?\\s++#.*");
public Entry () {}
public Entry (int bytes, int cp, int cp2) {
this.bs = bytes;
this.cp = cp;
this.cp2 = cp2;
static void genClass(String argv[]) throws IOException
{
InputStream in = new FileInputStream(argv[0]) ;
OutputStream out = new FileOutputStream(argv[1]);
int[] sb = new int[0x100]; // singlebyte
int[] db = new int[0x10000]; // doublebyte
int[] indexC2B = new int[256];
Entry[] supp = new Entry[0x10000];
Entry[] comp = new Entry[0x100];
int suppTotal = 0;
int compTotal = 0;
int b1Min1 = 0x81;
int b1Max1 = 0x9f;
int b1Min2 = 0xe0;
int b1Max2 = 0xfc;
int b2Min = 0x40;
int b2Max = 0xfe;
//init
for (int i = 0; i < 0x80; i++) sb[i] = i;
for (int i = 0x80; i < 0x100; i++) sb[i] = UNMAPPABLE_DECODING;
for (int i = 0; i < 0x10000; i++) db[i] = UNMAPPABLE_DECODING;
try {
Parser p = new Parser(in, sjis0213);
Entry e = null;
while ((e = p.next()) != null) {
if (e.cp2 != 0) {
comp[compTotal++] = e;
} else {
if (e.cp <= 0xffff) {
if (e.bs <= 0xff)
sb[e.bs] = e.cp;
else
db[e.bs] = e.cp;
indexC2B[e.cp>>8] = 1;
} else {
supp[suppTotal++] = e;
}
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// c2b Index Table, always the first one
writeINDEXC2B(baos, indexC2B);
writeSINGLEBYTE(baos, sb);
writeDOUBLEBYTE1(baos, db, b1Min1, b1Max1, b2Min, b2Max);
writeDOUBLEBYTE2(baos, db, b1Min2, b1Max2, b2Min, b2Max);
writeSUPPLEMENT(baos, supp, suppTotal);
writeCOMPOSITE(baos, comp, compTotal);
writeSIZE(out, baos.size());
baos.writeTo(out);
out.close();
} catch (Exception x) {
x.printStackTrace();
}
}
......@@ -61,76 +103,6 @@ public class CharsetMapping {
}
};
public static class Parser {
static final Pattern basic = Pattern.compile("(?:0x)?(\\p{XDigit}++)\\s++(?:0x)?(\\p{XDigit}++)?\\s*+.*");
static final int gBS = 1;
static final int gCP = 2;
static final int gCP2 = 3;
BufferedReader reader;
boolean closed;
Matcher matcher;
int gbs, gcp, gcp2;
public Parser (InputStream in, Pattern p, int gbs, int gcp, int gcp2)
throws IOException
{
this.reader = new BufferedReader(new InputStreamReader(in));
this.closed = false;
this.matcher = p.matcher("");
this.gbs = gbs;
this.gcp = gcp;
this.gcp2 = gcp2;
}
public Parser (InputStream in, Pattern p) throws IOException {
this(in, p, gBS, gCP, gCP2);
}
public Parser (InputStream in) throws IOException {
this(in, basic, gBS, gCP, gCP2);
}
protected boolean isDirective(String line) {
return line.startsWith("#");
}
protected Entry parse(Matcher matcher, Entry mapping) {
mapping.bs = Integer.parseInt(matcher.group(gbs), 16);
mapping.cp = Integer.parseInt(matcher.group(gcp), 16);
if (gcp2 <= matcher.groupCount() &&
matcher.group(gcp2) != null)
mapping.cp2 = Integer.parseInt(matcher.group(gcp2), 16);
else
mapping.cp2 = 0;
return mapping;
}
public Entry next() throws Exception {
return next(new Entry());
}
// returns null and closes the input stream if the eof has beenreached.
public Entry next(Entry mapping) throws Exception {
if (closed)
return null;
String line;
while ((line = reader.readLine()) != null) {
if (isDirective(line))
continue;
matcher.reset(line);
if (!matcher.lookingAt()) {
//System.out.println("Missed: " + line);
continue;
}
return parse(matcher, mapping);
}
reader.close();
closed = true;
return null;
}
}
// tags of different charset mapping tables
private final static int MAP_SINGLEBYTE = 0x1; // 0..256 : c
private final static int MAP_DOUBLEBYTE1 = 0x2; // min..max: c
......@@ -161,7 +133,7 @@ public class CharsetMapping {
}
}
public static final void writeSIZE(OutputStream out, int data)
private static final void writeSIZE(OutputStream out, int data)
throws IOException
{
out.write((data >>> 24) & 0xFF);
......@@ -170,7 +142,7 @@ public class CharsetMapping {
out.write((data ) & 0xFF);
}
public static void writeINDEXC2B(OutputStream out, int[] indexC2B)
private static void writeINDEXC2B(OutputStream out, int[] indexC2B)
throws IOException
{
writeShort(out, MAP_INDEXC2B);
......@@ -186,7 +158,7 @@ public class CharsetMapping {
}
}
public static void writeSINGLEBYTE(OutputStream out, int[] sb)
private static void writeSINGLEBYTE(OutputStream out, int[] sb)
throws IOException
{
writeShortArray(out, MAP_SINGLEBYTE, sb, 0, 256);
......@@ -212,7 +184,8 @@ public class CharsetMapping {
}
}
}
public static void writeDOUBLEBYTE1(OutputStream out,
private static void writeDOUBLEBYTE1(OutputStream out,
int[] db,
int b1Min, int b1Max,
int b2Min, int b2Max)
......@@ -221,7 +194,7 @@ public class CharsetMapping {
writeDOUBLEBYTE(out, MAP_DOUBLEBYTE1, db, b1Min, b1Max, b2Min, b2Max);
}
public static void writeDOUBLEBYTE2(OutputStream out,
private static void writeDOUBLEBYTE2(OutputStream out,
int[] db,
int b1Min, int b1Max,
int b2Min, int b2Max)
......@@ -231,7 +204,7 @@ public class CharsetMapping {
}
// the c2b table is output as well
public static void writeSUPPLEMENT(OutputStream out, Entry[] supp, int size)
private static void writeSUPPLEMENT(OutputStream out, Entry[] supp, int size)
throws IOException
{
writeShort(out, MAP_SUPPLEMENT);
......@@ -256,7 +229,7 @@ public class CharsetMapping {
}
}
public static void writeCOMPOSITE(OutputStream out, Entry[] comp, int size)
private static void writeCOMPOSITE(OutputStream out, Entry[] comp, int size)
throws IOException
{
writeShort(out, MAP_COMPOSITE);
......
......@@ -32,23 +32,19 @@ public class Main {
public static void main(String args[]) throws Exception {
if (args.length < 3 ) {
System.out.println("Usage: java -jar charsetmapping.jar src dst mType...");
System.out.println("Usage: java -jar charsetmapping.jar src dst mType [copyrightSrc]");
System.exit(1);
}
if ("sbcs".equals(args[2]) || "extsbcs".equals(args[2])) {
GenerateSBCS.genSBCS(args);
SBCS.genClass(args);
} else if ("dbcs".equals(args[2])) {
GenerateDBCS.genDBCS(args);
DBCS.genClass(args);
} else if ("euctw".equals(args[2])) {
if (args.length != 4) {
System.out.println("Usage: java -jar charsetmapping.jar srcDir dstDir euctw copyrightSrc");
System.exit(1);
}
GenerateEUC_TW.genEUC_TW(args);
EUC_TW.genClass(args);
} else if ("sjis0213".equals(args[2])) {
GenerateMapping.genMapping(args);
JIS0213.genClass(args);
} else if ("hkscs".equals(args[2])) {
HKSCS.genClass(args);
}
}
}
......@@ -32,11 +32,11 @@ import java.util.Scanner;
import java.util.Formatter;
import java.util.regex.*;
import java.nio.charset.*;
import static build.tools.charsetmapping.CharsetMapping.*;
import static build.tools.charsetmapping.Utils.*;
public class GenerateSBCS {
public class SBCS {
public static void genSBCS(String args[]) throws Exception {
public static void genClass(String args[]) throws Exception {
Scanner s = new Scanner(new File(args[0], args[2]));
while (s.hasNextLine()) {
......@@ -55,8 +55,8 @@ public class GenerateSBCS {
String pkgName = fields[4];
System.out.printf("%s,%s,%s,%b,%s%n", clzName, csName, hisName, isASCII, pkgName);
genClass(args[0], args[1], "SingleByte-X.java.template",
clzName, csName, hisName, pkgName, isASCII);
genClass0(args[0], args[1], "SingleByte-X.java.template",
clzName, csName, hisName, pkgName, isASCII);
}
}
......@@ -108,13 +108,13 @@ public class GenerateSBCS {
static Pattern sbmap = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(\\s++#.*)?");
private static void genClass(String srcDir, String dstDir,
String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII)
private static void genClass0(String srcDir, String dstDir,
String template,
String clzName,
String csName,
String hisName,
String pkgName,
boolean isASCII)
throws Exception
{
StringBuilder b2cSB = new StringBuilder();
......
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package build.tools.charsetmapping;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Scanner;
import java.util.Formatter;
public class Utils {
public final static char UNMAPPABLE_DECODING = '\uFFFD';
public final static int UNMAPPABLE_ENCODING = 0xFFFD;
public static class Entry {
public int bs; //byte sequence reps
public int cp; //Unicode codepoint
public int cp2; //CC of composite
public Entry () {}
public Entry (int bytes, int cp, int cp2) {
this.bs = bytes;
this.cp = cp;
this.cp2 = cp2;
}
}
public static class Parser {
static final Pattern basic = Pattern.compile("(?:0x)?(\\p{XDigit}++)\\s++(?:0x)?(\\p{XDigit}++)?\\s*+.*");
static final int gBS = 1;
static final int gCP = 2;
static final int gCP2 = 3;
BufferedReader reader;
boolean closed;
Matcher matcher;
int gbs, gcp, gcp2;
public Parser (InputStream in, Pattern p, int gbs, int gcp, int gcp2)
throws IOException
{
this.reader = new BufferedReader(new InputStreamReader(in));
this.closed = false;
this.matcher = p.matcher("");
this.gbs = gbs;
this.gcp = gcp;
this.gcp2 = gcp2;
}
public Parser (InputStream in, Pattern p) throws IOException {
this(in, p, gBS, gCP, gCP2);
}
public Parser (InputStream in) throws IOException {
this(in, basic, gBS, gCP, gCP2);
}
protected boolean isDirective(String line) {
return line.startsWith("#");
}
protected Entry parse(Matcher matcher, Entry mapping) {
mapping.bs = Integer.parseInt(matcher.group(gbs), 16);
mapping.cp = Integer.parseInt(matcher.group(gcp), 16);
if (gcp2 <= matcher.groupCount() &&
matcher.group(gcp2) != null)
mapping.cp2 = Integer.parseInt(matcher.group(gcp2), 16);
else
mapping.cp2 = 0;
return mapping;
}
public Entry next() throws Exception {
return next(new Entry());
}
// returns null and closes the input stream if the eof has beenreached.
public Entry next(Entry mapping) throws Exception {
if (closed)
return null;
String line;
while ((line = reader.readLine()) != null) {
if (isDirective(line))
continue;
matcher.reset(line);
if (!matcher.lookingAt()) {
//System.out.println("Missed: " + line);
continue;
}
return parse(matcher, mapping);
}
reader.close();
closed = true;
return null;
}
}
public static class Output {
private Formatter out;
public Output(Formatter out) {
this.out = out;
}
public void close() {
out.close();
}
private void toChar(String fmt, char c) {
switch (c) {
case '\b':
out.format("\\b"); break;
case '\t':
out.format("\\t"); break;
case '\n':
out.format("\\n"); break;
case '\f':
out.format("\\f"); break;
case '\r':
out.format("\\r"); break;
case '\"':
out.format("\\\""); break;
case '\'':
out.format("\\'"); break;
case '\\':
out.format("\\\\"); break;
default:
out.format(fmt, c & 0xffff);
}
}
public void format(String fmt, Object ... args) {
out.format(fmt, args);
}
public void format(char[] cc, int off, int end, String closure) {
while (off < end) {
out.format(" \"");
for (int j = 0; j < 8; j++) {
if (off == end)
break;
toChar("\\u%04X", cc[off++]);
}
if (off == end)
out.format("\" %s%n", closure);
else
out.format("\" + %n");
}
}
public void format(char[] cc, String closure) {
format(cc, 0, cc.length, closure);
}
public void format(char[] db, int b1, int b2Min, int b2Max,
String closure)
{
char[] cc = new char[b2Max - b2Min + 1];
int off = 0;
for (int b2 = b2Min; b2 <= b2Max; b2++) {
cc[off++] = db[(b1 << 8) | b2];
}
format(cc, 0, cc.length, closure);
}
public void format(char[] date) {
int off = 0;
int end = date.length;
while (off < end) {
out.format(" ");
for (int j = 0; j < 8 && off < end; j++) {
toChar("'\\u%04X',", date[off++]);
}
out.format("%n");
}
}
}
public static String getCopyright(File f) throws IOException {
Scanner s = new Scanner(f, "ISO-8859-1");
StringBuilder sb = new StringBuilder();
while (s.hasNextLine()) {
String ln = s.nextLine();
sb.append(ln + "\n");
// assume we have the copyright as the first comment
if (ln.matches("^\\s\\*\\/$"))
break;
}
s.close();
return sb.toString();
}
}
......@@ -32,7 +32,6 @@ import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EventObject;
import sun.reflect.misc.MethodUtil;
/**
......@@ -279,9 +278,9 @@ import sun.reflect.misc.MethodUtil;
public class EventHandler implements InvocationHandler {
private Object target;
private String action;
private String eventPropertyName;
private String listenerMethodName;
private AccessControlContext acc;
private final String eventPropertyName;
private final String listenerMethodName;
private final AccessControlContext acc = AccessController.getContext();
/**
* Creates a new <code>EventHandler</code> object;
......@@ -310,7 +309,6 @@ public class EventHandler implements InvocationHandler {
*/
@ConstructorProperties({"target", "action", "eventPropertyName", "listenerMethodName"})
public EventHandler(Object target, String action, String eventPropertyName, String listenerMethodName) {
this.acc = AccessController.getContext();
this.target = target;
this.action = action;
if (target == null) {
......@@ -422,7 +420,11 @@ public class EventHandler implements InvocationHandler {
* @see EventHandler
*/
public Object invoke(final Object proxy, final Method method, final Object[] arguments) {
return AccessController.doPrivileged(new PrivilegedAction() {
AccessControlContext acc = this.acc;
if ((acc == null) && (System.getSecurityManager() != null)) {
throw new SecurityException("AccessControlContext is not set");
}
return AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
return invokeInternal(proxy, method, arguments);
}
......@@ -482,7 +484,10 @@ public class EventHandler implements InvocationHandler {
throw new RuntimeException(ex);
}
catch (InvocationTargetException ex) {
throw new RuntimeException(ex.getTargetException());
Throwable th = ex.getTargetException();
throw (th instanceof RuntimeException)
? (RuntimeException) th
: new RuntimeException(th);
}
}
return null;
......
......@@ -29,6 +29,10 @@ import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import com.sun.beans.finder.ClassFinder;
import com.sun.beans.finder.ConstructorFinder;
......@@ -63,9 +67,10 @@ public class Statement {
}
};
Object target;
String methodName;
Object[] arguments;
private final AccessControlContext acc = AccessController.getContext();
private final Object target;
private final String methodName;
private final Object[] arguments;
ClassLoader loader;
/**
......@@ -169,6 +174,26 @@ public class Statement {
}
Object invoke() throws Exception {
AccessControlContext acc = this.acc;
if ((acc == null) && (System.getSecurityManager() != null)) {
throw new SecurityException("AccessControlContext is not set");
}
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {
return invokeInternal();
}
},
acc
);
}
catch (PrivilegedActionException exception) {
throw exception.getException();
}
}
private Object invokeInternal() throws Exception {
Object target = getTarget();
String methodName = getMethodName();
......
......@@ -2064,11 +2064,12 @@ public class File
private synchronized void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException
{
s.defaultReadObject();
ObjectInputStream.GetField fields = s.readFields();
String pathField = (String)fields.get("path", null);
char sep = s.readChar(); // read the previous separator char
if (sep != separatorChar)
this.path = this.path.replace(sep, separatorChar);
this.path = fs.normalize(this.path);
pathField = pathField.replace(sep, separatorChar);
this.path = fs.normalize(pathField);
this.prefixLength = fs.prefixLength(this.path);
}
......
......@@ -134,9 +134,18 @@ class FilterInputStream extends InputStream {
}
/**
* {@inheritDoc}
* Skips over and discards <code>n</code> bytes of data from the
* input stream. The <code>skip</code> method may, for a variety of
* reasons, end up skipping over some smaller number of bytes,
* possibly <code>0</code>. The actual number of bytes skipped is
* returned.
* <p>
* This method simply performs <code>in.skip(n)</code>.
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException if the stream does not support seek,
* or if some other I/O error occurs.
*/
public long skip(long n) throws IOException {
return in.skip(n);
......
......@@ -994,6 +994,8 @@ public final class ProcessBuilder
// Must convert to array first -- a malicious user-supplied
// list might try to circumvent the security check.
String[] cmdarray = command.toArray(new String[command.size()]);
cmdarray = cmdarray.clone();
for (String arg : cmdarray)
if (arg == null)
throw new NullPointerException();
......
......@@ -55,7 +55,7 @@ import sun.misc.VM;
*/
public
class ThreadGroup implements Thread.UncaughtExceptionHandler {
ThreadGroup parent;
private final ThreadGroup parent;
String name;
int maxPriority;
boolean destroyed;
......@@ -76,6 +76,7 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler {
private ThreadGroup() { // called from C code
this.name = "system";
this.maxPriority = Thread.MAX_PRIORITY;
this.parent = null;
}
/**
......@@ -113,10 +114,10 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @since JDK1.0
*/
public ThreadGroup(ThreadGroup parent, String name) {
if (parent == null) {
throw new NullPointerException();
}
parent.checkAccess();
this(checkParentAccess(parent), parent, name);
}
private ThreadGroup(Void unused, ThreadGroup parent, String name) {
this.name = name;
this.maxPriority = parent.maxPriority;
this.daemon = parent.daemon;
......@@ -125,6 +126,16 @@ class ThreadGroup implements Thread.UncaughtExceptionHandler {
parent.add(this);
}
/*
* @throws NullPointerException if the parent argument is {@code null}
* @throws SecurityException if the current thread cannot create a
* thread in the specified thread group.
*/
private static Void checkParentAccess(ThreadGroup parent) {
parent.checkAccess();
return null;
}
/**
* Returns the name of this thread group.
*
......
......@@ -118,6 +118,7 @@ class DatagramSocket implements java.io.Closeable {
if (address == null) {
throw new IllegalArgumentException("connect: null address");
}
checkAddress (address, "connect");
if (isClosed())
return;
SecurityManager security = System.getSecurityManager();
......@@ -363,13 +364,15 @@ class DatagramSocket implements java.io.Closeable {
InetSocketAddress epoint = (InetSocketAddress) addr;
if (epoint.isUnresolved())
throw new SocketException("Unresolved address");
InetAddress iaddr = epoint.getAddress();
int port = epoint.getPort();
checkAddress(iaddr, "bind");
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkListen(epoint.getPort());
sec.checkListen(port);
}
try {
getImpl().bind(epoint.getPort(),
epoint.getAddress());
getImpl().bind(port, iaddr);
} catch (SocketException e) {
getImpl().close();
throw e;
......@@ -377,6 +380,15 @@ class DatagramSocket implements java.io.Closeable {
bound = true;
}
void checkAddress (InetAddress addr, String op) {
if (addr == null) {
return;
}
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) {
throw new IllegalArgumentException(op + ": invalid address type");
}
}
/**
* Connects the socket to a remote address for this socket. When a
* socket is connected to a remote address, packets may only be
......@@ -603,6 +615,7 @@ class DatagramSocket implements java.io.Closeable {
synchronized (p) {
if (isClosed())
throw new SocketException("Socket is closed");
checkAddress (p.getAddress(), "send");
if (connectState == ST_NOT_CONNECTED) {
// check the address is ok wiht the security manager on every send.
SecurityManager security = System.getSecurityManager();
......
......@@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.security.AccessController;
import java.io.ObjectStreamException;
import java.io.IOException;
import java.io.ObjectInputStream;
import sun.security.action.*;
import sun.net.InetAddressCachePolicy;
import sun.net.util.IPAddressUtil;
......@@ -1472,6 +1473,23 @@ class InetAddress implements java.io.Serializable {
return impl;
}
private void readObjectNoData (ObjectInputStream s) throws
IOException, ClassNotFoundException {
if (getClass().getClassLoader() != null) {
throw new SecurityException ("invalid address type");
}
}
private void readObject (ObjectInputStream s) throws
IOException, ClassNotFoundException {
s.defaultReadObject ();
if (getClass().getClassLoader() != null) {
hostName = null;
address = 0;
throw new SecurityException ("invalid address type");
}
}
}
/*
......
......@@ -289,6 +289,7 @@ class MulticastSocket extends DatagramSocket {
throw new SocketException("Socket is closed");
}
checkAddress(mcastaddr, "joinGroup");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkMulticast(mcastaddr);
......@@ -323,6 +324,7 @@ class MulticastSocket extends DatagramSocket {
throw new SocketException("Socket is closed");
}
checkAddress(mcastaddr, "leaveGroup");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkMulticast(mcastaddr);
......@@ -370,6 +372,7 @@ class MulticastSocket extends DatagramSocket {
if (oldImpl)
throw new UnsupportedOperationException();
checkAddress(((InetSocketAddress)mcastaddr).getAddress(), "joinGroup");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkMulticast(((InetSocketAddress)mcastaddr).getAddress());
......@@ -416,6 +419,7 @@ class MulticastSocket extends DatagramSocket {
if (oldImpl)
throw new UnsupportedOperationException();
checkAddress(((InetSocketAddress)mcastaddr).getAddress(), "leaveGroup");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkMulticast(((InetSocketAddress)mcastaddr).getAddress());
......@@ -441,6 +445,7 @@ class MulticastSocket extends DatagramSocket {
if (isClosed()) {
throw new SocketException("Socket is closed");
}
checkAddress(inf, "setInterface");
synchronized (infLock) {
getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf);
infAddress = inf;
......@@ -632,6 +637,7 @@ class MulticastSocket extends DatagramSocket {
throws IOException {
if (isClosed())
throw new SocketException("Socket is closed");
checkAddress(p.getAddress(), "send");
synchronized(ttlLock) {
synchronized(p) {
if (connectState == ST_NOT_CONNECTED) {
......
......@@ -290,8 +290,12 @@ public final class NetworkInterface {
* If the specified address is <tt>null</tt>.
*/
public static NetworkInterface getByInetAddress(InetAddress addr) throws SocketException {
if (addr == null)
if (addr == null) {
throw new NullPointerException();
}
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) {
throw new IllegalArgumentException ("invalid address type");
}
return getByInetAddress0(addr);
}
......
......@@ -122,6 +122,9 @@ class Socket implements java.io.Closeable {
if (p.type() == Proxy.Type.SOCKS) {
SecurityManager security = System.getSecurityManager();
InetSocketAddress epoint = (InetSocketAddress) p.address();
if (epoint.getAddress() != null) {
checkAddress (epoint.getAddress(), "Socket");
}
if (security != null) {
if (epoint.isUnresolved())
security.checkConnect(epoint.getHostName(),
......@@ -558,15 +561,16 @@ class Socket implements java.io.Closeable {
throw new IllegalArgumentException("Unsupported address type");
InetSocketAddress epoint = (InetSocketAddress) endpoint;
InetAddress addr = epoint.getAddress ();
int port = epoint.getPort();
checkAddress(addr, "connect");
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (epoint.isUnresolved())
security.checkConnect(epoint.getHostName(),
epoint.getPort());
security.checkConnect(epoint.getHostName(), port);
else
security.checkConnect(epoint.getAddress().getHostAddress(),
epoint.getPort());
security.checkConnect(addr.getHostAddress(), port);
}
if (!created)
createImpl(true);
......@@ -574,10 +578,9 @@ class Socket implements java.io.Closeable {
impl.connect(epoint, timeout);
else if (timeout == 0) {
if (epoint.isUnresolved())
impl.connect(epoint.getAddress().getHostName(),
epoint.getPort());
impl.connect(addr.getHostName(), port);
else
impl.connect(epoint.getAddress(), epoint.getPort());
impl.connect(addr, port);
} else
throw new UnsupportedOperationException("SocketImpl.connect(addr, timeout)");
connected = true;
......@@ -614,14 +617,25 @@ class Socket implements java.io.Closeable {
InetSocketAddress epoint = (InetSocketAddress) bindpoint;
if (epoint != null && epoint.isUnresolved())
throw new SocketException("Unresolved address");
if (bindpoint == null)
getImpl().bind(InetAddress.anyLocalAddress(), 0);
else
getImpl().bind(epoint.getAddress(),
epoint.getPort());
if (epoint == null) {
epoint = new InetSocketAddress(0);
}
InetAddress addr = epoint.getAddress();
int port = epoint.getPort();
checkAddress (addr, "bind");
getImpl().bind (addr, port);
bound = true;
}
private void checkAddress (InetAddress addr, String op) {
if (addr == null) {
return;
}
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) {
throw new IllegalArgumentException(op + ": invalid address type");
}
}
/**
* set the flags after an accept() call.
*/
......
......@@ -118,6 +118,10 @@ class SocketInputStream extends FileInputStream
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[], int off, int length) throws IOException {
return read(b, off, length, impl.getTimeout());
}
int read(byte b[], int off, int length, int timeout) throws IOException {
int n;
// EOF already encountered
......@@ -143,7 +147,7 @@ class SocketInputStream extends FileInputStream
// acquire file descriptor and do the read
FileDescriptor fd = impl.acquireFD();
try {
n = socketRead0(fd, b, off, length, impl.getTimeout());
n = socketRead0(fd, b, off, length, timeout);
if (n > 0) {
return n;
}
......@@ -161,7 +165,7 @@ class SocketInputStream extends FileInputStream
impl.setConnectionResetPending();
impl.acquireFD();
try {
n = socketRead0(fd, b, off, length, impl.getTimeout());
n = socketRead0(fd, b, off, length, timeout);
if (n > 0) {
return n;
}
......
......@@ -98,11 +98,31 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
super.connect(new InetSocketAddress(host, port), timeout);
}
private static int remainingMillis(long deadlineMillis) throws IOException {
if (deadlineMillis == 0L)
return 0;
final long remaining = deadlineMillis - System.currentTimeMillis();
if (remaining > 0)
return (int) remaining;
throw new SocketTimeoutException();
}
private int readSocksReply(InputStream in, byte[] data) throws IOException {
return readSocksReply(in, data, 0L);
}
private int readSocksReply(InputStream in, byte[] data, long deadlineMillis) throws IOException {
int len = data.length;
int received = 0;
for (int attempts = 0; received < len && attempts < 3; attempts++) {
int count = in.read(data, received, len - received);
int count;
try {
count = ((SocketInputStream)in).read(data, received, len - received, remainingMillis(deadlineMillis));
} catch (SocketTimeoutException e) {
throw new SocketTimeoutException("Connect timed out");
}
if (count < 0)
throw new SocketException("Malformed reply from SOCKS server");
received += count;
......@@ -115,6 +135,12 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
*/
private boolean authenticate(byte method, InputStream in,
BufferedOutputStream out) throws IOException {
return authenticate(method, in, out, 0L);
}
private boolean authenticate(byte method, InputStream in,
BufferedOutputStream out,
long deadlineMillis) throws IOException {
// No Authentication required. We're done then!
if (method == NO_AUTH)
return true;
......@@ -162,7 +188,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write(0);
out.flush();
byte[] data = new byte[2];
int i = readSocksReply(in, data);
int i = readSocksReply(in, data, deadlineMillis);
if (i != 2 || data[1] != 0) {
/* RFC 1929 specifies that the connection MUST be closed if
authentication fails */
......@@ -201,18 +227,18 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
// out.write(outToken);
// out.flush();
// data = new byte[2];
// i = readSocksReply(in, data);
// i = readSocksReply(in, data, deadlineMillis);
// if (i != 2 || data[1] == 0xff) {
// in.close();
// out.close();
// return false;
// }
// i = readSocksReply(in, data);
// i = readSocksReply(in, data, deadlineMillis);
// int len = 0;
// len = ((int)data[0] & 0xff) << 8;
// len += data[1];
// data = new byte[len];
// i = readSocksReply(in, data);
// i = readSocksReply(in, data, deadlineMillis);
// if (i == len)
// return true;
// in.close();
......@@ -231,7 +257,8 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
}
private void connectV4(InputStream in, OutputStream out,
InetSocketAddress endpoint) throws IOException {
InetSocketAddress endpoint,
long deadlineMillis) throws IOException {
if (!(endpoint.getAddress() instanceof Inet4Address)) {
throw new SocketException("SOCKS V4 requires IPv4 only addresses");
}
......@@ -249,7 +276,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write(0);
out.flush();
byte[] data = new byte[8];
int n = readSocksReply(in, data);
int n = readSocksReply(in, data, deadlineMillis);
if (n != 8)
throw new SocketException("Reply from SOCKS server has bad length: " + n);
if (data[0] != 0 && data[0] != 4)
......@@ -296,6 +323,15 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
*/
@Override
protected void connect(SocketAddress endpoint, int timeout) throws IOException {
final long deadlineMillis;
if (timeout == 0) {
deadlineMillis = 0L;
} else {
long finish = System.currentTimeMillis() + timeout;
deadlineMillis = finish < 0 ? Long.MAX_VALUE : finish;
}
SecurityManager security = System.getSecurityManager();
if (endpoint == null || !(endpoint instanceof InetSocketAddress))
throw new IllegalArgumentException("Unsupported address type");
......@@ -322,7 +358,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
/*
* No default proxySelector --> direct connection
*/
super.connect(epoint, timeout);
super.connect(epoint, remainingMillis(deadlineMillis));
return;
}
URI uri;
......@@ -345,13 +381,13 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
java.util.Iterator<Proxy> iProxy = null;
iProxy = sel.select(uri).iterator();
if (iProxy == null || !(iProxy.hasNext())) {
super.connect(epoint, timeout);
super.connect(epoint, remainingMillis(deadlineMillis));
return;
}
while (iProxy.hasNext()) {
p = iProxy.next();
if (p == null || p == Proxy.NO_PROXY) {
super.connect(epoint, timeout);
super.connect(epoint, remainingMillis(deadlineMillis));
return;
}
if (p.type() != Proxy.Type.SOCKS)
......@@ -364,7 +400,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
// Connects to the SOCKS server
try {
privilegedConnect(server, serverPort, timeout);
privilegedConnect(server, serverPort, remainingMillis(deadlineMillis));
// Worked, let's get outta here
break;
} catch (IOException e) {
......@@ -388,7 +424,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
} else {
// Connects to the SOCKS server
try {
privilegedConnect(server, serverPort, timeout);
privilegedConnect(server, serverPort, remainingMillis(deadlineMillis));
} catch (IOException e) {
throw new SocketException(e.getMessage());
}
......@@ -403,7 +439,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
// DOMAIN type of addresses (unresolved addresses here)
if (epoint.isUnresolved())
throw new UnknownHostException(epoint.toString());
connectV4(in, out, epoint);
connectV4(in, out, epoint, deadlineMillis);
return;
}
......@@ -414,7 +450,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
out.write(USER_PASSW);
out.flush();
byte[] data = new byte[2];
int i = readSocksReply(in, data);
int i = readSocksReply(in, data, deadlineMillis);
if (i != 2 || ((int)data[0]) != PROTO_VERS) {
// Maybe it's not a V5 sever after all
// Let's try V4 before we give up
......@@ -422,12 +458,12 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
// DOMAIN type of addresses (unresolved addresses here)
if (epoint.isUnresolved())
throw new UnknownHostException(epoint.toString());
connectV4(in, out, epoint);
connectV4(in, out, epoint, deadlineMillis);
return;
}
if (((int)data[1]) == NO_METHODS)
throw new SocketException("SOCKS : No acceptable methods");
if (!authenticate(data[1], in, out)) {
if (!authenticate(data[1], in, out, deadlineMillis)) {
throw new SocketException("SOCKS : authentication failed");
}
out.write(PROTO_VERS);
......@@ -457,7 +493,7 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
}
out.flush();
data = new byte[4];
i = readSocksReply(in, data);
i = readSocksReply(in, data, deadlineMillis);
if (i != 4)
throw new SocketException("Reply from SOCKS server has bad length");
SocketException ex = null;
......@@ -469,33 +505,33 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
switch(data[3]) {
case IPV4:
addr = new byte[4];
i = readSocksReply(in, addr);
i = readSocksReply(in, addr, deadlineMillis);
if (i != 4)
throw new SocketException("Reply from SOCKS server badly formatted");
data = new byte[2];
i = readSocksReply(in, data);
i = readSocksReply(in, data, deadlineMillis);
if (i != 2)
throw new SocketException("Reply from SOCKS server badly formatted");
break;
case DOMAIN_NAME:
len = data[1];
byte[] host = new byte[len];
i = readSocksReply(in, host);
i = readSocksReply(in, host, deadlineMillis);
if (i != len)
throw new SocketException("Reply from SOCKS server badly formatted");
data = new byte[2];
i = readSocksReply(in, data);
i = readSocksReply(in, data, deadlineMillis);
if (i != 2)
throw new SocketException("Reply from SOCKS server badly formatted");
break;
case IPV6:
len = data[1];
addr = new byte[len];
i = readSocksReply(in, addr);
i = readSocksReply(in, addr, deadlineMillis);
if (i != len)
throw new SocketException("Reply from SOCKS server badly formatted");
data = new byte[2];
i = readSocksReply(in, data);
i = readSocksReply(in, data, deadlineMillis);
if (i != 2)
throw new SocketException("Reply from SOCKS server badly formatted");
break;
......
/*
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -28,19 +28,17 @@ package java.security;
import java.io.*;
import java.lang.RuntimePermission;
import java.lang.reflect.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import java.util.StringTokenizer;
import java.util.PropertyPermission;
import java.lang.reflect.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.WeakHashMap;
import sun.security.util.Debug;
import sun.security.jca.GetInstance;
import sun.security.util.Debug;
import sun.security.util.SecurityConstants;
......@@ -113,8 +111,8 @@ public abstract class Policy {
private static final Debug debug = Debug.getInstance("policy");
// Cache mapping ProtectionDomain to PermissionCollection
private WeakHashMap<ProtectionDomain, PermissionCollection> pdMapping;
// Cache mapping ProtectionDomain.Key to PermissionCollection
private WeakHashMap<ProtectionDomain.Key, PermissionCollection> pdMapping;
/** package private for AccessControlContext */
static boolean isSet()
......@@ -307,7 +305,7 @@ public abstract class Policy {
synchronized (p) {
if (p.pdMapping == null) {
p.pdMapping =
new WeakHashMap<ProtectionDomain, PermissionCollection>();
new WeakHashMap<ProtectionDomain.Key, PermissionCollection>();
}
}
......@@ -323,7 +321,7 @@ public abstract class Policy {
synchronized (p.pdMapping) {
// cache of pd to permissions
p.pdMapping.put(policyDomain, policyPerms);
p.pdMapping.put(policyDomain.key, policyPerms);
}
}
return;
......@@ -638,7 +636,7 @@ public abstract class Policy {
}
synchronized (pdMapping) {
pc = pdMapping.get(domain);
pc = pdMapping.get(domain.key);
}
if (pc != null) {
......@@ -697,7 +695,7 @@ public abstract class Policy {
}
synchronized (pdMapping) {
pc = pdMapping.get(domain);
pc = pdMapping.get(domain.key);
}
if (pc != null) {
......@@ -711,7 +709,7 @@ public abstract class Policy {
synchronized (pdMapping) {
// cache it
pdMapping.put(domain, pc);
pdMapping.put(domain.key, pc);
}
return pc.implies(permission);
......@@ -747,21 +745,25 @@ public abstract class Policy {
this.params = params;
}
public String getType() { return type; }
@Override public String getType() { return type; }
public Policy.Parameters getParameters() { return params; }
@Override public Policy.Parameters getParameters() { return params; }
public Provider getProvider() { return p; }
@Override public Provider getProvider() { return p; }
@Override
public PermissionCollection getPermissions(CodeSource codesource) {
return spi.engineGetPermissions(codesource);
}
@Override
public PermissionCollection getPermissions(ProtectionDomain domain) {
return spi.engineGetPermissions(domain);
}
@Override
public boolean implies(ProtectionDomain domain, Permission perm) {
return spi.engineImplies(domain, perm);
}
@Override
public void refresh() {
spi.engineRefresh();
}
......@@ -803,7 +805,7 @@ public abstract class Policy {
* @exception SecurityException - if this PermissionCollection object
* has been marked readonly
*/
public void add(Permission permission) {
@Override public void add(Permission permission) {
perms.add(permission);
}
......@@ -816,7 +818,7 @@ public abstract class Policy {
* @return true if "permission" is implied by the permissions in
* the collection, false if not.
*/
public boolean implies(Permission permission) {
@Override public boolean implies(Permission permission) {
return perms.implies(permission);
}
......@@ -826,7 +828,7 @@ public abstract class Policy {
*
* @return an enumeration of all the Permissions.
*/
public Enumeration<Permission> elements() {
@Override public Enumeration<Permission> elements() {
return perms.elements();
}
}
......
/*
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -25,9 +25,15 @@
package java.security;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.WeakHashMap;
import sun.misc.JavaSecurityProtectionDomainAccess;
import static sun.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
import sun.misc.SharedSecrets;
import sun.security.util.Debug;
import sun.security.util.SecurityConstants;
......@@ -72,6 +78,11 @@ public class ProtectionDomain {
or dynamic (via a policy refresh) */
private boolean staticPermissions;
/*
* An object used as a key when the ProtectionDomain is stored in a Map.
*/
final Key key = new Key();
private static final Debug debug = Debug.getInstance("domain");
/**
......@@ -238,7 +249,7 @@ public class ProtectionDomain {
/**
* Convert a ProtectionDomain to a String.
*/
public String toString() {
@Override public String toString() {
String pals = "<no principals>";
if (principals != null && principals.length > 0) {
StringBuilder palBuf = new StringBuilder("(principals ");
......@@ -396,4 +407,29 @@ public class ProtectionDomain {
return mergedPerms;
}
/**
* Used for storing ProtectionDomains as keys in a Map.
*/
final class Key {}
static {
SharedSecrets.setJavaSecurityProtectionDomainAccess(
new JavaSecurityProtectionDomainAccess() {
public ProtectionDomainCache getProtectionDomainCache() {
return new ProtectionDomainCache() {
private final Map<Key, PermissionCollection> map =
Collections.synchronizedMap
(new WeakHashMap<Key, PermissionCollection>());
public void put(ProtectionDomain pd,
PermissionCollection pc) {
map.put((pd == null ? null : pd.key), pc);
}
public PermissionCollection get(ProtectionDomain pd) {
return pd == null ? map.get(null) : map.get(pd.key);
}
};
}
});
}
}
......@@ -191,8 +191,11 @@ public class Semaphore implements java.io.Serializable {
protected final boolean tryReleaseShared(int releases) {
for (;;) {
int p = getState();
if (compareAndSetState(p, p + releases))
int current = getState();
int next = current + releases;
if (next < current) // overflow
throw new Error("Maximum permit count exceeded");
if (compareAndSetState(current, next))
return true;
}
}
......@@ -201,6 +204,8 @@ public class Semaphore implements java.io.Serializable {
for (;;) {
int current = getState();
int next = current - reductions;
if (next > current) // underflow
throw new Error("Permit count underflow");
if (compareAndSetState(current, next))
return;
}
......
......@@ -57,7 +57,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
private long rawIndex(int i) {
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
return base + i * scale;
return base + (long) i * scale;
}
/**
......
......@@ -56,7 +56,7 @@ public class AtomicLongArray implements java.io.Serializable {
private long rawIndex(int i) {
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
return base + i * scale;
return base + (long) i * scale;
}
/**
......
......@@ -57,7 +57,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
private long rawIndex(int i) {
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
return base + i * scale;
return base + (long) i * scale;
}
/**
......
/*
* Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -23,26 +23,24 @@
* have any questions.
*/
package sun.io;
import sun.nio.cs.ext.HKSCS;
package java.util.zip;
/**
* Tables and data to convert Unicode to HKSCS
*
* @author ConverterGenerator tool
* A reference to the native zlib's z_stream structure.
*/
public class CharToByteHKSCS extends CharToByteDoubleByte {
class ZStreamRef {
private long address;
ZStreamRef (long address) {
this.address = address;
}
public String getCharacterEncoding() {
return "HKSCS";
long address() {
return address;
}
public CharToByteHKSCS() {
super.index1 = HKSCS.getEncoderIndex1();
super.index2 = HKSCS.getEncoderIndex2();
void clear() {
address = 0;
}
}
......@@ -36,6 +36,8 @@ import java.util.Enumeration;
import java.util.Set;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
import static java.util.zip.ZipConstants64.*;
/**
......@@ -78,6 +80,17 @@ class ZipFile implements ZipConstants, Closeable {
private static native void initIDs();
private static final boolean usemmap;
static {
// A system prpperty to disable mmap use to avoid vm crash when
// in-use zip file is accidently overwritten by others.
String prop = AccessController.doPrivileged(
new GetPropertyAction("sun.zip.disableMemoryMapping"));
usemmap = (prop == null ||
!(prop.length() == 0 || prop.equalsIgnoreCase("true")));
}
/**
* Opens a zip file for reading.
*
......@@ -196,7 +209,7 @@ class ZipFile implements ZipConstants, Closeable {
throw new NullPointerException("charset is null");
this.zc = ZipCoder.get(charset);
long t0 = System.nanoTime();
jzfile = open(name, mode, file.lastModified());
jzfile = open(name, mode, file.lastModified(), usemmap);
sun.misc.PerfCounter.getZipFileOpenTime().addElapsedTimeFrom(t0);
sun.misc.PerfCounter.getZipFileCount().increment();
this.name = name;
......@@ -673,8 +686,8 @@ class ZipFile implements ZipConstants, Closeable {
}
private static native long open(String name, int mode, long lastModified)
throws IOException;
private static native long open(String name, int mode, long lastModified,
boolean usemmap) throws IOException;
private static native int getTotal(long jzfile);
private static native int read(long jzfile, long jzentry,
long pos, byte[] b, int off, int len);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册