Merge
This commit is contained in:
commit
e98b3651ea
@ -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): \
|
||||
|
8
jdk/make/tools/CharsetMapping/Big5.c2b
Normal file
8
jdk/make/tools/CharsetMapping/Big5.c2b
Normal file
@ -0,0 +1,8 @@
|
||||
#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
|
||||
#
|
13837
jdk/make/tools/CharsetMapping/Big5.map
Normal file
13837
jdk/make/tools/CharsetMapping/Big5.map
Normal file
File diff suppressed because it is too large
Load Diff
5
jdk/make/tools/CharsetMapping/Big5.nr
Normal file
5
jdk/make/tools/CharsetMapping/Big5.nr
Normal file
@ -0,0 +1,5 @@
|
||||
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
|
2187
jdk/make/tools/CharsetMapping/HKSCS2001.c2b
Normal file
2187
jdk/make/tools/CharsetMapping/HKSCS2001.c2b
Normal file
File diff suppressed because it is too large
Load Diff
4821
jdk/make/tools/CharsetMapping/HKSCS2001.map
Normal file
4821
jdk/make/tools/CharsetMapping/HKSCS2001.map
Normal file
File diff suppressed because it is too large
Load Diff
4969
jdk/make/tools/CharsetMapping/HKSCS2008.c2b
Normal file
4969
jdk/make/tools/CharsetMapping/HKSCS2008.c2b
Normal file
File diff suppressed because it is too large
Load Diff
5019
jdk/make/tools/CharsetMapping/HKSCS2008.map
Normal file
5019
jdk/make/tools/CharsetMapping/HKSCS2008.map
Normal file
File diff suppressed because it is too large
Load Diff
529
jdk/make/tools/CharsetMapping/HKSCS_XP.c2b
Normal file
529
jdk/make/tools/CharsetMapping/HKSCS_XP.c2b
Normal file
@ -0,0 +1,529 @@
|
||||
# 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
|
4704
jdk/make/tools/CharsetMapping/HKSCS_XP.map
Normal file
4704
jdk/make/tools/CharsetMapping/HKSCS_XP.map
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
||||
#
|
||||
#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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
177
jdk/make/tools/src/build/tools/charsetmapping/EUC_TW.java
Normal file
177
jdk/make/tools/src/build/tools/charsetmapping/EUC_TW.java
Normal file
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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.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 EUC_TW {
|
||||
|
||||
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;
|
||||
for (int b1 = b1Min; b1 <= b1Max; b1++) {
|
||||
for (int b2 = b2Min; b2 <= b2Max; b2++) {
|
||||
ca[off++] = (char)(db[b1 * 256 + b2] & 0xffff);
|
||||
}
|
||||
}
|
||||
return ca;
|
||||
}
|
||||
|
||||
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;
|
||||
for (int b1 = b1Min; b1 <= b1Max; b1++) {
|
||||
int b2 = b2Min;
|
||||
while (b2 <= b2Max) {
|
||||
ca[off++] = (char)(((ba[b1 * 256 + b2++] & 0xff) << 8) |
|
||||
(ba[b1 * 256 + b2++] & 0xff));
|
||||
}
|
||||
}
|
||||
return ca;
|
||||
}
|
||||
|
||||
private static int initC2BIndex(char[] index) {
|
||||
int off = 0;
|
||||
for (int i = 0; i < index.length; i++) {
|
||||
if (index[i] != 0) {
|
||||
index[i] = (char)off;
|
||||
off += 0x100;
|
||||
} else {
|
||||
index[i] = UNMAPPABLE_ENCODING;
|
||||
}
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
private static Pattern euctw = Pattern.compile("(?:8ea)?(\\p{XDigit}++)\\s++(\\p{XDigit}++)?\\s*+.*");
|
||||
|
||||
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;
|
||||
int b2Min = 0xa1;
|
||||
int b2Max = 0xfe;
|
||||
|
||||
try {
|
||||
int[][] db = new int[8][0x10000]; // doublebyte
|
||||
byte[] suppFlag = new byte[0x10000]; // doublebyte
|
||||
char[] indexC2B = new char[256];
|
||||
char[] indexC2BSupp = new char[256];
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 0x10000; j++)
|
||||
db[i][j] = UNMAPPABLE_DECODING;
|
||||
|
||||
Parser p = new Parser(is, euctw);
|
||||
Entry e = null;
|
||||
while ((e = p.next()) != null) {
|
||||
int plane = 0;
|
||||
if (e.bs >= 0x10000) {
|
||||
plane = ((e.bs >> 16) & 0xff) - 1;
|
||||
if (plane >= 14)
|
||||
plane = 7;
|
||||
e.bs = e.bs & 0xffff;
|
||||
}
|
||||
db[plane][e.bs] = e.cp;
|
||||
if (e.cp < 0x10000) {
|
||||
indexC2B[e.cp>>8] = 1;
|
||||
} else {
|
||||
indexC2BSupp[(e.cp&0xffff)>>8] = 1;
|
||||
suppFlag[e.bs] |= (1 << plane);
|
||||
}
|
||||
}
|
||||
|
||||
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 EUC_TWMapping {%n%n");
|
||||
|
||||
// boundaries
|
||||
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
|
||||
out.format("%n final static String[] b2c = {%n");
|
||||
for (int plane = 0; plane < 8; plane++) {
|
||||
out.format(" // Plane %d%n", plane);
|
||||
out.format(toCharArray(db[plane], b1Min, b1Max, b2Min, b2Max),
|
||||
",");
|
||||
out.format("%n");
|
||||
}
|
||||
out.format(" };%n");
|
||||
|
||||
// c2bIndex
|
||||
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
|
||||
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
|
||||
out.format("%n static String b2cIsSuppStr =%n");
|
||||
out.format(toCharArray(suppFlag, b1Min, b1Max, b2Min, b2Max),
|
||||
";");
|
||||
out.format("}");
|
||||
out.close();
|
||||
|
||||
ps.println(sb.toString());
|
||||
ps.close();
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,246 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* 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.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.util.Formatter;
|
||||
import java.util.regex.*;
|
||||
import java.nio.charset.*;
|
||||
import static build.tools.charsetmapping.CharsetMapping.*;
|
||||
|
||||
public class GenerateEUC_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)
|
||||
{
|
||||
char[] ca = new char[(b1Max - b1Min + 1) * (b2Max - b2Min + 1)];
|
||||
int off = 0;
|
||||
for (int b1 = b1Min; b1 <= b1Max; b1++) {
|
||||
for (int b2 = b2Min; b2 <= b2Max; b2++) {
|
||||
ca[off++] = (char)(db[b1 * 256 + b2] & 0xffff);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
char[] ca = new char[(b1Max - b1Min + 1) * (b2Max - b2Min + 1)];
|
||||
int off = 0;
|
||||
for (int b1 = b1Min; b1 <= b1Max; b1++) {
|
||||
int b2 = b2Min;
|
||||
while (b2 <= b2Max) {
|
||||
ca[off++] = (char)(((ba[b1 * 256 + b2++] & 0xff) << 8) |
|
||||
(ba[b1 * 256 + b2++] & 0xff));
|
||||
}
|
||||
}
|
||||
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++) {
|
||||
if (index[i] != 0) {
|
||||
index[i] = (char)off;
|
||||
off += 0x100;
|
||||
} else {
|
||||
index[i] = CharsetMapping.UNMAPPABLE_ENCODING;
|
||||
}
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
// ranges of byte1 and byte2, something should come from a "config" file
|
||||
int b1Min = 0xa1;
|
||||
int b1Max = 0xfe;
|
||||
int b2Min = 0xa1;
|
||||
int b2Max = 0xfe;
|
||||
|
||||
try {
|
||||
int[][] db = new int[8][0x10000]; // doublebyte
|
||||
byte[] suppFlag = new byte[0x10000]; // doublebyte
|
||||
char[] indexC2B = new char[256];
|
||||
char[] indexC2BSupp = new char[256];
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (int j = 0; j < 0x10000; j++)
|
||||
db[i][j] = CharsetMapping.UNMAPPABLE_DECODING;
|
||||
|
||||
CharsetMapping.Parser p = new CharsetMapping.Parser(is, euctw);
|
||||
CharsetMapping.Entry e = null;
|
||||
while ((e = p.next()) != null) {
|
||||
int plane = 0;
|
||||
if (e.bs >= 0x10000) {
|
||||
plane = ((e.bs >> 16) & 0xff) - 1;
|
||||
if (plane >= 14)
|
||||
plane = 7;
|
||||
e.bs = e.bs & 0xffff;
|
||||
}
|
||||
db[plane][e.bs] = e.cp;
|
||||
if (e.cp < 0x10000) {
|
||||
indexC2B[e.cp>>8] = 1;
|
||||
} else {
|
||||
indexC2BSupp[(e.cp&0xffff)>>8] = 1;
|
||||
suppFlag[e.bs] |= (1 << plane);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
Formatter fm = new Formatter(out);
|
||||
|
||||
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");
|
||||
|
||||
// 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);
|
||||
|
||||
// b2c tables
|
||||
fm.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");
|
||||
}
|
||||
fm.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");
|
||||
|
||||
// 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");
|
||||
|
||||
// suppFlags
|
||||
fm.format("%n static String b2cIsSuppStr =%n");
|
||||
toString(fm, toCharArray(suppFlag,
|
||||
b1Min, b1Max, b2Min, b2Max),
|
||||
";");
|
||||
|
||||
fm.format("}");
|
||||
fm.close();
|
||||
|
||||
ps.println(out.toString());
|
||||
ps.close();
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
}
|
190
jdk/make/tools/src/build/tools/charsetmapping/HKSCS.java
Normal file
190
jdk/make/tools/src/build/tools/charsetmapping/HKSCS.java
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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();
|
221
jdk/make/tools/src/build/tools/charsetmapping/Utils.java
Normal file
221
jdk/make/tools/src/build/tools/charsetmapping/Utils.java
Normal file
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* 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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2006 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 1996-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
|
||||
@ -72,7 +72,8 @@ package java.util.zip;
|
||||
*/
|
||||
public
|
||||
class Deflater {
|
||||
private long strm;
|
||||
|
||||
private final ZStreamRef zsRef;
|
||||
private byte[] buf = new byte[0];
|
||||
private int off, len;
|
||||
private int level, strategy;
|
||||
@ -165,7 +166,7 @@ class Deflater {
|
||||
public Deflater(int level, boolean nowrap) {
|
||||
this.level = level;
|
||||
this.strategy = DEFAULT_STRATEGY;
|
||||
strm = init(level, DEFAULT_STRATEGY, nowrap);
|
||||
this.zsRef = new ZStreamRef(init(level, DEFAULT_STRATEGY, nowrap));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,16 +194,18 @@ class Deflater {
|
||||
* @param len the length of the data
|
||||
* @see Deflater#needsInput
|
||||
*/
|
||||
public synchronized void setInput(byte[] b, int off, int len) {
|
||||
public void setInput(byte[] b, int off, int len) {
|
||||
if (b== null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (off < 0 || len < 0 || off > b.length - len) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
this.buf = b;
|
||||
this.off = off;
|
||||
this.len = len;
|
||||
synchronized (zsRef) {
|
||||
this.buf = b;
|
||||
this.off = off;
|
||||
this.len = len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,14 +230,17 @@ class Deflater {
|
||||
* @see Inflater#inflate
|
||||
* @see Inflater#getAdler
|
||||
*/
|
||||
public synchronized void setDictionary(byte[] b, int off, int len) {
|
||||
if (strm == 0 || b == null) {
|
||||
public void setDictionary(byte[] b, int off, int len) {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (off < 0 || len < 0 || off > b.length - len) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
setDictionary(strm, b, off, len);
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
setDictionary(zsRef.address(), b, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -257,7 +263,7 @@ class Deflater {
|
||||
* @exception IllegalArgumentException if the compression strategy is
|
||||
* invalid
|
||||
*/
|
||||
public synchronized void setStrategy(int strategy) {
|
||||
public void setStrategy(int strategy) {
|
||||
switch (strategy) {
|
||||
case DEFAULT_STRATEGY:
|
||||
case FILTERED:
|
||||
@ -266,9 +272,11 @@ class Deflater {
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (this.strategy != strategy) {
|
||||
this.strategy = strategy;
|
||||
setParams = true;
|
||||
synchronized (zsRef) {
|
||||
if (this.strategy != strategy) {
|
||||
this.strategy = strategy;
|
||||
setParams = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,13 +285,15 @@ class Deflater {
|
||||
* @param level the new compression level (0-9)
|
||||
* @exception IllegalArgumentException if the compression level is invalid
|
||||
*/
|
||||
public synchronized void setLevel(int level) {
|
||||
public void setLevel(int level) {
|
||||
if ((level < 0 || level > 9) && level != DEFAULT_COMPRESSION) {
|
||||
throw new IllegalArgumentException("invalid compression level");
|
||||
}
|
||||
if (this.level != level) {
|
||||
this.level = level;
|
||||
setParams = true;
|
||||
synchronized (zsRef) {
|
||||
if (this.level != level) {
|
||||
this.level = level;
|
||||
setParams = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,8 +311,10 @@ class Deflater {
|
||||
* When called, indicates that compression should end with the current
|
||||
* contents of the input buffer.
|
||||
*/
|
||||
public synchronized void finish() {
|
||||
finish = true;
|
||||
public void finish() {
|
||||
synchronized (zsRef) {
|
||||
finish = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,8 +323,10 @@ class Deflater {
|
||||
* @return true if the end of the compressed data output stream has
|
||||
* been reached
|
||||
*/
|
||||
public synchronized boolean finished() {
|
||||
return finished;
|
||||
public boolean finished() {
|
||||
synchronized (zsRef) {
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,26 +413,31 @@ class Deflater {
|
||||
* @throws IllegalArgumentException if the flush mode is invalid
|
||||
* @since 1.7
|
||||
*/
|
||||
public synchronized int deflate(byte[] b, int off, int len, int flush) {
|
||||
public int deflate(byte[] b, int off, int len, int flush) {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (off < 0 || len < 0 || off > b.length - len) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
if (flush == NO_FLUSH || flush == SYNC_FLUSH ||
|
||||
flush == FULL_FLUSH)
|
||||
return deflateBytes(b, off, len, flush);
|
||||
throw new IllegalArgumentException();
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
if (flush == NO_FLUSH || flush == SYNC_FLUSH ||
|
||||
flush == FULL_FLUSH)
|
||||
return deflateBytes(zsRef.address(), b, off, len, flush);
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ADLER-32 value of the uncompressed data.
|
||||
* @return the ADLER-32 value of the uncompressed data
|
||||
*/
|
||||
public synchronized int getAdler() {
|
||||
ensureOpen();
|
||||
return getAdler(strm);
|
||||
public int getAdler() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return getAdler(zsRef.address());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -440,9 +459,11 @@ class Deflater {
|
||||
* @return the total (non-negative) number of uncompressed bytes input so far
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized long getBytesRead() {
|
||||
ensureOpen();
|
||||
return getBytesRead(strm);
|
||||
public long getBytesRead() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return getBytesRead(zsRef.address());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -464,21 +485,25 @@ class Deflater {
|
||||
* @return the total (non-negative) number of compressed bytes output so far
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized long getBytesWritten() {
|
||||
ensureOpen();
|
||||
return getBytesWritten(strm);
|
||||
public long getBytesWritten() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return getBytesWritten(zsRef.address());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets deflater so that a new set of input data can be processed.
|
||||
* Keeps current compression level and strategy settings.
|
||||
*/
|
||||
public synchronized void reset() {
|
||||
ensureOpen();
|
||||
reset(strm);
|
||||
finish = false;
|
||||
finished = false;
|
||||
off = len = 0;
|
||||
public void reset() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
reset(zsRef.address());
|
||||
finish = false;
|
||||
finished = false;
|
||||
off = len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -488,11 +513,14 @@ class Deflater {
|
||||
* finalize() method. Once this method is called, the behavior
|
||||
* of the Deflater object is undefined.
|
||||
*/
|
||||
public synchronized void end() {
|
||||
if (strm != 0) {
|
||||
end(strm);
|
||||
strm = 0;
|
||||
buf = null;
|
||||
public void end() {
|
||||
synchronized (zsRef) {
|
||||
long addr = zsRef.address();
|
||||
zsRef.clear();
|
||||
if (addr != 0) {
|
||||
end(addr);
|
||||
buf = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -504,18 +532,19 @@ class Deflater {
|
||||
}
|
||||
|
||||
private void ensureOpen() {
|
||||
if (strm == 0)
|
||||
throw new NullPointerException();
|
||||
assert Thread.holdsLock(zsRef);
|
||||
if (zsRef.address() == 0)
|
||||
throw new NullPointerException("Deflater has been closed");
|
||||
}
|
||||
|
||||
private static native void initIDs();
|
||||
private native static long init(int level, int strategy, boolean nowrap);
|
||||
private native static void setDictionary(long strm, byte[] b, int off,
|
||||
int len);
|
||||
private native int deflateBytes(byte[] b, int off, int len, int flush);
|
||||
private native static int getAdler(long strm);
|
||||
private native static long getBytesRead(long strm);
|
||||
private native static long getBytesWritten(long strm);
|
||||
private native static void reset(long strm);
|
||||
private native static void end(long strm);
|
||||
private native static void setDictionary(long addr, byte[] b, int off, int len);
|
||||
private native int deflateBytes(long addr, byte[] b, int off, int len,
|
||||
int flush);
|
||||
private native static int getAdler(long addr);
|
||||
private native static long getBytesRead(long addr);
|
||||
private native static long getBytesWritten(long addr);
|
||||
private native static void reset(long addr);
|
||||
private native static void end(long addr);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 1996-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
|
||||
@ -72,7 +72,8 @@ package java.util.zip;
|
||||
*/
|
||||
public
|
||||
class Inflater {
|
||||
private long strm;
|
||||
|
||||
private final ZStreamRef zsRef;
|
||||
private byte[] buf = defaultBuf;
|
||||
private int off, len;
|
||||
private boolean finished;
|
||||
@ -97,7 +98,7 @@ class Inflater {
|
||||
* @param nowrap if true then support GZIP compatible compression
|
||||
*/
|
||||
public Inflater(boolean nowrap) {
|
||||
strm = init(nowrap);
|
||||
zsRef = new ZStreamRef(init(nowrap));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,16 +117,18 @@ class Inflater {
|
||||
* @param len the length of the input data
|
||||
* @see Inflater#needsInput
|
||||
*/
|
||||
public synchronized void setInput(byte[] b, int off, int len) {
|
||||
public void setInput(byte[] b, int off, int len) {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (off < 0 || len < 0 || off > b.length - len) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
this.buf = b;
|
||||
this.off = off;
|
||||
this.len = len;
|
||||
synchronized (zsRef) {
|
||||
this.buf = b;
|
||||
this.off = off;
|
||||
this.len = len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,15 +153,18 @@ class Inflater {
|
||||
* @see Inflater#needsDictionary
|
||||
* @see Inflater#getAdler
|
||||
*/
|
||||
public synchronized void setDictionary(byte[] b, int off, int len) {
|
||||
if (strm == 0 || b == null) {
|
||||
public void setDictionary(byte[] b, int off, int len) {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
if (off < 0 || len < 0 || off > b.length - len) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
setDictionary(strm, b, off, len);
|
||||
needDict = false;
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
setDictionary(zsRef.address(), b, off, len);
|
||||
needDict = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,8 +186,10 @@ class Inflater {
|
||||
* buffer after decompression has finished.
|
||||
* @return the total number of bytes remaining in the input buffer
|
||||
*/
|
||||
public synchronized int getRemaining() {
|
||||
return len;
|
||||
public int getRemaining() {
|
||||
synchronized (zsRef) {
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,8 +198,10 @@ class Inflater {
|
||||
* to provide more input.
|
||||
* @return true if no data remains in the input buffer
|
||||
*/
|
||||
public synchronized boolean needsInput() {
|
||||
return len <= 0;
|
||||
public boolean needsInput() {
|
||||
synchronized (zsRef) {
|
||||
return len <= 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,8 +209,10 @@ class Inflater {
|
||||
* @return true if a preset dictionary is needed for decompression
|
||||
* @see Inflater#setDictionary
|
||||
*/
|
||||
public synchronized boolean needsDictionary() {
|
||||
return needDict;
|
||||
public boolean needsDictionary() {
|
||||
synchronized (zsRef) {
|
||||
return needDict;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -209,8 +221,10 @@ class Inflater {
|
||||
* @return true if the end of the compressed data stream has been
|
||||
* reached
|
||||
*/
|
||||
public synchronized boolean finished() {
|
||||
return finished;
|
||||
public boolean finished() {
|
||||
synchronized (zsRef) {
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +242,7 @@ class Inflater {
|
||||
* @see Inflater#needsInput
|
||||
* @see Inflater#needsDictionary
|
||||
*/
|
||||
public synchronized int inflate(byte[] b, int off, int len)
|
||||
public int inflate(byte[] b, int off, int len)
|
||||
throws DataFormatException
|
||||
{
|
||||
if (b == null) {
|
||||
@ -237,7 +251,10 @@ class Inflater {
|
||||
if (off < 0 || len < 0 || off > b.length - len) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
return inflateBytes(b, off, len);
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return inflateBytes(zsRef.address(), b, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,9 +278,11 @@ class Inflater {
|
||||
* Returns the ADLER-32 value of the uncompressed data.
|
||||
* @return the ADLER-32 value of the uncompressed data
|
||||
*/
|
||||
public synchronized int getAdler() {
|
||||
ensureOpen();
|
||||
return getAdler(strm);
|
||||
public int getAdler() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return getAdler(zsRef.address());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,9 +304,11 @@ class Inflater {
|
||||
* @return the total (non-negative) number of compressed bytes input so far
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized long getBytesRead() {
|
||||
ensureOpen();
|
||||
return getBytesRead(strm);
|
||||
public long getBytesRead() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return getBytesRead(zsRef.address());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,21 +330,25 @@ class Inflater {
|
||||
* @return the total (non-negative) number of uncompressed bytes output so far
|
||||
* @since 1.5
|
||||
*/
|
||||
public synchronized long getBytesWritten() {
|
||||
ensureOpen();
|
||||
return getBytesWritten(strm);
|
||||
public long getBytesWritten() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
return getBytesWritten(zsRef.address());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets inflater so that a new set of input data can be processed.
|
||||
*/
|
||||
public synchronized void reset() {
|
||||
ensureOpen();
|
||||
reset(strm);
|
||||
buf = defaultBuf;
|
||||
finished = false;
|
||||
needDict = false;
|
||||
off = len = 0;
|
||||
public void reset() {
|
||||
synchronized (zsRef) {
|
||||
ensureOpen();
|
||||
reset(zsRef.address());
|
||||
buf = defaultBuf;
|
||||
finished = false;
|
||||
needDict = false;
|
||||
off = len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,11 +358,14 @@ class Inflater {
|
||||
* method. Once this method is called, the behavior of the Inflater
|
||||
* object is undefined.
|
||||
*/
|
||||
public synchronized void end() {
|
||||
if (strm != 0) {
|
||||
end(strm);
|
||||
strm = 0;
|
||||
buf = null;
|
||||
public void end() {
|
||||
synchronized (zsRef) {
|
||||
long addr = zsRef.address();
|
||||
zsRef.clear();
|
||||
if (addr != 0) {
|
||||
end(addr);
|
||||
buf = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,19 +377,20 @@ class Inflater {
|
||||
}
|
||||
|
||||
private void ensureOpen () {
|
||||
if (strm == 0)
|
||||
throw new NullPointerException();
|
||||
assert Thread.holdsLock(zsRef);
|
||||
if (zsRef.address() == 0)
|
||||
throw new NullPointerException("Inflater has been closed");
|
||||
}
|
||||
|
||||
private native static void initIDs();
|
||||
private native static long init(boolean nowrap);
|
||||
private native static void setDictionary(long strm, byte[] b, int off,
|
||||
private native static void setDictionary(long addr, byte[] b, int off,
|
||||
int len);
|
||||
private native int inflateBytes(byte[] b, int off, int len)
|
||||
private native int inflateBytes(long addr, byte[] b, int off, int len)
|
||||
throws DataFormatException;
|
||||
private native static int getAdler(long strm);
|
||||
private native static long getBytesRead(long strm);
|
||||
private native static long getBytesWritten(long strm);
|
||||
private native static void reset(long strm);
|
||||
private native static void end(long strm);
|
||||
private native static int getAdler(long addr);
|
||||
private native static long getBytesRead(long addr);
|
||||
private native static long getBytesWritten(long addr);
|
||||
private native static void reset(long addr);
|
||||
private native static void end(long addr);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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 {
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "HKSCS";
|
||||
private long address;
|
||||
ZStreamRef (long address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public CharToByteHKSCS() {
|
||||
super.index1 = HKSCS.getEncoderIndex1();
|
||||
super.index2 = HKSCS.getEncoderIndex2();
|
||||
long address() {
|
||||
return address;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1271,6 +1271,7 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
|
||||
*
|
||||
* @return a String representation of this object.
|
||||
**/
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + ": connectionId=" + connectionId;
|
||||
}
|
||||
@ -1514,6 +1515,21 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SetCcl implements PrivilegedExceptionAction<ClassLoader> {
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
SetCcl(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public ClassLoader run() {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
ClassLoader old = currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(classLoader);
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T unwrap(final MarshalledObject<?> mo,
|
||||
final ClassLoader cl,
|
||||
final Class<T> wrappedClass)
|
||||
@ -1522,22 +1538,14 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<T>() {
|
||||
public T run()
|
||||
throws IOException {
|
||||
final ClassLoader old =
|
||||
Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
try {
|
||||
return wrappedClass.cast(mo.get());
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new UnmarshalException(cnfe.toString(), cnfe);
|
||||
} finally {
|
||||
Thread.currentThread().setContextClassLoader(old);
|
||||
}
|
||||
}
|
||||
});
|
||||
final ClassLoader old = AccessController.doPrivileged(new SetCcl(cl));
|
||||
try {
|
||||
return wrappedClass.cast(mo.get());
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new UnmarshalException(cnfe.toString(), cnfe);
|
||||
} finally {
|
||||
AccessController.doPrivileged(new SetCcl(old));
|
||||
}
|
||||
} catch (PrivilegedActionException pe) {
|
||||
Exception e = extractException(pe);
|
||||
if (e instanceof IOException) {
|
||||
@ -1561,14 +1569,14 @@ public class RMIConnectionImpl implements RMIConnection, Unreferenced {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<T>() {
|
||||
public T run()
|
||||
throws IOException {
|
||||
return unwrap(mo, new OrderClassLoaders(cl1, cl2),
|
||||
wrappedClass);
|
||||
}
|
||||
});
|
||||
ClassLoader orderCL = AccessController.doPrivileged(
|
||||
new PrivilegedExceptionAction<ClassLoader>() {
|
||||
public ClassLoader run() throws Exception {
|
||||
return new OrderClassLoaders(cl1, cl2);
|
||||
}
|
||||
}
|
||||
);
|
||||
return unwrap(mo, orderCL, wrappedClass);
|
||||
} catch (PrivilegedActionException pe) {
|
||||
Exception e = extractException(pe);
|
||||
if (e instanceof IOException) {
|
||||
|
@ -27,8 +27,10 @@
|
||||
package javax.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.*;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* This class creates sockets. It may be subclassed by other factories,
|
||||
@ -113,7 +115,17 @@ public abstract class SocketFactory
|
||||
* @see java.net.Socket#Socket()
|
||||
*/
|
||||
public Socket createSocket() throws IOException {
|
||||
throw new SocketException("Unconnected sockets not implemented");
|
||||
//
|
||||
// bug 6771432:
|
||||
// The Exception is used by HttpsClient to signal that
|
||||
// unconnected sockets have not been implemented.
|
||||
//
|
||||
UnsupportedOperationException uop = new
|
||||
UnsupportedOperationException();
|
||||
SocketException se = new SocketException(
|
||||
"Unconnected sockets not implemented");
|
||||
se.initCause(uop);
|
||||
throw se;
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,7 +34,7 @@ import java.nio.charset.CharsetDecoder;
|
||||
ExtendedCharsets class, because if we want to have a public HKSCS,
|
||||
it probably should be HKSCS_2001 not HKSCS.
|
||||
*/
|
||||
public class HKSCS extends sun.nio.cs.ext.HKSCS {
|
||||
public class HKSCS extends sun.nio.cs.ext.MS950_HKSCS_XP {
|
||||
public HKSCS () {
|
||||
super();
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ import sun.awt.AppContext;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.datatransfer.DataTransferer;
|
||||
import sun.awt.datatransfer.ToolkitThreadBlockedHandler;
|
||||
import sun.security.util.SecurityConstants;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -216,6 +217,18 @@ public abstract class SunDropTargetContextPeer implements DropTargetContextPeer,
|
||||
throws UnsupportedFlavorException, IOException,
|
||||
InvalidDnDOperationException
|
||||
{
|
||||
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
try {
|
||||
if (!dropComplete && sm != null) {
|
||||
sm.checkSystemClipboardAccess();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
Long lFormat = null;
|
||||
Transferable localTransferable = local;
|
||||
|
||||
|
@ -333,10 +333,10 @@ public class ImageRepresentation extends ImageWatched implements ImageConsumer
|
||||
hints = h;
|
||||
}
|
||||
|
||||
public native void setICMpixels(int x, int y, int w, int h, int[] lut,
|
||||
private native void setICMpixels(int x, int y, int w, int h, int[] lut,
|
||||
byte[] pix, int off, int scansize,
|
||||
IntegerComponentRaster ict);
|
||||
public native int setDiffICM(int x, int y, int w, int h, int[] lut,
|
||||
private native int setDiffICM(int x, int y, int w, int h, int[] lut,
|
||||
int transPix, int numLut, IndexColorModel icm,
|
||||
byte[] pix, int off, int scansize,
|
||||
ByteComponentRaster bct, int chanOff);
|
||||
@ -361,6 +361,64 @@ public class ImageRepresentation extends ImageWatched implements ImageConsumer
|
||||
}
|
||||
createBufferedImage();
|
||||
}
|
||||
|
||||
if (w <= 0 || h <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int biWidth = biRaster.getWidth();
|
||||
int biHeight = biRaster.getHeight();
|
||||
|
||||
int x1 = x+w; // Overflow protection below
|
||||
int y1 = y+h; // Overflow protection below
|
||||
if (x < 0) {
|
||||
off -= x;
|
||||
x = 0;
|
||||
} else if (x1 < 0) {
|
||||
x1 = biWidth; // Must be overflow
|
||||
}
|
||||
if (y < 0) {
|
||||
off -= y*scansize;
|
||||
y = 0;
|
||||
} else if (y1 < 0) {
|
||||
y1 = biHeight; // Must be overflow
|
||||
}
|
||||
if (x1 > biWidth) {
|
||||
x1 = biWidth;
|
||||
}
|
||||
if (y1 > biHeight) {
|
||||
y1 = biHeight;
|
||||
}
|
||||
if (x >= x1 || y >= y1) {
|
||||
return;
|
||||
}
|
||||
// x,y,x1,y1 are all >= 0, so w,h must be >= 0
|
||||
w = x1-x;
|
||||
h = y1-y;
|
||||
// off is first pixel read so it must be in bounds
|
||||
if (off < 0 || off >= pix.length) {
|
||||
// They overflowed their own array
|
||||
throw new ArrayIndexOutOfBoundsException("Data offset out of bounds.");
|
||||
}
|
||||
// pix.length and off are >= 0 so remainder >= 0
|
||||
int remainder = pix.length - off;
|
||||
if (remainder < w) {
|
||||
// They overflowed their own array
|
||||
throw new ArrayIndexOutOfBoundsException("Data array is too short.");
|
||||
}
|
||||
int num;
|
||||
if (scansize < 0) {
|
||||
num = (off / -scansize) + 1;
|
||||
} else if (scansize > 0) {
|
||||
num = ((remainder-w) / scansize) + 1;
|
||||
} else {
|
||||
num = h;
|
||||
}
|
||||
if (h > num) {
|
||||
// They overflowed their own array.
|
||||
throw new ArrayIndexOutOfBoundsException("Data array is too short.");
|
||||
}
|
||||
|
||||
if (isSameCM && (cmodel != model) && (srcLUT != null) &&
|
||||
(model instanceof IndexColorModel) &&
|
||||
(biRaster instanceof ByteComponentRaster))
|
||||
|
@ -26,26 +26,24 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
import sun.nio.cs.ext.DoubleByte;
|
||||
import sun.nio.cs.ext.Big5;
|
||||
|
||||
/**
|
||||
* Tables and data to convert Big5 to Unicode
|
||||
*
|
||||
* @author ConverterGenerator tool
|
||||
*/
|
||||
|
||||
public class ByteToCharBig5 extends ByteToCharDoubleByte {
|
||||
public class ByteToCharBig5 extends ByteToCharDBCS_ASCII {
|
||||
|
||||
private final static Big5 nioCoder = new Big5();
|
||||
private static DoubleByte.Decoder dec =
|
||||
(DoubleByte.Decoder)new Big5().newDecoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "Big5";
|
||||
}
|
||||
|
||||
public ByteToCharBig5() {
|
||||
super.index1 = nioCoder.getDecoderIndex1();
|
||||
super.index2 = nioCoder.getDecoderIndex2();
|
||||
start = 0x40;
|
||||
end = 0xFE;
|
||||
super(dec);
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,28 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
public class ByteToCharBig5_HKSCS extends ByteToCharHKSCS_2001 {
|
||||
ByteToCharBig5 bcBig5 = new ByteToCharBig5();
|
||||
import sun.nio.cs.ext.Big5_HKSCS;
|
||||
import sun.nio.cs.ext.HKSCS;
|
||||
import static sun.nio.cs.CharsetMapping.*;
|
||||
|
||||
public class ByteToCharBig5_HKSCS extends ByteToCharDBCS_ASCII {
|
||||
|
||||
protected static HKSCS.Decoder dec =
|
||||
(HKSCS.Decoder)new Big5_HKSCS().newDecoder();
|
||||
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "Big5_HKSCS";
|
||||
}
|
||||
|
||||
protected char getUnicode(int byte1, int byte2) {
|
||||
char c = super.getUnicode(byte1, byte2);
|
||||
return (c != REPLACE_CHAR) ? c : bcBig5.getUnicode(byte1, byte2);
|
||||
public ByteToCharBig5_HKSCS() {
|
||||
super(dec);
|
||||
}
|
||||
|
||||
protected char decodeDouble(int byte1, int byte2) {
|
||||
char c = dec.decodeDouble(byte1, byte2);
|
||||
if (c == UNMAPPABLE_DECODING)
|
||||
c = dec.decodeBig5(byte1, byte2);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@ -25,49 +25,19 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ByteToCharBig5_Solaris extends ByteToCharBig5 {
|
||||
public ByteToCharBig5_Solaris() {}
|
||||
import sun.nio.cs.ext.DoubleByte;
|
||||
import sun.nio.cs.ext.Big5_Solaris;
|
||||
|
||||
public class ByteToCharBig5_Solaris extends ByteToCharDBCS_ASCII {
|
||||
|
||||
private static DoubleByte.Decoder dec =
|
||||
(DoubleByte.Decoder)new Big5_Solaris().newDecoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "Big5_Solaris";
|
||||
}
|
||||
|
||||
protected char getUnicode(int byte1, int byte2) {
|
||||
//
|
||||
char c = super.getUnicode(byte1, byte2);
|
||||
if (c == REPLACE_CHAR) {
|
||||
if (byte1 == 0xf9) {
|
||||
switch (byte2) {
|
||||
case 0xD6:
|
||||
c = (char)0x7881;
|
||||
break;
|
||||
case 0xD7:
|
||||
c = (char)0x92B9;
|
||||
break;
|
||||
case 0xD8:
|
||||
c = (char)0x88CF;
|
||||
break;
|
||||
case 0xD9:
|
||||
c = (char)0x58BB;
|
||||
break;
|
||||
case 0xDA:
|
||||
c = (char)0x6052;
|
||||
break;
|
||||
case 0xDB:
|
||||
c = (char)0x7CA7;
|
||||
break;
|
||||
case 0xDC:
|
||||
c = (char)0x5AFA;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return c;
|
||||
public ByteToCharBig5_Solaris() {
|
||||
super(dec);
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2007 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 sun.io;
|
||||
|
||||
import sun.nio.cs.ext.HKSCS_2001;
|
||||
|
||||
/**
|
||||
* Tables and data to convert HKSCS (2001 revision) to Unicode
|
||||
*
|
||||
* @author ConverterGenerator tool
|
||||
*/
|
||||
|
||||
public class ByteToCharHKSCS_2001 extends ByteToCharDoubleByte {
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "HKSCS_2001";
|
||||
}
|
||||
|
||||
public ByteToCharHKSCS_2001() {
|
||||
super.index1 = HKSCS_2001.getDecoderIndex1();
|
||||
super.index2= HKSCS_2001.getDecoderIndex2();
|
||||
start = 0x40;
|
||||
end = 0xFE;
|
||||
}
|
||||
}
|
@ -25,15 +25,27 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
public class ByteToCharMS950_HKSCS extends ByteToCharHKSCS {
|
||||
ByteToCharMS950 bcMS950 = new ByteToCharMS950();
|
||||
import sun.nio.cs.ext.HKSCS;
|
||||
import sun.nio.cs.ext.MS950_HKSCS;
|
||||
import static sun.nio.cs.CharsetMapping.*;
|
||||
|
||||
public class ByteToCharMS950_HKSCS extends ByteToCharDBCS_ASCII {
|
||||
|
||||
private static HKSCS.Decoder dec =
|
||||
(HKSCS.Decoder)new MS950_HKSCS().newDecoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "MS950_HKSCS";
|
||||
}
|
||||
|
||||
protected char getUnicode(int byte1, int byte2) {
|
||||
char c = super.getUnicode(byte1, byte2);
|
||||
return (c != REPLACE_CHAR) ? c : bcMS950.decodeDouble(byte1, byte2);
|
||||
public ByteToCharMS950_HKSCS() {
|
||||
super(dec);
|
||||
}
|
||||
|
||||
protected char decodeDouble(int byte1, int byte2) {
|
||||
char c = dec.decodeDouble(byte1, byte2);
|
||||
if (c == UNMAPPABLE_DECODING)
|
||||
c = dec.decodeBig5(byte1, byte2);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@ -26,24 +26,24 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
import sun.nio.cs.ext.DoubleByte;
|
||||
import sun.nio.cs.ext.Big5;
|
||||
|
||||
/**
|
||||
* Tables and data to convert Unicode to Big5
|
||||
*
|
||||
* @author ConverterGenerator tool
|
||||
*/
|
||||
|
||||
public class CharToByteBig5 extends CharToByteDoubleByte {
|
||||
public class CharToByteBig5 extends CharToByteDBCS_ASCII {
|
||||
|
||||
private static final Big5 nioCoder = new Big5();
|
||||
private static DoubleByte.Encoder enc =
|
||||
(DoubleByte.Encoder)new Big5().newEncoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "Big5";
|
||||
}
|
||||
|
||||
public CharToByteBig5() {
|
||||
super.index1 = nioCoder.getEncoderIndex1();
|
||||
super.index2 = nioCoder.getEncoderIndex2();
|
||||
super(enc);
|
||||
}
|
||||
}
|
||||
|
@ -25,15 +25,18 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
public class CharToByteBig5_HKSCS extends CharToByteHKSCS_2001 {
|
||||
CharToByteBig5 cbBig5 = new CharToByteBig5();
|
||||
import sun.nio.cs.ext.DoubleByte;
|
||||
import sun.nio.cs.ext.Big5_HKSCS;
|
||||
|
||||
public class CharToByteBig5_HKSCS extends CharToByteDBCS_ASCII {
|
||||
private static DoubleByte.Encoder enc =
|
||||
(DoubleByte.Encoder)new Big5_HKSCS().newEncoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "Big5_HKSCS";
|
||||
}
|
||||
|
||||
protected int getNative(char ch) {
|
||||
int r = super.getNative(ch);
|
||||
return (r != 0) ? r : cbBig5.getNative(ch);
|
||||
public CharToByteBig5_HKSCS() {
|
||||
super(enc);
|
||||
}
|
||||
}
|
||||
|
@ -23,48 +23,21 @@
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
|
||||
package sun.io;
|
||||
|
||||
/**
|
||||
*/
|
||||
import sun.nio.cs.ext.DoubleByte;
|
||||
import sun.nio.cs.ext.Big5_Solaris;
|
||||
|
||||
public class CharToByteBig5_Solaris extends CharToByteBig5 {
|
||||
public class CharToByteBig5_Solaris extends CharToByteDBCS_ASCII {
|
||||
|
||||
private static DoubleByte.Encoder enc =
|
||||
(DoubleByte.Encoder)new Big5_Solaris().newEncoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "Big5_Solaris";
|
||||
}
|
||||
|
||||
protected int getNative(char ch) {
|
||||
int nativeVal;
|
||||
|
||||
if ((nativeVal = super.getNative(ch)) != 0) {
|
||||
return nativeVal;
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case 0x7881:
|
||||
nativeVal = 0xF9D6;
|
||||
break;
|
||||
case 0x92B9:
|
||||
nativeVal = 0xF9D7;
|
||||
break;
|
||||
case 0x88CF:
|
||||
nativeVal = 0xF9D8;
|
||||
break;
|
||||
case 0x58BB:
|
||||
nativeVal = 0xF9D9;
|
||||
break;
|
||||
case 0x6052:
|
||||
nativeVal = 0xF9DA;
|
||||
break;
|
||||
case 0x7CA7:
|
||||
nativeVal = 0xF9DB;
|
||||
break;
|
||||
case 0x5AFA:
|
||||
nativeVal = 0xF9DC;
|
||||
break;
|
||||
}
|
||||
return nativeVal;
|
||||
public CharToByteBig5_Solaris() {
|
||||
super(enc);
|
||||
}
|
||||
}
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003 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 sun.io;
|
||||
|
||||
import sun.nio.cs.ext.HKSCS_2001;
|
||||
|
||||
/**
|
||||
* Tables and data to convert Unicode to HKSCS (2001 revision)
|
||||
*
|
||||
* @author ConverterGenerator tool
|
||||
*/
|
||||
|
||||
public class CharToByteHKSCS_2001 extends CharToByteDoubleByte {
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "HKSCS_2001";
|
||||
}
|
||||
|
||||
public CharToByteHKSCS_2001() {
|
||||
super.index1 = HKSCS_2001.getEncoderIndex1();
|
||||
super.index2 = HKSCS_2001.getEncoderIndex2();
|
||||
}
|
||||
}
|
@ -25,15 +25,19 @@
|
||||
|
||||
package sun.io;
|
||||
|
||||
public class CharToByteMS950_HKSCS extends CharToByteHKSCS {
|
||||
CharToByteMS950 cbMS950 = new CharToByteMS950();
|
||||
import sun.nio.cs.ext.DoubleByte;
|
||||
import sun.nio.cs.ext.MS950_HKSCS;
|
||||
|
||||
public class CharToByteMS950_HKSCS extends CharToByteDBCS_ASCII {
|
||||
|
||||
private static DoubleByte.Encoder enc =
|
||||
(DoubleByte.Encoder)new MS950_HKSCS().newEncoder();
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "MS950_HKSCS";
|
||||
}
|
||||
|
||||
protected int getNative(char ch) {
|
||||
int r = super.getNative(ch);
|
||||
return (r != 0) ? r : cbMS950.encodeChar(ch);
|
||||
public CharToByteMS950_HKSCS() {
|
||||
super(enc);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2001-2007 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
|
||||
@ -22,27 +22,18 @@
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
package sun.misc;
|
||||
|
||||
package sun.io;
|
||||
import java.security.PermissionCollection;
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import sun.nio.cs.ext.HKSCS;
|
||||
|
||||
/**
|
||||
* Tables and data to convert HKSCS to Unicode
|
||||
*
|
||||
* @author ConverterGenerator tool
|
||||
*/
|
||||
|
||||
public class ByteToCharHKSCS extends ByteToCharDoubleByte {
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
return "HKSCS";
|
||||
}
|
||||
|
||||
public ByteToCharHKSCS() {
|
||||
super.index1 = HKSCS.getDecoderIndex1();
|
||||
super.index2= HKSCS.getDecoderIndex2();
|
||||
start = 0x40;
|
||||
end = 0xFE;
|
||||
public interface JavaSecurityProtectionDomainAccess {
|
||||
interface ProtectionDomainCache {
|
||||
void put(ProtectionDomain pd, PermissionCollection pc);
|
||||
PermissionCollection get(ProtectionDomain pd);
|
||||
}
|
||||
/**
|
||||
* Returns the ProtectionDomainCache.
|
||||
*/
|
||||
ProtectionDomainCache getProtectionDomainCache();
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2002-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
|
||||
@ -47,6 +47,7 @@ public class SharedSecrets {
|
||||
private static JavaNetAccess javaNetAccess;
|
||||
private static JavaNioAccess javaNioAccess;
|
||||
private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
|
||||
private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
|
||||
|
||||
public static JavaUtilJarAccess javaUtilJarAccess() {
|
||||
if (javaUtilJarAccess == null) {
|
||||
@ -113,4 +114,13 @@ public class SharedSecrets {
|
||||
return javaIOFileDescriptorAccess;
|
||||
}
|
||||
|
||||
public static void setJavaSecurityProtectionDomainAccess
|
||||
(JavaSecurityProtectionDomainAccess jspda) {
|
||||
javaSecurityProtectionDomainAccess = jspda;
|
||||
}
|
||||
|
||||
public static JavaSecurityProtectionDomainAccess
|
||||
getJavaSecurityProtectionDomainAccess() {
|
||||
return javaSecurityProtectionDomainAccess;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import java.net.Socket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URL;
|
||||
import java.net.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.security.AccessController;
|
||||
@ -157,10 +156,15 @@ public class NetworkClient {
|
||||
public Socket run() {
|
||||
return new Socket(proxy);
|
||||
}});
|
||||
} else
|
||||
} else if (proxy.type() == Proxy.Type.DIRECT) {
|
||||
s = createSocket();
|
||||
} else {
|
||||
// Still connecting through a proxy
|
||||
// server & port will be the proxy address and port
|
||||
s = new Socket(Proxy.NO_PROXY);
|
||||
}
|
||||
} else
|
||||
s = new Socket();
|
||||
s = createSocket();
|
||||
// Instance specific timeouts do have priority, that means
|
||||
// connectTimeout & readTimeout (-1 means not set)
|
||||
// Then global default timeouts
|
||||
@ -182,6 +186,15 @@ public class NetworkClient {
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* The following method, createSocket, is provided to allow the
|
||||
* https client to override it so that it may use its socket factory
|
||||
* to create the socket.
|
||||
*/
|
||||
protected Socket createSocket() throws IOException {
|
||||
return new java.net.Socket();
|
||||
}
|
||||
|
||||
protected InetAddress getLocalAddress() throws IOException {
|
||||
if (serverSocket == null)
|
||||
throw new IOException("not connected");
|
||||
|
@ -270,13 +270,17 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
|
||||
* In this case we do not use the path because the protection space
|
||||
* is identified by the host:port:realm only
|
||||
*/
|
||||
static AuthenticationInfo getServerAuth(URL url, String realm, AuthScheme scheme) {
|
||||
static String getServerAuthKey(URL url, String realm, AuthScheme scheme) {
|
||||
int port = url.getPort();
|
||||
if (port == -1) {
|
||||
port = url.getDefaultPort();
|
||||
}
|
||||
String key = SERVER_AUTHENTICATION + ":" + scheme + ":" + url.getProtocol().toLowerCase()
|
||||
+ ":" + url.getHost().toLowerCase() + ":" + port + ":" + realm;
|
||||
return key;
|
||||
}
|
||||
|
||||
static AuthenticationInfo getServerAuth(String key) {
|
||||
AuthenticationInfo cached = getAuth(key, null);
|
||||
if ((cached == null) && requestIsInProgress (key)) {
|
||||
/* check the cache again, it might contain an entry */
|
||||
@ -314,9 +318,13 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
|
||||
* Used in response to a challenge. Note, the protocol field is always
|
||||
* blank for proxies.
|
||||
*/
|
||||
static AuthenticationInfo getProxyAuth(String host, int port, String realm, AuthScheme scheme) {
|
||||
static String getProxyAuthKey(String host, int port, String realm, AuthScheme scheme) {
|
||||
String key = PROXY_AUTHENTICATION + ":" + scheme + "::" + host.toLowerCase()
|
||||
+ ":" + port + ":" + realm;
|
||||
return key;
|
||||
}
|
||||
|
||||
static AuthenticationInfo getProxyAuth(String key) {
|
||||
AuthenticationInfo cached = (AuthenticationInfo) cache.get(key, null);
|
||||
if ((cached == null) && requestIsInProgress (key)) {
|
||||
/* check the cache again, it might contain an entry */
|
||||
@ -330,19 +338,20 @@ public abstract class AuthenticationInfo extends AuthCacheValue implements Clone
|
||||
* Add this authentication to the cache
|
||||
*/
|
||||
void addToCache() {
|
||||
cache.put (cacheKey(true), this);
|
||||
String key = cacheKey(true);
|
||||
cache.put(key, this);
|
||||
if (supportsPreemptiveAuthorization()) {
|
||||
cache.put (cacheKey(false), this);
|
||||
cache.put(cacheKey(false), this);
|
||||
}
|
||||
endAuthRequest();
|
||||
endAuthRequest(key);
|
||||
}
|
||||
|
||||
void endAuthRequest () {
|
||||
static void endAuthRequest (String key) {
|
||||
if (!serializeAuth) {
|
||||
return;
|
||||
}
|
||||
synchronized (requests) {
|
||||
requestCompleted (cacheKey(true));
|
||||
requestCompleted(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 1995-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
|
||||
@ -249,6 +249,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
boolean isUserServerAuth;
|
||||
boolean isUserProxyAuth;
|
||||
|
||||
String serverAuthKey, proxyAuthKey;
|
||||
|
||||
/* Progress source */
|
||||
protected ProgressSource pi;
|
||||
|
||||
@ -1258,6 +1260,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
doingNTLMp2ndStage = false;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
inNegotiateProxy = false;
|
||||
doingNTLMp2ndStage = false;
|
||||
if (!isUserProxyAuth)
|
||||
requests.remove("Proxy-Authorization");
|
||||
}
|
||||
|
||||
// cache proxy authentication info
|
||||
@ -1303,7 +1310,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
serverAuthentication.getAuthScheme() != NTLM) {
|
||||
if (serverAuthentication.isAuthorizationStale (raw)) {
|
||||
/* we can retry with the current credentials */
|
||||
disconnectInternal();
|
||||
disconnectWeb();
|
||||
redirects++;
|
||||
requests.set(serverAuthentication.getHeaderName(),
|
||||
serverAuthentication.getHeaderValue(url, method));
|
||||
@ -1318,7 +1325,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
currentServerCredentials = serverAuthentication;
|
||||
|
||||
if (serverAuthentication != null) {
|
||||
disconnectInternal();
|
||||
disconnectWeb();
|
||||
redirects++; // don't let things loop ad nauseum
|
||||
setCookieHeader();
|
||||
continue;
|
||||
@ -1327,7 +1334,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
reset ();
|
||||
/* header not used for ntlm */
|
||||
if (!serverAuthentication.setHeaders(this, null, raw)) {
|
||||
disconnectInternal();
|
||||
disconnectWeb();
|
||||
throw new IOException ("Authentication failure");
|
||||
}
|
||||
doingNTLM2ndStage = false;
|
||||
@ -1498,11 +1505,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
if (respCode == HTTP_PROXY_AUTH && proxyAuthentication != null) {
|
||||
proxyAuthentication.endAuthRequest();
|
||||
if (proxyAuthKey != null) {
|
||||
AuthenticationInfo.endAuthRequest(proxyAuthKey);
|
||||
}
|
||||
else if (respCode == HTTP_UNAUTHORIZED && serverAuthentication != null) {
|
||||
serverAuthentication.endAuthRequest();
|
||||
if (serverAuthKey != null) {
|
||||
AuthenticationInfo.endAuthRequest(serverAuthKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1715,8 +1722,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
statusLine + "\"");
|
||||
}
|
||||
} finally {
|
||||
if (respCode == HTTP_PROXY_AUTH && proxyAuthentication != null) {
|
||||
proxyAuthentication.endAuthRequest();
|
||||
if (proxyAuthKey != null) {
|
||||
AuthenticationInfo.endAuthRequest(proxyAuthKey);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1832,10 +1839,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
|
||||
if (realm == null)
|
||||
realm = "";
|
||||
ret = AuthenticationInfo.getProxyAuth(host,
|
||||
port,
|
||||
realm,
|
||||
authScheme);
|
||||
proxyAuthKey = AuthenticationInfo.getProxyAuthKey(host, port, realm, authScheme);
|
||||
ret = AuthenticationInfo.getProxyAuth(proxyAuthKey);
|
||||
if (ret == null) {
|
||||
switch (authScheme) {
|
||||
case BASIC:
|
||||
@ -1976,7 +1981,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
domain = p.findValue ("domain");
|
||||
if (realm == null)
|
||||
realm = "";
|
||||
ret = AuthenticationInfo.getServerAuth(url, realm, authScheme);
|
||||
serverAuthKey = AuthenticationInfo.getServerAuthKey(url, realm, authScheme);
|
||||
ret = AuthenticationInfo.getServerAuth(serverAuthKey);
|
||||
InetAddress addr = null;
|
||||
if (ret == null) {
|
||||
try {
|
||||
@ -2319,6 +2325,22 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
|
||||
connected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the web server at the first 401 error. Do not
|
||||
* disconnect when using a proxy, a good proxy should have already
|
||||
* closed the connection to the web server.
|
||||
*/
|
||||
private void disconnectWeb() throws IOException {
|
||||
if (usingProxy()) {
|
||||
responseCode = -1;
|
||||
// clean up, particularly, skip the content part
|
||||
// of a 401 error response
|
||||
reset();
|
||||
} else {
|
||||
disconnectInternal();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the server (for internal use)
|
||||
*/
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2005-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
|
||||
@ -45,43 +45,50 @@ public class NegotiateCallbackHandler implements CallbackHandler {
|
||||
private String username;
|
||||
private char[] password;
|
||||
|
||||
/**
|
||||
* Authenticator asks for username and password in a single prompt,
|
||||
* but CallbackHandler checks one by one. So, no matter which callback
|
||||
* gets handled first, make sure Authenticator is only called once.
|
||||
*/
|
||||
private boolean answered;
|
||||
|
||||
private final HttpCallerInfo hci;
|
||||
|
||||
public NegotiateCallbackHandler(HttpCallerInfo hci) {
|
||||
this.hci = hci;
|
||||
}
|
||||
|
||||
private void getAnswer() {
|
||||
if (!answered) {
|
||||
answered = true;
|
||||
PasswordAuthentication passAuth =
|
||||
Authenticator.requestPasswordAuthentication(
|
||||
hci.host, hci.addr, hci.port, hci.protocol,
|
||||
hci.prompt, hci.scheme, hci.url, hci.authType);
|
||||
/**
|
||||
* To be compatible with existing callback handler implementations,
|
||||
* when the underlying Authenticator is canceled, username and
|
||||
* password are assigned null. No exception is thrown.
|
||||
*/
|
||||
if (passAuth != null) {
|
||||
username = passAuth.getUserName();
|
||||
password = passAuth.getPassword();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handle(Callback[] callbacks) throws
|
||||
UnsupportedCallbackException, IOException {
|
||||
for (int i=0; i<callbacks.length; i++) {
|
||||
Callback callBack = callbacks[i];
|
||||
|
||||
if (callBack instanceof NameCallback) {
|
||||
if (username == null) {
|
||||
PasswordAuthentication passAuth =
|
||||
Authenticator.requestPasswordAuthentication(
|
||||
hci.host, hci.addr, hci.port, hci.protocol,
|
||||
hci.prompt, hci.scheme, hci.url, hci.authType);
|
||||
username = passAuth.getUserName();
|
||||
password = passAuth.getPassword();
|
||||
}
|
||||
NameCallback nameCallback =
|
||||
(NameCallback)callBack;
|
||||
nameCallback.setName(username);
|
||||
|
||||
getAnswer();
|
||||
((NameCallback)callBack).setName(username);
|
||||
} else if (callBack instanceof PasswordCallback) {
|
||||
PasswordCallback passwordCallback =
|
||||
(PasswordCallback)callBack;
|
||||
if (password == null) {
|
||||
PasswordAuthentication passAuth =
|
||||
Authenticator.requestPasswordAuthentication(
|
||||
hci.host, hci.addr, hci.port, hci.protocol,
|
||||
hci.prompt, hci.scheme, hci.url, hci.authType);
|
||||
username = passAuth.getUserName();
|
||||
password = passAuth.getPassword();
|
||||
}
|
||||
passwordCallback.setPassword(password);
|
||||
Arrays.fill(password, ' ');
|
||||
getAnswer();
|
||||
((PasswordCallback)callBack).setPassword(password);
|
||||
if (password != null) Arrays.fill(password, ' ');
|
||||
} else {
|
||||
throw new UnsupportedCallbackException(callBack,
|
||||
"Call back not supported");
|
||||
|
@ -28,39 +28,24 @@ package sun.net.www.protocol.https;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.Authenticator;
|
||||
import java.net.PasswordAuthentication;
|
||||
import java.security.Principal;
|
||||
import java.security.KeyStore;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.cert.*;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.security.AccessController;
|
||||
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import sun.security.x509.X500Name;
|
||||
import sun.misc.Regexp;
|
||||
import sun.misc.RegexpPool;
|
||||
import sun.net.www.HeaderParser;
|
||||
import sun.net.www.MessageHeader;
|
||||
import sun.net.www.http.HttpClient;
|
||||
import sun.security.action.*;
|
||||
|
||||
@ -125,6 +110,7 @@ final class HttpsClient extends HttpClient
|
||||
private static final int httpsPortNumber = 443;
|
||||
|
||||
/** Returns the default HTTPS port (443) */
|
||||
@Override
|
||||
protected int getDefaultPort() { return httpsPortNumber; }
|
||||
|
||||
private HostnameVerifier hv;
|
||||
@ -368,11 +354,39 @@ final class HttpsClient extends HttpClient
|
||||
return sslSocketFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* The following method, createSocket, is defined in NetworkClient
|
||||
* and overridden here so that the socket facroty is used to create
|
||||
* new sockets.
|
||||
*/
|
||||
@Override
|
||||
protected Socket createSocket() throws IOException {
|
||||
try {
|
||||
return sslSocketFactory.createSocket();
|
||||
} catch (SocketException se) {
|
||||
//
|
||||
// bug 6771432
|
||||
// javax.net.SocketFactory throws a SocketException with an
|
||||
// UnsupportedOperationException as its cause to indicate that
|
||||
// unconnected sockets have not been implemented.
|
||||
//
|
||||
Throwable t = se.getCause();
|
||||
if (t != null && t instanceof UnsupportedOperationException) {
|
||||
return super.createSocket();
|
||||
} else {
|
||||
throw se;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean needsTunneling() {
|
||||
return (proxy != null && proxy.type() != Proxy.Type.DIRECT
|
||||
&& proxy.type() != Proxy.Type.SOCKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnect() throws IOException, UnknownHostException {
|
||||
if (!isCachedConnection()) {
|
||||
SSLSocket s = null;
|
||||
@ -383,6 +397,9 @@ final class HttpsClient extends HttpClient
|
||||
host, port, true);
|
||||
} else {
|
||||
s = (SSLSocket)serverSocket;
|
||||
if (s instanceof SSLSocketImpl) {
|
||||
((SSLSocketImpl)s).setHost(host);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// If we fail to connect through the tunnel, try it
|
||||
@ -451,7 +468,6 @@ final class HttpsClient extends HttpClient
|
||||
//
|
||||
// Get authenticated server name, if any
|
||||
//
|
||||
boolean done = false;
|
||||
String host = url.getHost();
|
||||
|
||||
// if IPv6 strip off the "[]"
|
||||
@ -467,7 +483,7 @@ final class HttpsClient extends HttpClient
|
||||
|
||||
// Use ciphersuite to determine whether Kerberos is present.
|
||||
if (cipher.startsWith("TLS_KRB5")) {
|
||||
if (!checker.match(host, getPeerPrincipal())) {
|
||||
if (!HostnameChecker.match(host, getPeerPrincipal())) {
|
||||
throw new SSLPeerUnverifiedException("Hostname checker" +
|
||||
" failed for Kerberos");
|
||||
}
|
||||
@ -514,6 +530,7 @@ final class HttpsClient extends HttpClient
|
||||
+ url.getHost() + ">");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void putInKeepAliveCache() {
|
||||
kac.put(url, sslSocketFactory, this);
|
||||
}
|
||||
@ -521,6 +538,7 @@ final class HttpsClient extends HttpClient
|
||||
/*
|
||||
* Close an idle connection to this URL (if it exists in the cache).
|
||||
*/
|
||||
@Override
|
||||
public void closeIdleConnection() {
|
||||
HttpClient http = (HttpClient) kac.get(url, sslSocketFactory);
|
||||
if (http != null) {
|
||||
@ -626,11 +644,12 @@ final class HttpsClient extends HttpClient
|
||||
* @return the proxy host being used for this client, or null
|
||||
* if we're not going through a proxy
|
||||
*/
|
||||
@Override
|
||||
public String getProxyHostUsed() {
|
||||
if (!needsTunneling()) {
|
||||
return null;
|
||||
} else {
|
||||
return ((InetSocketAddress)proxy.address()).getHostName();
|
||||
return super.getProxyHostUsed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -638,6 +657,7 @@ final class HttpsClient extends HttpClient
|
||||
* @return the proxy port being used for this client. Meaningless
|
||||
* if getProxyHostUsed() gives null.
|
||||
*/
|
||||
@Override
|
||||
public int getProxyPortUsed() {
|
||||
return (proxy == null || proxy.type() == Proxy.Type.DIRECT ||
|
||||
proxy.type() == Proxy.Type.SOCKS)? -1:
|
||||
|
@ -68,6 +68,9 @@ class Net { // package-private
|
||||
InetSocketAddress isa = (InetSocketAddress)sa;
|
||||
if (isa.isUnresolved())
|
||||
throw new UnresolvedAddressException(); // ## needs arg
|
||||
InetAddress addr = isa.getAddress();
|
||||
if (!(addr instanceof Inet4Address || addr instanceof Inet6Address))
|
||||
throw new IllegalArgumentException("Invalid address type");
|
||||
return isa;
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ public class Surrogate {
|
||||
* Tells whether or not the given UCS-4 character is in the Basic
|
||||
* Multilingual Plane, and can be represented using a single char.
|
||||
*/
|
||||
public static boolean isBMP(int uc) {
|
||||
return (int) (char) uc == uc;
|
||||
public static boolean isBMPCodePoint(int uc) {
|
||||
return uc >> 16 == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -290,7 +290,7 @@ public class Surrogate {
|
||||
* error() will return a descriptive result object
|
||||
*/
|
||||
public int generate(int uc, int len, CharBuffer dst) {
|
||||
if (Surrogate.isBMP(uc)) {
|
||||
if (Surrogate.isBMPCodePoint(uc)) {
|
||||
if (Surrogate.is(uc)) {
|
||||
error = CoderResult.malformedForLength(len);
|
||||
return -1;
|
||||
@ -334,7 +334,7 @@ public class Surrogate {
|
||||
* error() will return a descriptive result object
|
||||
*/
|
||||
public int generate(int uc, int len, char[] da, int dp, int dl) {
|
||||
if (Surrogate.isBMP(uc)) {
|
||||
if (Surrogate.isBMPCodePoint(uc)) {
|
||||
if (Surrogate.is(uc)) {
|
||||
error = CoderResult.malformedForLength(len);
|
||||
return -1;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2004 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
|
||||
@ -23,15 +23,13 @@
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
package sun.nio.cs.ext;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import sun.nio.cs.HistoricallyNamedCharset;
|
||||
import static sun.nio.cs.CharsetMapping.*;
|
||||
|
||||
public class Big5_HKSCS extends Charset implements HistoricallyNamedCharset
|
||||
{
|
||||
@ -57,33 +55,35 @@ public class Big5_HKSCS extends Charset implements HistoricallyNamedCharset
|
||||
return new Encoder(this);
|
||||
}
|
||||
|
||||
private static class Decoder extends HKSCS_2001.Decoder {
|
||||
static class Decoder extends HKSCS.Decoder {
|
||||
private static DoubleByte.Decoder big5 =
|
||||
(DoubleByte.Decoder)new Big5().newDecoder();
|
||||
|
||||
Big5.Decoder big5Dec;
|
||||
|
||||
protected char decodeDouble(int byte1, int byte2) {
|
||||
char c = super.decodeDouble(byte1, byte2);
|
||||
return (c != REPLACE_CHAR) ? c : big5Dec.decodeDouble(byte1, byte2);
|
||||
private static char[][] b2cBmp = new char[0x100][];
|
||||
private static char[][] b2cSupp = new char[0x100][];
|
||||
static {
|
||||
initb2c(b2cBmp, HKSCSMapping.b2cBmpStr);
|
||||
initb2c(b2cSupp, HKSCSMapping.b2cSuppStr);
|
||||
}
|
||||
|
||||
private Decoder(Charset cs) {
|
||||
super(cs);
|
||||
big5Dec = new Big5.Decoder(cs);
|
||||
super(cs, big5, b2cBmp, b2cSupp);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Encoder extends HKSCS_2001.Encoder {
|
||||
static class Encoder extends HKSCS.Encoder {
|
||||
private static DoubleByte.Encoder big5 =
|
||||
(DoubleByte.Encoder)new Big5().newEncoder();
|
||||
|
||||
private Big5.Encoder big5Enc;
|
||||
|
||||
protected int encodeDouble(char ch) {
|
||||
int r = super.encodeDouble(ch);
|
||||
return (r != 0) ? r : big5Enc.encodeDouble(ch);
|
||||
static char[][] c2bBmp = new char[0x100][];
|
||||
static char[][] c2bSupp = new char[0x100][];
|
||||
static {
|
||||
initc2b(c2bBmp, HKSCSMapping.b2cBmpStr, HKSCSMapping.pua);
|
||||
initc2b(c2bSupp, HKSCSMapping.b2cSuppStr, null);
|
||||
}
|
||||
|
||||
private Encoder(Charset cs) {
|
||||
super(cs);
|
||||
big5Enc = new Big5.Encoder(cs);
|
||||
super(cs, big5, c2bBmp, c2bSupp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
85
jdk/src/share/classes/sun/nio/cs/ext/Big5_HKSCS_2001.java
Normal file
85
jdk/src/share/classes/sun/nio/cs/ext/Big5_HKSCS_2001.java
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2002-2004 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 sun.nio.cs.ext;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import sun.nio.cs.HistoricallyNamedCharset;
|
||||
|
||||
public class Big5_HKSCS_2001 extends Charset
|
||||
{
|
||||
public Big5_HKSCS_2001() {
|
||||
super("x-Big5-HKSCS-2001", ExtendedCharsets.aliasesFor("x-Big5-HKSCS-2001"));
|
||||
}
|
||||
|
||||
public boolean contains(Charset cs) {
|
||||
return ((cs.name().equals("US-ASCII"))
|
||||
|| (cs instanceof Big5)
|
||||
|| (cs instanceof Big5_HKSCS_2001));
|
||||
}
|
||||
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new Decoder(this);
|
||||
}
|
||||
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new Encoder(this);
|
||||
}
|
||||
|
||||
private static class Decoder extends HKSCS.Decoder {
|
||||
private static DoubleByte.Decoder big5 =
|
||||
(DoubleByte.Decoder)new Big5().newDecoder();
|
||||
|
||||
private static char[][] b2cBmp = new char[0x100][];
|
||||
private static char[][] b2cSupp = new char[0x100][];
|
||||
static {
|
||||
initb2c(b2cBmp, HKSCS2001Mapping.b2cBmpStr);
|
||||
initb2c(b2cSupp, HKSCS2001Mapping.b2cSuppStr);
|
||||
}
|
||||
|
||||
private Decoder(Charset cs) {
|
||||
super(cs, big5, b2cBmp, b2cSupp);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Encoder extends HKSCS.Encoder {
|
||||
private static DoubleByte.Encoder big5 =
|
||||
(DoubleByte.Encoder)new Big5().newEncoder();
|
||||
|
||||
static char[][] c2bBmp = new char[0x100][];
|
||||
static char[][] c2bSupp = new char[0x100][];
|
||||
static {
|
||||
initc2b(c2bBmp, HKSCS2001Mapping.b2cBmpStr,
|
||||
HKSCS2001Mapping.pua);
|
||||
initc2b(c2bSupp, HKSCS2001Mapping.b2cSuppStr, null);
|
||||
}
|
||||
|
||||
private Encoder(Charset cs) {
|
||||
super(cs, big5, c2bBmp, c2bSupp);
|
||||
}
|
||||
}
|
||||
}
|
@ -23,15 +23,14 @@
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
package sun.nio.cs.ext;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import sun.nio.cs.HistoricallyNamedCharset;
|
||||
import java.util.Arrays;
|
||||
import static sun.nio.cs.CharsetMapping.*;
|
||||
|
||||
public class Big5_Solaris extends Charset implements HistoricallyNamedCharset
|
||||
{
|
||||
@ -50,90 +49,78 @@ public class Big5_Solaris extends Charset implements HistoricallyNamedCharset
|
||||
}
|
||||
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new Decoder(this);
|
||||
initb2c();
|
||||
return new DoubleByte.Decoder(this, b2c, b2cSB, 0x40, 0xfe);
|
||||
}
|
||||
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new Encoder(this);
|
||||
initc2b();
|
||||
return new DoubleByte.Encoder(this, c2b, c2bIndex);
|
||||
}
|
||||
|
||||
private static class Decoder extends Big5.Decoder {
|
||||
|
||||
protected char decodeDouble(int byte1, int byte2) {
|
||||
char c = super.decodeDouble(byte1, byte2);
|
||||
static char[][] b2c;
|
||||
static char[] b2cSB;
|
||||
private static volatile boolean b2cInitialized = false;
|
||||
|
||||
static void initb2c() {
|
||||
if (b2cInitialized)
|
||||
return;
|
||||
synchronized (Big5_Solaris.class) {
|
||||
if (b2cInitialized)
|
||||
return;
|
||||
Big5.initb2c();
|
||||
b2c = Big5.b2c.clone();
|
||||
// Big5 Solaris implementation has 7 additional mappings
|
||||
|
||||
if (c == REPLACE_CHAR) {
|
||||
if (byte1 == 0xf9) {
|
||||
switch (byte2) {
|
||||
case 0xD6:
|
||||
c = (char)0x7881;
|
||||
break;
|
||||
case 0xD7:
|
||||
c = (char)0x92B9;
|
||||
break;
|
||||
case 0xD8:
|
||||
c = (char)0x88CF;
|
||||
break;
|
||||
case 0xD9:
|
||||
c = (char)0x58BB;
|
||||
break;
|
||||
case 0xDA:
|
||||
c = (char)0x6052;
|
||||
break;
|
||||
case 0xDB:
|
||||
c = (char)0x7CA7;
|
||||
break;
|
||||
case 0xDC:
|
||||
c = (char)0x5AFA;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int[] sol = new int[] {
|
||||
0xF9D6, 0x7881,
|
||||
0xF9D7, 0x92B9,
|
||||
0xF9D8, 0x88CF,
|
||||
0xF9D9, 0x58BB,
|
||||
0xF9DA, 0x6052,
|
||||
0xF9DB, 0x7CA7,
|
||||
0xF9DC, 0x5AFA };
|
||||
if (b2c[0xf9] == DoubleByte.B2C_UNMAPPABLE) {
|
||||
b2c[0xf9] = new char[0xfe - 0x40 + 1];
|
||||
Arrays.fill(b2c[0xf9], UNMAPPABLE_DECODING);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private Decoder(Charset cs) {
|
||||
super(cs);
|
||||
for (int i = 0; i < sol.length;) {
|
||||
b2c[0xf9][sol[i++] & 0xff - 0x40] = (char)sol[i++];
|
||||
}
|
||||
b2cSB = Big5.b2cSB;
|
||||
b2cInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Encoder extends Big5.Encoder {
|
||||
static char[] c2b;
|
||||
static char[] c2bIndex;
|
||||
private static volatile boolean c2bInitialized = false;
|
||||
|
||||
protected int encodeDouble(char ch) {
|
||||
int r = super.encodeDouble(ch);
|
||||
static void initc2b() {
|
||||
if (c2bInitialized)
|
||||
return;
|
||||
synchronized (Big5_Solaris.class) {
|
||||
if (c2bInitialized)
|
||||
return;
|
||||
Big5.initc2b();
|
||||
c2b = Big5.c2b.clone();
|
||||
c2bIndex = Big5.c2bIndex.clone();
|
||||
int[] sol = new int[] {
|
||||
0x7881, 0xF9D6,
|
||||
0x92B9, 0xF9D7,
|
||||
0x88CF, 0xF9D8,
|
||||
0x58BB, 0xF9D9,
|
||||
0x6052, 0xF9DA,
|
||||
0x7CA7, 0xF9DB,
|
||||
0x5AFA, 0xF9DC };
|
||||
|
||||
if (r == 0) {
|
||||
switch (ch) {
|
||||
case 0x7881:
|
||||
r = 0xF9D6;
|
||||
break;
|
||||
case 0x92B9:
|
||||
r = 0xF9D7;
|
||||
break;
|
||||
case 0x88CF:
|
||||
r = 0xF9D8;
|
||||
break;
|
||||
case 0x58BB:
|
||||
r = 0xF9D9;
|
||||
break;
|
||||
case 0x6052:
|
||||
r = 0xF9DA;
|
||||
break;
|
||||
case 0x7CA7:
|
||||
r = 0xF9DB;
|
||||
break;
|
||||
case 0x5AFA:
|
||||
r = 0xF9DC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
private Encoder(Charset cs) {
|
||||
super(cs);
|
||||
for (int i = 0; i < sol.length;) {
|
||||
int c = sol[i++];
|
||||
// no need to check c2bIndex[c >>8], we know it points
|
||||
// to the appropriate place.
|
||||
c2b[c2bIndex[c >> 8] + (c & 0xff)] = (char)sol[i++];
|
||||
}
|
||||
c2bInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,15 @@ public class ExtendedCharsets
|
||||
"csBig5"
|
||||
});
|
||||
|
||||
charset("x-MS950-HKSCS-XP", "MS950_HKSCS_XP",
|
||||
new String[] {
|
||||
"MS950_HKSCS_XP" // JDK historical;
|
||||
});
|
||||
|
||||
charset("x-MS950-HKSCS", "MS950_HKSCS",
|
||||
new String[] {
|
||||
// IANA aliases
|
||||
"MS950_HKSCS" // JDK historical;
|
||||
"MS950_HKSCS" // JDK historical;
|
||||
});
|
||||
|
||||
charset("x-windows-950", "MS950",
|
||||
@ -86,8 +91,16 @@ public class ExtendedCharsets
|
||||
"Big5_HKSCS", // JDK historical
|
||||
"big5hk",
|
||||
"big5-hkscs",
|
||||
"big5hkscs" // Linux alias
|
||||
});
|
||||
|
||||
charset("x-Big5-HKSCS-2001", "Big5_HKSCS_2001",
|
||||
new String[] {
|
||||
"Big5_HKSCS_2001",
|
||||
"big5hk-2001",
|
||||
"big5-hkscs-2001",
|
||||
"big5-hkscs:unicode3.0",
|
||||
"big5hkscs" // Linux alias
|
||||
"big5hkscs-2001",
|
||||
});
|
||||
|
||||
charset("x-Big5-Solaris", "Big5_Solaris",
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2004 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
|
||||
@ -55,47 +55,35 @@ public class MS950_HKSCS extends Charset implements HistoricallyNamedCharset
|
||||
return new Encoder(this);
|
||||
}
|
||||
|
||||
private static class Decoder extends HKSCS.Decoder {
|
||||
|
||||
private static DoubleByte.Decoder ms950Dec =
|
||||
static class Decoder extends HKSCS.Decoder {
|
||||
private static DoubleByte.Decoder ms950 =
|
||||
(DoubleByte.Decoder)new MS950().newDecoder();
|
||||
|
||||
/*
|
||||
* Note current decoder decodes 0x8BC2 --> U+F53A
|
||||
* ie. maps to Unicode PUA.
|
||||
* Unaccounted discrepancy between this mapping
|
||||
* inferred from MS950/windows-950 and the published
|
||||
* MS HKSCS mappings which maps 0x8BC2 --> U+5C22
|
||||
* a character defined with the Unified CJK block
|
||||
*/
|
||||
|
||||
protected char decodeDouble(int byte1, int byte2) {
|
||||
char c = super.decodeDouble(byte1, byte2);
|
||||
return (c != UNMAPPABLE_DECODING) ? c : ms950Dec.decodeDouble(byte1, byte2);
|
||||
private static char[][] b2cBmp = new char[0x100][];
|
||||
private static char[][] b2cSupp = new char[0x100][];
|
||||
static {
|
||||
initb2c(b2cBmp, HKSCSMapping.b2cBmpStr);
|
||||
initb2c(b2cSupp, HKSCSMapping.b2cSuppStr);
|
||||
}
|
||||
|
||||
private Decoder(Charset cs) {
|
||||
super(cs);
|
||||
super(cs, ms950, b2cBmp, b2cSupp);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Encoder extends HKSCS.Encoder {
|
||||
|
||||
private static DoubleByte.Encoder ms950Enc =
|
||||
private static DoubleByte.Encoder ms950 =
|
||||
(DoubleByte.Encoder)new MS950().newEncoder();
|
||||
|
||||
/*
|
||||
* Note current encoder encodes U+F53A --> 0x8BC2
|
||||
* Published MS HKSCS mappings show
|
||||
* U+5C22 <--> 0x8BC2
|
||||
*/
|
||||
protected int encodeDouble(char ch) {
|
||||
int r = super.encodeDouble(ch);
|
||||
return (r != UNMAPPABLE_ENCODING) ? r : ms950Enc.encodeChar(ch);
|
||||
static char[][] c2bBmp = new char[0x100][];
|
||||
static char[][] c2bSupp = new char[0x100][];
|
||||
static {
|
||||
initc2b(c2bBmp, HKSCSMapping.b2cBmpStr, HKSCSMapping.pua);
|
||||
initc2b(c2bSupp, HKSCSMapping.b2cSuppStr, null);
|
||||
}
|
||||
|
||||
private Encoder(Charset cs) {
|
||||
super(cs);
|
||||
super(cs, ms950, c2bBmp, c2bSupp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
102
jdk/src/share/classes/sun/nio/cs/ext/MS950_HKSCS_XP.java
Normal file
102
jdk/src/share/classes/sun/nio/cs/ext/MS950_HKSCS_XP.java
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2002-2004 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 sun.nio.cs.ext;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import sun.nio.cs.HistoricallyNamedCharset;
|
||||
import static sun.nio.cs.CharsetMapping.*;
|
||||
|
||||
public class MS950_HKSCS_XP extends Charset
|
||||
{
|
||||
public MS950_HKSCS_XP() {
|
||||
super("x-MS950-HKSCS-XP", ExtendedCharsets.aliasesFor("x-MS950-HKSCS-XP"));
|
||||
}
|
||||
|
||||
public boolean contains(Charset cs) {
|
||||
return ((cs.name().equals("US-ASCII"))
|
||||
|| (cs instanceof MS950)
|
||||
|| (cs instanceof MS950_HKSCS_XP));
|
||||
}
|
||||
|
||||
public CharsetDecoder newDecoder() {
|
||||
return new Decoder(this);
|
||||
}
|
||||
|
||||
public CharsetEncoder newEncoder() {
|
||||
return new Encoder(this);
|
||||
}
|
||||
|
||||
static class Decoder extends HKSCS.Decoder {
|
||||
private static DoubleByte.Decoder ms950 =
|
||||
(DoubleByte.Decoder)new MS950().newDecoder();
|
||||
|
||||
/*
|
||||
* Note current decoder decodes 0x8BC2 --> U+F53A
|
||||
* ie. maps to Unicode PUA.
|
||||
* Unaccounted discrepancy between this mapping
|
||||
* inferred from MS950/windows-950 and the published
|
||||
* MS HKSCS mappings which maps 0x8BC2 --> U+5C22
|
||||
* a character defined with the Unified CJK block
|
||||
*/
|
||||
private static char[][] b2cBmp = new char[0x100][];
|
||||
static {
|
||||
initb2c(b2cBmp, HKSCS_XPMapping.b2cBmpStr);
|
||||
}
|
||||
|
||||
public char decodeDoubleEx(int b1, int b2) {
|
||||
return UNMAPPABLE_DECODING;
|
||||
}
|
||||
|
||||
private Decoder(Charset cs) {
|
||||
super(cs, ms950, b2cBmp, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Encoder extends HKSCS.Encoder {
|
||||
private static DoubleByte.Encoder ms950 =
|
||||
(DoubleByte.Encoder)new MS950().newEncoder();
|
||||
|
||||
/*
|
||||
* Note current encoder encodes U+F53A --> 0x8BC2
|
||||
* Published MS HKSCS mappings show
|
||||
* U+5C22 <--> 0x8BC2
|
||||
*/
|
||||
static char[][] c2bBmp = new char[0x100][];
|
||||
static {
|
||||
initc2b(c2bBmp, HKSCS_XPMapping.b2cBmpStr, null);
|
||||
}
|
||||
|
||||
public int encodeSupp(int cp) {
|
||||
return UNMAPPABLE_ENCODING;
|
||||
}
|
||||
|
||||
private Encoder(Charset cs) {
|
||||
super(cs, ms950, c2bBmp, null);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2003-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
|
||||
@ -26,7 +26,7 @@
|
||||
package sun.security.pkcs11;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
|
||||
import sun.security.pkcs11.wrapper.*;
|
||||
@ -61,9 +61,28 @@ final class P11SecureRandom extends SecureRandomSpi {
|
||||
// buffer, if mixing is used
|
||||
private byte[] mixBuffer;
|
||||
|
||||
// bytes remaining in buffer, if mixing is used
|
||||
// bytes remaining in mixBuffer, if mixing is used
|
||||
private int buffered;
|
||||
|
||||
/*
|
||||
* we buffer data internally for efficiency but limit the lifetime
|
||||
* to avoid using stale bits.
|
||||
*/
|
||||
// lifetime in ms, currently 100 ms (0.1 s)
|
||||
private static final long MAX_IBUFFER_TIME = 100;
|
||||
|
||||
// size of the internal buffer
|
||||
private static final int IBUFFER_SIZE = 32;
|
||||
|
||||
// internal buffer for the random bits
|
||||
private transient byte[] iBuffer = new byte[IBUFFER_SIZE];
|
||||
|
||||
// number of bytes remain in iBuffer
|
||||
private transient int ibuffered = 0;
|
||||
|
||||
// time that data was read into iBuffer
|
||||
private transient long lastRead = 0L;
|
||||
|
||||
P11SecureRandom(Token token) {
|
||||
this.token = token;
|
||||
}
|
||||
@ -104,16 +123,29 @@ final class P11SecureRandom extends SecureRandomSpi {
|
||||
if ((bytes == null) || (bytes.length == 0)) {
|
||||
return;
|
||||
}
|
||||
Session session = null;
|
||||
try {
|
||||
session = token.getOpSession();
|
||||
token.p11.C_GenerateRandom(session.id(), bytes);
|
||||
mix(bytes);
|
||||
} catch (PKCS11Exception e) {
|
||||
throw new ProviderException("nextBytes() failed", e);
|
||||
} finally {
|
||||
token.releaseSession(session);
|
||||
if (bytes.length <= IBUFFER_SIZE) {
|
||||
int ofs = 0;
|
||||
synchronized (iBuffer) {
|
||||
while (ofs < bytes.length) {
|
||||
long time = System.currentTimeMillis();
|
||||
// refill the internal buffer if empty or stale
|
||||
if ((ibuffered == 0) ||
|
||||
!(time - lastRead < MAX_IBUFFER_TIME)) {
|
||||
lastRead = time;
|
||||
implNextBytes(iBuffer);
|
||||
ibuffered = IBUFFER_SIZE;
|
||||
}
|
||||
// copy the buffered bytes into 'bytes'
|
||||
while ((ofs < bytes.length) && (ibuffered > 0)) {
|
||||
bytes[ofs++] = iBuffer[IBUFFER_SIZE - ibuffered--];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// avoid using the buffer - just fill bytes directly
|
||||
implNextBytes(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
@ -143,4 +175,26 @@ final class P11SecureRandom extends SecureRandomSpi {
|
||||
}
|
||||
}
|
||||
|
||||
// fill up the specified buffer with random bytes, and mix them
|
||||
private void implNextBytes(byte[] bytes) {
|
||||
Session session = null;
|
||||
try {
|
||||
session = token.getOpSession();
|
||||
token.p11.C_GenerateRandom(session.id(), bytes);
|
||||
mix(bytes);
|
||||
} catch (PKCS11Exception e) {
|
||||
throw new ProviderException("nextBytes() failed", e);
|
||||
} finally {
|
||||
token.releaseSession(session);
|
||||
}
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
// assign default values to non-null transient fields
|
||||
iBuffer = new byte[IBUFFER_SIZE];
|
||||
ibuffered = 0;
|
||||
lastRead = 0L;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2003-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
|
||||
@ -30,8 +30,7 @@ import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import java.security.*;
|
||||
import java.security.interfaces.ECPublicKey;
|
||||
|
||||
import java.security.interfaces.*;
|
||||
import sun.nio.ch.DirectBuffer;
|
||||
|
||||
import sun.security.util.*;
|
||||
@ -88,7 +87,7 @@ final class P11Signature extends SignatureSpi {
|
||||
// mechanism id
|
||||
private final long mechanism;
|
||||
|
||||
// digest algorithm OID, if we do RSA padding ourselves
|
||||
// digest algorithm OID, if we encode RSA signature ourselves
|
||||
private final ObjectIdentifier digestOID;
|
||||
|
||||
// type, one of T_* below
|
||||
@ -103,7 +102,7 @@ final class P11Signature extends SignatureSpi {
|
||||
// associated session, if any
|
||||
private Session session;
|
||||
|
||||
// mode, on of M_* below
|
||||
// mode, one of M_* below
|
||||
private int mode;
|
||||
|
||||
// flag indicating whether an operation is initialized
|
||||
@ -137,6 +136,9 @@ final class P11Signature extends SignatureSpi {
|
||||
this.token = token;
|
||||
this.algorithm = algorithm;
|
||||
this.mechanism = mechanism;
|
||||
byte[] buffer = null;
|
||||
ObjectIdentifier digestOID = null;
|
||||
MessageDigest md = null;
|
||||
switch ((int)mechanism) {
|
||||
case (int)CKM_MD2_RSA_PKCS:
|
||||
case (int)CKM_MD5_RSA_PKCS:
|
||||
@ -146,34 +148,25 @@ final class P11Signature extends SignatureSpi {
|
||||
case (int)CKM_SHA512_RSA_PKCS:
|
||||
keyAlgorithm = "RSA";
|
||||
type = T_UPDATE;
|
||||
digestOID = null;
|
||||
buffer = new byte[1];
|
||||
md = null;
|
||||
break;
|
||||
case (int)CKM_DSA_SHA1:
|
||||
keyAlgorithm = "DSA";
|
||||
type = T_UPDATE;
|
||||
digestOID = null;
|
||||
buffer = new byte[1];
|
||||
md = null;
|
||||
break;
|
||||
case (int)CKM_ECDSA_SHA1:
|
||||
keyAlgorithm = "EC";
|
||||
type = T_UPDATE;
|
||||
digestOID = null;
|
||||
buffer = new byte[1];
|
||||
md = null;
|
||||
break;
|
||||
case (int)CKM_DSA:
|
||||
keyAlgorithm = "DSA";
|
||||
digestOID = null;
|
||||
if (algorithm.equals("DSA")) {
|
||||
type = T_DIGEST;
|
||||
md = MessageDigest.getInstance("SHA-1");
|
||||
buffer = null;
|
||||
} else if (algorithm.equals("RawDSA")) {
|
||||
type = T_RAW;
|
||||
md = null;
|
||||
buffer = new byte[20];
|
||||
} else {
|
||||
throw new ProviderException(algorithm);
|
||||
@ -181,10 +174,8 @@ final class P11Signature extends SignatureSpi {
|
||||
break;
|
||||
case (int)CKM_ECDSA:
|
||||
keyAlgorithm = "EC";
|
||||
digestOID = null;
|
||||
if (algorithm.equals("NONEwithECDSA")) {
|
||||
type = T_RAW;
|
||||
md = null;
|
||||
buffer = new byte[RAW_ECDSA_MAX];
|
||||
} else {
|
||||
String digestAlg;
|
||||
@ -201,14 +192,12 @@ final class P11Signature extends SignatureSpi {
|
||||
}
|
||||
type = T_DIGEST;
|
||||
md = MessageDigest.getInstance(digestAlg);
|
||||
buffer = null;
|
||||
}
|
||||
break;
|
||||
case (int)CKM_RSA_PKCS:
|
||||
case (int)CKM_RSA_X_509:
|
||||
keyAlgorithm = "RSA";
|
||||
type = T_DIGEST;
|
||||
buffer = null;
|
||||
if (algorithm.equals("MD5withRSA")) {
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
digestOID = AlgorithmId.MD5_oid;
|
||||
@ -234,6 +223,9 @@ final class P11Signature extends SignatureSpi {
|
||||
default:
|
||||
throw new ProviderException("Unknown mechanism: " + mechanism);
|
||||
}
|
||||
this.buffer = buffer;
|
||||
this.digestOID = digestOID;
|
||||
this.md = md;
|
||||
session = token.getOpSession();
|
||||
}
|
||||
|
||||
@ -326,9 +318,52 @@ final class P11Signature extends SignatureSpi {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRSAKeyLength(int len) throws InvalidKeyException {
|
||||
RSAPadding padding;
|
||||
try {
|
||||
padding = RSAPadding.getInstance
|
||||
(RSAPadding.PAD_BLOCKTYPE_1, (len + 7) >> 3);
|
||||
} catch (InvalidAlgorithmParameterException iape) {
|
||||
throw new InvalidKeyException(iape.getMessage());
|
||||
}
|
||||
int maxDataSize = padding.getMaxDataSize();
|
||||
int encodedLength;
|
||||
if (algorithm.equals("MD5withRSA") ||
|
||||
algorithm.equals("MD2withRSA")) {
|
||||
encodedLength = 34;
|
||||
} else if (algorithm.equals("SHA1withRSA")) {
|
||||
encodedLength = 35;
|
||||
} else if (algorithm.equals("SHA256withRSA")) {
|
||||
encodedLength = 51;
|
||||
} else if (algorithm.equals("SHA384withRSA")) {
|
||||
encodedLength = 67;
|
||||
} else if (algorithm.equals("SHA512withRSA")) {
|
||||
encodedLength = 83;
|
||||
} else {
|
||||
throw new ProviderException("Unknown signature algo: " + algorithm);
|
||||
}
|
||||
if (encodedLength > maxDataSize) {
|
||||
throw new InvalidKeyException
|
||||
("Key is too short for this signature algorithm");
|
||||
}
|
||||
}
|
||||
|
||||
// see JCA spec
|
||||
protected void engineInitVerify(PublicKey publicKey)
|
||||
throws InvalidKeyException {
|
||||
if (publicKey == null) {
|
||||
throw new InvalidKeyException("Key must not be null");
|
||||
}
|
||||
// Need to check RSA key length whenever a new key is set
|
||||
if (keyAlgorithm.equals("RSA") && publicKey != p11Key) {
|
||||
int keyLen;
|
||||
if (publicKey instanceof P11Key) {
|
||||
keyLen = ((P11Key) publicKey).keyLength();
|
||||
} else {
|
||||
keyLen = ((RSAKey) publicKey).getModulus().bitLength();
|
||||
}
|
||||
checkRSAKeyLength(keyLen);
|
||||
}
|
||||
cancelOperation();
|
||||
mode = M_VERIFY;
|
||||
p11Key = P11KeyFactory.convertKey(token, publicKey, keyAlgorithm);
|
||||
@ -338,6 +373,19 @@ final class P11Signature extends SignatureSpi {
|
||||
// see JCA spec
|
||||
protected void engineInitSign(PrivateKey privateKey)
|
||||
throws InvalidKeyException {
|
||||
if (privateKey == null) {
|
||||
throw new InvalidKeyException("Key must not be null");
|
||||
}
|
||||
// Need to check RSA key length whenever a new key is set
|
||||
if (keyAlgorithm.equals("RSA") && privateKey != p11Key) {
|
||||
int keyLen;
|
||||
if (privateKey instanceof P11Key) {
|
||||
keyLen = ((P11Key) privateKey).keyLength;
|
||||
} else {
|
||||
keyLen = ((RSAKey) privateKey).getModulus().bitLength();
|
||||
}
|
||||
checkRSAKeyLength(keyLen);
|
||||
}
|
||||
cancelOperation();
|
||||
mode = M_SIGN;
|
||||
p11Key = P11KeyFactory.convertKey(token, privateKey, keyAlgorithm);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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
|
||||
@ -65,6 +65,9 @@ import java.lang.reflect.ReflectPermission;
|
||||
import javax.sound.sampled.AudioPermission;
|
||||
import javax.net.ssl.SSLPermission;
|
||||
*/
|
||||
import sun.misc.JavaSecurityProtectionDomainAccess;
|
||||
import static sun.misc.JavaSecurityProtectionDomainAccess.ProtectionDomainCache;
|
||||
import sun.misc.SharedSecrets;
|
||||
import sun.security.util.Password;
|
||||
import sun.security.util.PolicyUtil;
|
||||
import sun.security.util.PropertyExpander;
|
||||
@ -1102,7 +1105,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
/**
|
||||
* Refreshes the policy object by re-reading all the policy files.
|
||||
*/
|
||||
public void refresh() {
|
||||
@Override public void refresh() {
|
||||
init(url);
|
||||
}
|
||||
|
||||
@ -1119,9 +1122,10 @@ public class PolicyFile extends java.security.Policy {
|
||||
*
|
||||
* @see java.security.ProtectionDomain
|
||||
*/
|
||||
@Override
|
||||
public boolean implies(ProtectionDomain pd, Permission p) {
|
||||
PolicyInfo pi = policyInfo.get();
|
||||
Map<ProtectionDomain, PermissionCollection> pdMap = pi.getPdMapping();
|
||||
ProtectionDomainCache pdMap = pi.getPdMapping();
|
||||
|
||||
PermissionCollection pc = pdMap.get(pd);
|
||||
|
||||
@ -1167,6 +1171,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
* @return the Permissions granted to the provided
|
||||
* <code>ProtectionDomain</code>.
|
||||
*/
|
||||
@Override
|
||||
public PermissionCollection getPermissions(ProtectionDomain domain) {
|
||||
Permissions perms = new Permissions();
|
||||
|
||||
@ -1202,6 +1207,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
*
|
||||
* @return the set of permissions according to the policy.
|
||||
*/
|
||||
@Override
|
||||
public PermissionCollection getPermissions(CodeSource codesource) {
|
||||
return getPermissions(new Permissions(), codesource);
|
||||
}
|
||||
@ -2119,7 +2125,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
return codesource;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
@Override public String toString(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(ResourcesMgr.getString("("));
|
||||
sb.append(getCodeSource());
|
||||
@ -2255,7 +2261,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
*
|
||||
* @return false.
|
||||
*/
|
||||
public boolean implies(Permission p) {
|
||||
@Override public boolean implies(Permission p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2272,7 +2278,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
* type (class) name, permission name, actions, and
|
||||
* certificates as this object.
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
@Override public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
|
||||
@ -2320,7 +2326,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
*
|
||||
* @return a hash code value for this object.
|
||||
*/
|
||||
public int hashCode() {
|
||||
@Override public int hashCode() {
|
||||
int hash = type.hashCode();
|
||||
if (name != null)
|
||||
hash ^= name.hashCode();
|
||||
@ -2339,7 +2345,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
*
|
||||
* @return the empty string "".
|
||||
*/
|
||||
public String getActions() {
|
||||
@Override public String getActions() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -2366,7 +2372,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
*
|
||||
* @return information about this SelfPermission.
|
||||
*/
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
return "(SelfPermission " + type + " " + name + " " + actions + ")";
|
||||
}
|
||||
}
|
||||
@ -2388,7 +2394,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
final Map aliasMapping;
|
||||
|
||||
// Maps ProtectionDomain to PermissionCollection
|
||||
private final Map<ProtectionDomain, PermissionCollection>[] pdMapping;
|
||||
private final ProtectionDomainCache[] pdMapping;
|
||||
private java.util.Random random;
|
||||
|
||||
PolicyInfo(int numCaches) {
|
||||
@ -2397,16 +2403,17 @@ public class PolicyFile extends java.security.Policy {
|
||||
Collections.synchronizedList(new ArrayList<PolicyEntry>(2));
|
||||
aliasMapping = Collections.synchronizedMap(new HashMap(11));
|
||||
|
||||
pdMapping = new Map[numCaches];
|
||||
pdMapping = new ProtectionDomainCache[numCaches];
|
||||
JavaSecurityProtectionDomainAccess jspda
|
||||
= SharedSecrets.getJavaSecurityProtectionDomainAccess();
|
||||
for (int i = 0; i < numCaches; i++) {
|
||||
pdMapping[i] = Collections.synchronizedMap
|
||||
(new WeakHashMap<ProtectionDomain, PermissionCollection>());
|
||||
pdMapping[i] = jspda.getProtectionDomainCache();
|
||||
}
|
||||
if (numCaches > 1) {
|
||||
random = new java.util.Random();
|
||||
}
|
||||
}
|
||||
Map<ProtectionDomain, PermissionCollection> getPdMapping() {
|
||||
ProtectionDomainCache getPdMapping() {
|
||||
if (pdMapping.length == 1) {
|
||||
return pdMapping[0];
|
||||
} else {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 1998-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
|
||||
@ -26,7 +26,6 @@
|
||||
package sun.security.provider;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Collection;
|
||||
import java.util.*;
|
||||
import java.security.cert.*;
|
||||
import sun.security.x509.X509CertImpl;
|
||||
@ -37,6 +36,7 @@ import sun.security.provider.certpath.X509CertificatePair;
|
||||
import sun.security.util.DerValue;
|
||||
import sun.security.util.Cache;
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.security.pkcs.ParsingException;
|
||||
|
||||
/**
|
||||
* This class defines a certificate factory for X.509 v3 certificates &
|
||||
@ -62,10 +62,6 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
public static final String BEGIN_CERT = "-----BEGIN CERTIFICATE-----";
|
||||
public static final String END_CERT = "-----END CERTIFICATE-----";
|
||||
|
||||
private static final int defaultExpectedLineLength = 80;
|
||||
|
||||
private static final char[] endBoundary = "-----END".toCharArray();
|
||||
|
||||
private static final int ENC_MAX_LENGTH = 4096 * 1024; // 4 MB MAX
|
||||
|
||||
private static final Cache certCache = Cache.newSoftMemoryCache(750);
|
||||
@ -92,13 +88,7 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
throw new CertificateException("Missing input stream");
|
||||
}
|
||||
try {
|
||||
if (is.markSupported() == false) {
|
||||
// consume the entire input stream
|
||||
byte[] totalBytes;
|
||||
totalBytes = getTotalBytes(new BufferedInputStream(is));
|
||||
is = new ByteArrayInputStream(totalBytes);
|
||||
}
|
||||
byte[] encoding = readSequence(is);
|
||||
byte[] encoding = readOneBlock(is);
|
||||
if (encoding != null) {
|
||||
X509CertImpl cert = (X509CertImpl)getFromCache(certCache, encoding);
|
||||
if (cert != null) {
|
||||
@ -108,19 +98,7 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
addToCache(certCache, cert.getEncodedInternal(), cert);
|
||||
return cert;
|
||||
} else {
|
||||
X509CertImpl cert;
|
||||
// determine if binary or Base64 encoding. If Base64 encoding,
|
||||
// the certificate must be bounded at the beginning by
|
||||
// "-----BEGIN".
|
||||
if (isBase64(is)) {
|
||||
// Base64
|
||||
byte[] data = base64_to_binary(is);
|
||||
cert = new X509CertImpl(data);
|
||||
} else {
|
||||
// binary
|
||||
cert = new X509CertImpl(new DerValue(is));
|
||||
}
|
||||
return intern(cert);
|
||||
throw new IOException("Empty input");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw (CertificateException)new CertificateException
|
||||
@ -128,74 +106,22 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a DER SEQUENCE from an InputStream and return the encoding.
|
||||
* If data does not represent a SEQUENCE, it uses indefinite length
|
||||
* encoding, or is longer than ENC_MAX_LENGTH, the stream is reset
|
||||
* and this method returns null.
|
||||
*/
|
||||
private static byte[] readSequence(InputStream in) throws IOException {
|
||||
in.mark(ENC_MAX_LENGTH);
|
||||
byte[] b = new byte[4];
|
||||
int i = readFully(in, b, 0, b.length);
|
||||
if ((i != b.length) || (b[0] != 0x30)) { // first byte must be SEQUENCE
|
||||
in.reset();
|
||||
return null;
|
||||
}
|
||||
i = b[1] & 0xff;
|
||||
int totalLength;
|
||||
if (i < 0x80) {
|
||||
int valueLength = i;
|
||||
totalLength = valueLength + 2;
|
||||
} else if (i == 0x81) {
|
||||
int valueLength = b[2] & 0xff;
|
||||
totalLength = valueLength + 3;
|
||||
} else if (i == 0x82) {
|
||||
int valueLength = ((b[2] & 0xff) << 8) | (b[3] & 0xff);
|
||||
totalLength = valueLength + 4;
|
||||
} else { // ignore longer length forms
|
||||
in.reset();
|
||||
return null;
|
||||
}
|
||||
if (totalLength > ENC_MAX_LENGTH) {
|
||||
in.reset();
|
||||
return null;
|
||||
}
|
||||
byte[] encoding = new byte[totalLength];
|
||||
if( totalLength < b.length ) {
|
||||
in.reset();
|
||||
i = readFully(in, encoding, 0, totalLength);
|
||||
if( i != totalLength ) {
|
||||
in.reset();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
System.arraycopy(b, 0, encoding, 0, b.length);
|
||||
int n = totalLength - b.length;
|
||||
i = readFully(in, encoding, b.length, n);
|
||||
if (i != n) {
|
||||
in.reset();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the stream until length bytes have been read or EOF has
|
||||
* been reached. Return the number of bytes actually read.
|
||||
*/
|
||||
private static int readFully(InputStream in, byte[] buffer, int offset,
|
||||
private static int readFully(InputStream in, ByteArrayOutputStream bout,
|
||||
int length) throws IOException {
|
||||
int read = 0;
|
||||
byte[] buffer = new byte[2048];
|
||||
while (length > 0) {
|
||||
int n = in.read(buffer, offset, length);
|
||||
int n = in.read(buffer, 0, length<2048?length:2048);
|
||||
if (n <= 0) {
|
||||
break;
|
||||
}
|
||||
bout.write(buffer, 0, n);
|
||||
read += n;
|
||||
length -= n;
|
||||
offset += n;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
@ -309,21 +235,11 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
throw new CertificateException("Missing input stream");
|
||||
}
|
||||
try {
|
||||
if (inStream.markSupported() == false) {
|
||||
// consume the entire input stream
|
||||
byte[] totalBytes;
|
||||
totalBytes = getTotalBytes(new BufferedInputStream(inStream));
|
||||
inStream = new ByteArrayInputStream(totalBytes);
|
||||
}
|
||||
// determine if binary or Base64 encoding. If Base64 encoding,
|
||||
// each certificate must be bounded at the beginning by
|
||||
// "-----BEGIN".
|
||||
if (isBase64(inStream)) {
|
||||
// Base64
|
||||
byte[] data = base64_to_binary(inStream);
|
||||
return new X509CertPath(new ByteArrayInputStream(data));
|
||||
byte[] encoding = readOneBlock(inStream);
|
||||
if (encoding != null) {
|
||||
return new X509CertPath(new ByteArrayInputStream(encoding));
|
||||
} else {
|
||||
return new X509CertPath(inStream);
|
||||
throw new IOException("Empty input");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new CertificateException(ioe.getMessage());
|
||||
@ -350,21 +266,11 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
throw new CertificateException("Missing input stream");
|
||||
}
|
||||
try {
|
||||
if (inStream.markSupported() == false) {
|
||||
// consume the entire input stream
|
||||
byte[] totalBytes;
|
||||
totalBytes = getTotalBytes(new BufferedInputStream(inStream));
|
||||
inStream = new ByteArrayInputStream(totalBytes);
|
||||
}
|
||||
// determine if binary or Base64 encoding. If Base64 encoding,
|
||||
// each certificate must be bounded at the beginning by
|
||||
// "-----BEGIN".
|
||||
if (isBase64(inStream)) {
|
||||
// Base64
|
||||
byte[] data = base64_to_binary(inStream);
|
||||
byte[] data = readOneBlock(inStream);
|
||||
if (data != null) {
|
||||
return new X509CertPath(new ByteArrayInputStream(data), encoding);
|
||||
} else {
|
||||
return(new X509CertPath(inStream, encoding));
|
||||
throw new IOException("Empty input");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new CertificateException(ioe.getMessage());
|
||||
@ -426,11 +332,6 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
throw new CertificateException("Missing input stream");
|
||||
}
|
||||
try {
|
||||
if (is.markSupported() == false) {
|
||||
// consume the entire input stream
|
||||
is = new ByteArrayInputStream
|
||||
(getTotalBytes(new BufferedInputStream(is)));
|
||||
}
|
||||
return parseX509orPKCS7Cert(is);
|
||||
} catch (IOException ioe) {
|
||||
throw new CertificateException(ioe);
|
||||
@ -458,13 +359,7 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
throw new CRLException("Missing input stream");
|
||||
}
|
||||
try {
|
||||
if (is.markSupported() == false) {
|
||||
// consume the entire input stream
|
||||
byte[] totalBytes;
|
||||
totalBytes = getTotalBytes(new BufferedInputStream(is));
|
||||
is = new ByteArrayInputStream(totalBytes);
|
||||
}
|
||||
byte[] encoding = readSequence(is);
|
||||
byte[] encoding = readOneBlock(is);
|
||||
if (encoding != null) {
|
||||
X509CRLImpl crl = (X509CRLImpl)getFromCache(crlCache, encoding);
|
||||
if (crl != null) {
|
||||
@ -474,19 +369,7 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
addToCache(crlCache, crl.getEncodedInternal(), crl);
|
||||
return crl;
|
||||
} else {
|
||||
X509CRLImpl crl;
|
||||
// determine if binary or Base64 encoding. If Base64 encoding,
|
||||
// the CRL must be bounded at the beginning by
|
||||
// "-----BEGIN".
|
||||
if (isBase64(is)) {
|
||||
// Base64
|
||||
byte[] data = base64_to_binary(is);
|
||||
crl = new X509CRLImpl(data);
|
||||
} else {
|
||||
// binary
|
||||
crl = new X509CRLImpl(new DerValue(is));
|
||||
}
|
||||
return intern(crl);
|
||||
throw new IOException("Empty input");
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new CRLException(ioe.getMessage());
|
||||
@ -504,19 +387,13 @@ public class X509Factory extends CertificateFactorySpi {
|
||||
*
|
||||
* @exception CRLException on parsing errors.
|
||||
*/
|
||||
public Collection<? extends java.security.cert.CRL> engineGenerateCRLs(InputStream
|
||||
is)
|
||||
throws CRLException
|
||||
public Collection<? extends java.security.cert.CRL> engineGenerateCRLs(
|
||||
InputStream is) throws CRLException
|
||||
{
|
||||
if (is == null) {
|
||||
throw new CRLException("Missing input stream");
|
||||
}
|
||||
try {
|
||||
if (is.markSupported() == false) {
|
||||
// consume the entire input stream
|
||||
is = new ByteArrayInputStream
|
||||
(getTotalBytes(new BufferedInputStream(is)));
|
||||
}
|
||||
return parseX509orPKCS7CRL(is);
|
||||
} catch (IOException ioe) {
|
||||
throw new CRLException(ioe.getMessage());
|
||||
@ -533,42 +410,25 @@ is)
|
||||
throws CertificateException, IOException
|
||||
{
|
||||
Collection<X509CertImpl> coll = new ArrayList<X509CertImpl>();
|
||||
boolean first = true;
|
||||
while (is.available() != 0) {
|
||||
// determine if binary or Base64 encoding. If Base64 encoding,
|
||||
// each certificate must be bounded at the beginning by
|
||||
// "-----BEGIN".
|
||||
InputStream is2 = is;
|
||||
if (isBase64(is2)) {
|
||||
// Base64
|
||||
is2 = new ByteArrayInputStream(base64_to_binary(is2));
|
||||
byte[] data = readOneBlock(is);
|
||||
if (data == null) {
|
||||
return new ArrayList<X509CertImpl>(0);
|
||||
}
|
||||
try {
|
||||
PKCS7 pkcs7 = new PKCS7(data);
|
||||
X509Certificate[] certs = pkcs7.getCertificates();
|
||||
// certs are optional in PKCS #7
|
||||
if (certs != null) {
|
||||
return Arrays.asList(certs);
|
||||
} else {
|
||||
// no crls provided
|
||||
return new ArrayList<X509Certificate>(0);
|
||||
}
|
||||
if (first)
|
||||
is2.mark(is2.available());
|
||||
try {
|
||||
// treat as X.509 cert
|
||||
coll.add(intern(new X509CertImpl(new DerValue(is2))));
|
||||
} catch (CertificateException e) {
|
||||
Throwable cause = e.getCause();
|
||||
// only treat as PKCS#7 if this is the first cert parsed
|
||||
// and the root cause of the decoding failure is an IOException
|
||||
if (first && cause != null && (cause instanceof IOException)) {
|
||||
// treat as PKCS#7
|
||||
is2.reset();
|
||||
PKCS7 pkcs7 = new PKCS7(is2);
|
||||
X509Certificate[] certs = pkcs7.getCertificates();
|
||||
// certs are optional in PKCS #7
|
||||
if (certs != null) {
|
||||
return Arrays.asList(certs);
|
||||
} else {
|
||||
// no certs provided
|
||||
return new ArrayList<X509Certificate>(0);
|
||||
}
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} catch (ParsingException e) {
|
||||
while (data != null) {
|
||||
coll.add(new X509CertImpl(data));
|
||||
data = readOneBlock(is);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
@ -583,162 +443,215 @@ is)
|
||||
throws CRLException, IOException
|
||||
{
|
||||
Collection<X509CRLImpl> coll = new ArrayList<X509CRLImpl>();
|
||||
boolean first = true;
|
||||
while (is.available() != 0) {
|
||||
// determine if binary or Base64 encoding. If Base64 encoding,
|
||||
// the CRL must be bounded at the beginning by
|
||||
// "-----BEGIN".
|
||||
InputStream is2 = is;
|
||||
if (isBase64(is)) {
|
||||
// Base64
|
||||
is2 = new ByteArrayInputStream(base64_to_binary(is2));
|
||||
byte[] data = readOneBlock(is);
|
||||
if (data == null) {
|
||||
return new ArrayList<X509CRL>(0);
|
||||
}
|
||||
try {
|
||||
PKCS7 pkcs7 = new PKCS7(data);
|
||||
X509CRL[] crls = pkcs7.getCRLs();
|
||||
// CRLs are optional in PKCS #7
|
||||
if (crls != null) {
|
||||
return Arrays.asList(crls);
|
||||
} else {
|
||||
// no crls provided
|
||||
return new ArrayList<X509CRL>(0);
|
||||
}
|
||||
if (first)
|
||||
is2.mark(is2.available());
|
||||
try {
|
||||
// treat as X.509 CRL
|
||||
coll.add(new X509CRLImpl(is2));
|
||||
} catch (CRLException e) {
|
||||
// only treat as PKCS#7 if this is the first CRL parsed
|
||||
if (first) {
|
||||
is2.reset();
|
||||
PKCS7 pkcs7 = new PKCS7(is2);
|
||||
X509CRL[] crls = pkcs7.getCRLs();
|
||||
// CRLs are optional in PKCS #7
|
||||
if (crls != null) {
|
||||
return Arrays.asList(crls);
|
||||
} else {
|
||||
// no crls provided
|
||||
return new ArrayList<X509CRL>(0);
|
||||
}
|
||||
}
|
||||
} catch (ParsingException e) {
|
||||
while (data != null) {
|
||||
coll.add(new X509CRLImpl(data));
|
||||
data = readOneBlock(is);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
return coll;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts a Base64-encoded X.509 certificate or X.509 CRL or PKCS#7 data
|
||||
* to binary encoding.
|
||||
* In all cases, the data must be bounded at the beginning by
|
||||
* "-----BEGIN", and must be bounded at the end by "-----END".
|
||||
*/
|
||||
private byte[] base64_to_binary(InputStream is)
|
||||
throws IOException
|
||||
{
|
||||
long len = 0; // total length of base64 encoding, including boundaries
|
||||
|
||||
is.mark(is.available());
|
||||
|
||||
BufferedInputStream bufin = new BufferedInputStream(is);
|
||||
BufferedReader br =
|
||||
new BufferedReader(new InputStreamReader(bufin, "ASCII"));
|
||||
|
||||
// First read all of the data that is found between
|
||||
// the "-----BEGIN" and "-----END" boundaries into a buffer.
|
||||
String temp;
|
||||
while (true) {
|
||||
temp=readLine(br);
|
||||
if (temp == null) {
|
||||
throw new IOException("Unsupported encoding");
|
||||
}
|
||||
len += temp.length();
|
||||
if (temp.startsWith("-----BEGIN")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
while ((temp=readLine(br))!=null && !temp.startsWith("-----END")) {
|
||||
strBuf.append(temp);
|
||||
}
|
||||
if (temp == null) {
|
||||
throw new IOException("Unsupported encoding");
|
||||
} else {
|
||||
len += temp.length();
|
||||
}
|
||||
|
||||
// consume only as much as was needed
|
||||
len += strBuf.length();
|
||||
is.reset();
|
||||
is.skip(len);
|
||||
|
||||
// Now, that data is supposed to be a single X.509 certificate or
|
||||
// X.509 CRL or PKCS#7 formatted data... Base64 encoded.
|
||||
// Decode into binary and return the result.
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
return decoder.decodeBuffer(strBuf.toString());
|
||||
}
|
||||
|
||||
/*
|
||||
* Reads the entire input stream into a byte array.
|
||||
*/
|
||||
private byte[] getTotalBytes(InputStream is) throws IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
|
||||
int n;
|
||||
baos.reset();
|
||||
while ((n = is.read(buffer, 0, buffer.length)) != -1) {
|
||||
baos.write(buffer, 0, n);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines if input is binary or Base64 encoded.
|
||||
*/
|
||||
private boolean isBase64(InputStream is) throws IOException {
|
||||
if (is.available() >= 1) {
|
||||
is.mark(1);
|
||||
int c1 = is.read();
|
||||
is.reset();
|
||||
if (c1 != DerValue.tag_Sequence) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a line of text. A line is considered to be terminated by any one
|
||||
* of a line feed ('\n'), a carriage return ('\r'), a carriage return
|
||||
* followed immediately by a linefeed, or an end-of-certificate marker.
|
||||
/**
|
||||
* Returns an ASN.1 SEQUENCE from a stream, which might be a BER-encoded
|
||||
* binary block or a PEM-style BASE64-encoded ASCII data. In the latter
|
||||
* case, it's de-BASE64'ed before return.
|
||||
*
|
||||
* @return A String containing the contents of the line, including
|
||||
* any line-termination characters, or null if the end of the
|
||||
* stream has been reached.
|
||||
* After the reading, the input stream pointer is after the BER block, or
|
||||
* after the newline character after the -----END SOMETHING----- line.
|
||||
*
|
||||
* @param is the InputStream
|
||||
* @returns byte block or null if end of stream
|
||||
* @throws IOException If any parsing error
|
||||
*/
|
||||
private String readLine(BufferedReader br) throws IOException {
|
||||
int c;
|
||||
int i = 0;
|
||||
boolean isMatch = true;
|
||||
boolean matched = false;
|
||||
StringBuffer sb = new StringBuffer(defaultExpectedLineLength);
|
||||
do {
|
||||
c = br.read();
|
||||
if (isMatch && (i < endBoundary.length)) {
|
||||
isMatch = ((char)c != endBoundary[i++]) ? false : true;
|
||||
}
|
||||
if (!matched)
|
||||
matched = (isMatch && (i == endBoundary.length));
|
||||
sb.append((char)c);
|
||||
} while ((c != -1) && (c != '\n') && (c != '\r'));
|
||||
private static byte[] readOneBlock(InputStream is) throws IOException {
|
||||
|
||||
if (!matched && c == -1) {
|
||||
// The first character of a BLOCK.
|
||||
int c = is.read();
|
||||
if (c == -1) {
|
||||
return null;
|
||||
}
|
||||
if (c == '\r') {
|
||||
br.mark(1);
|
||||
int c2 = br.read();
|
||||
if (c2 == '\n') {
|
||||
sb.append((char)c);
|
||||
} else {
|
||||
br.reset();
|
||||
if (c == DerValue.tag_Sequence) {
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream(2048);
|
||||
bout.write(c);
|
||||
readBERInternal(is, bout, c);
|
||||
return bout.toByteArray();
|
||||
} else {
|
||||
// Read BASE64 encoded data, might skip info at the beginning
|
||||
char[] data = new char[2048];
|
||||
int pos = 0;
|
||||
|
||||
// Step 1: Read until header is found
|
||||
int hyphen = (c=='-') ? 1: 0; // count of consequent hyphens
|
||||
int last = (c=='-') ? -1: c; // the char before hyphen
|
||||
while (true) {
|
||||
int next = is.read();
|
||||
if (next == -1) {
|
||||
// We accept useless data after the last block,
|
||||
// say, empty lines.
|
||||
return null;
|
||||
}
|
||||
if (next == '-') {
|
||||
hyphen++;
|
||||
} else {
|
||||
hyphen = 0;
|
||||
last = next;
|
||||
}
|
||||
if (hyphen == 5 && (last==-1 || last=='\r' || last=='\n')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2: Read the rest of header, determine the line end
|
||||
int end;
|
||||
while (true) {
|
||||
int next = is.read();
|
||||
if (next == -1) {
|
||||
throw new IOException("Incomplete data");
|
||||
}
|
||||
if (next == '\n') {
|
||||
end = '\n';
|
||||
break;
|
||||
}
|
||||
if (next == '\r') {
|
||||
next = is.read();
|
||||
if (next == -1) {
|
||||
throw new IOException("Incomplete data");
|
||||
}
|
||||
if (next == '\n') {
|
||||
end = '\n';
|
||||
} else {
|
||||
end = '\r';
|
||||
data[pos++] = (char)next;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3: Read the data
|
||||
while (true) {
|
||||
int next = is.read();
|
||||
if (next == -1) {
|
||||
throw new IOException("Incomplete data");
|
||||
}
|
||||
if (next != '-') {
|
||||
data[pos++] = (char)next;
|
||||
if (pos >= data.length) {
|
||||
data = Arrays.copyOf(data, data.length+1024);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Step 4: Consume the footer
|
||||
while (true) {
|
||||
int next = is.read();
|
||||
// Add next == '\n' for maximum safety, in case endline
|
||||
// is not consistent.
|
||||
if (next == -1 || next == end || next == '\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
return decoder.decodeBuffer(new String(data, 0, pos));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read one BER data block. This method is aware of indefinite-length BER
|
||||
* encoding and will read all of the sub-sections in a recursive way
|
||||
*
|
||||
* @param is Read from this InputStream
|
||||
* @param bout Write into this OutputStream
|
||||
* @param tag Tag already read (-1 mean not read)
|
||||
* @returns The current tag, used to check EOC in indefinite-length BER
|
||||
* @throws IOException Any parsing error
|
||||
*/
|
||||
private static int readBERInternal(InputStream is,
|
||||
ByteArrayOutputStream bout, int tag) throws IOException {
|
||||
|
||||
if (tag == -1) { // Not read before the call, read now
|
||||
tag = is.read();
|
||||
if (tag == -1) {
|
||||
throw new IOException("BER/DER tag info absent");
|
||||
}
|
||||
if ((tag & 0x1f) == 0x1f) {
|
||||
throw new IOException("Multi octets tag not supported");
|
||||
}
|
||||
bout.write(tag);
|
||||
}
|
||||
|
||||
int n = is.read();
|
||||
if (n == -1) {
|
||||
throw new IOException("BER/DER length info ansent");
|
||||
}
|
||||
bout.write(n);
|
||||
|
||||
int length;
|
||||
|
||||
if (n == 0x80) { // Indefinite-length encoding
|
||||
if ((tag & 0x20) != 0x20) {
|
||||
throw new IOException(
|
||||
"Non constructed encoding must have definite length");
|
||||
}
|
||||
while (true) {
|
||||
int subTag = readBERInternal(is, bout, -1);
|
||||
if (subTag == 0) { // EOC, end of indefinite-length section
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (n < 0x80) {
|
||||
length = n;
|
||||
} else if (n == 0x81) {
|
||||
length = is.read();
|
||||
if (length == -1) {
|
||||
throw new IOException("Incomplete BER/DER length info");
|
||||
}
|
||||
bout.write(length);
|
||||
} else if (n == 0x82) {
|
||||
int highByte = is.read();
|
||||
int lowByte = is.read();
|
||||
if (lowByte == -1) {
|
||||
throw new IOException("Incomplete BER/DER length info");
|
||||
}
|
||||
bout.write(highByte);
|
||||
bout.write(lowByte);
|
||||
length = (highByte << 8) | lowByte;
|
||||
} else if (n == 0x83) {
|
||||
int highByte = is.read();
|
||||
int midByte = is.read();
|
||||
int lowByte = is.read();
|
||||
if (lowByte == -1) {
|
||||
throw new IOException("Incomplete BER/DER length info");
|
||||
}
|
||||
bout.write(highByte);
|
||||
bout.write(midByte);
|
||||
bout.write(lowByte);
|
||||
length = (highByte << 16) | (midByte << 8) | lowByte;
|
||||
} else { // ignore longer length forms
|
||||
throw new IOException("Invalid BER/DER data (too huge?)");
|
||||
}
|
||||
if (readFully(is, bout, length) != length) {
|
||||
throw new IOException("Incomplete BER/DER data");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
@ -93,13 +93,17 @@ final class ClientHandshaker extends Handshaker {
|
||||
* Constructors
|
||||
*/
|
||||
ClientHandshaker(SSLSocketImpl socket, SSLContextImpl context,
|
||||
ProtocolList enabledProtocols) {
|
||||
ProtocolList enabledProtocols,
|
||||
ProtocolVersion activeProtocolVersion) {
|
||||
super(socket, context, enabledProtocols, true, true);
|
||||
this.activeProtocolVersion = activeProtocolVersion;
|
||||
}
|
||||
|
||||
ClientHandshaker(SSLEngineImpl engine, SSLContextImpl context,
|
||||
ProtocolList enabledProtocols) {
|
||||
ProtocolList enabledProtocols,
|
||||
ProtocolVersion activeProtocolVersion) {
|
||||
super(engine, context, enabledProtocols, true, true);
|
||||
this.activeProtocolVersion = activeProtocolVersion;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -275,7 +279,42 @@ final class ClientHandshaker extends Handshaker {
|
||||
// sent the "client hello" but the server's not seen it.
|
||||
//
|
||||
if (state < HandshakeMessage.ht_client_hello) {
|
||||
kickstart();
|
||||
if (!renegotiable) { // renegotiation is not allowed.
|
||||
if (activeProtocolVersion.v >= ProtocolVersion.TLS10.v) {
|
||||
// response with a no_negotiation warning,
|
||||
warningSE(Alerts.alert_no_negotiation);
|
||||
|
||||
// invalidate the handshake so that the caller can
|
||||
// dispose this object.
|
||||
invalidated = true;
|
||||
|
||||
// If there is still unread block in the handshake
|
||||
// input stream, it would be truncated with the disposal
|
||||
// and the next handshake message will become incomplete.
|
||||
//
|
||||
// However, according to SSL/TLS specifications, no more
|
||||
// handshake message could immediately follow ClientHello
|
||||
// or HelloRequest. But in case of any improper messages,
|
||||
// we'd better check to ensure there is no remaining bytes
|
||||
// in the handshake input stream.
|
||||
if (input.available() > 0) {
|
||||
fatalSE(Alerts.alert_unexpected_message,
|
||||
"HelloRequest followed by an unexpected " +
|
||||
"handshake message");
|
||||
}
|
||||
|
||||
} else {
|
||||
// For SSLv3, send the handshake_failure fatal error.
|
||||
// Note that SSLv3 does not define a no_negotiation alert
|
||||
// like TLSv1. However we cannot ignore the message
|
||||
// simply, otherwise the other side was waiting for a
|
||||
// response that would never come.
|
||||
fatalSE(Alerts.alert_handshake_failure,
|
||||
"renegotiation is not allowed");
|
||||
}
|
||||
} else {
|
||||
kickstart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 1996-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
|
||||
@ -60,9 +60,12 @@ import sun.security.ssl.CipherSuite.*;
|
||||
*/
|
||||
abstract class Handshaker {
|
||||
|
||||
// current protocol version
|
||||
// protocol version being established using this Handshaker
|
||||
ProtocolVersion protocolVersion;
|
||||
|
||||
// the currently active protocol version during a renegotiation
|
||||
ProtocolVersion activeProtocolVersion;
|
||||
|
||||
// list of enabled protocols
|
||||
ProtocolList enabledProtocols;
|
||||
|
||||
@ -124,6 +127,13 @@ abstract class Handshaker {
|
||||
/* Class and subclass dynamic debugging support */
|
||||
static final Debug debug = Debug.getInstance("ssl");
|
||||
|
||||
// By default, disable the unsafe legacy session renegotiation
|
||||
static final boolean renegotiable = Debug.getBooleanProperty(
|
||||
"sun.security.ssl.allowUnsafeRenegotiation", false);
|
||||
|
||||
// need to dispose the object when it is invalidated
|
||||
boolean invalidated;
|
||||
|
||||
Handshaker(SSLSocketImpl c, SSLContextImpl context,
|
||||
ProtocolList enabledProtocols, boolean needCertVerify,
|
||||
boolean isClient) {
|
||||
@ -144,6 +154,7 @@ abstract class Handshaker {
|
||||
this.sslContext = context;
|
||||
this.isClient = isClient;
|
||||
enableNewSession = true;
|
||||
invalidated = false;
|
||||
|
||||
setCipherSuite(CipherSuite.C_NULL);
|
||||
|
||||
@ -489,7 +500,9 @@ abstract class Handshaker {
|
||||
*/
|
||||
void processLoop() throws IOException {
|
||||
|
||||
while (input.available() > 0) {
|
||||
// need to read off 4 bytes at least to get the handshake
|
||||
// message type and length.
|
||||
while (input.available() >= 4) {
|
||||
byte messageType;
|
||||
int messageLen;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2003-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
|
||||
@ -433,11 +433,12 @@ final public class SSLEngineImpl extends SSLEngine {
|
||||
connectionState = cs_RENEGOTIATE;
|
||||
}
|
||||
if (roleIsServer) {
|
||||
handshaker = new ServerHandshaker
|
||||
(this, sslContext, enabledProtocols, doClientAuth);
|
||||
handshaker = new ServerHandshaker(this, sslContext,
|
||||
enabledProtocols, doClientAuth,
|
||||
connectionState == cs_RENEGOTIATE, protocolVersion);
|
||||
} else {
|
||||
handshaker = new ClientHandshaker
|
||||
(this, sslContext, enabledProtocols);
|
||||
handshaker = new ClientHandshaker(this, sslContext,
|
||||
enabledProtocols, protocolVersion);
|
||||
}
|
||||
handshaker.enabledCipherSuites = enabledCipherSuites;
|
||||
handshaker.setEnableSessionCreation(enableSessionCreation);
|
||||
@ -639,6 +640,10 @@ final public class SSLEngineImpl extends SSLEngine {
|
||||
break;
|
||||
|
||||
case cs_DATA:
|
||||
if (!Handshaker.renegotiable) {
|
||||
throw new SSLHandshakeException("renegotiation is not allowed");
|
||||
}
|
||||
|
||||
// initialize the handshaker, move to cs_RENEGOTIATE
|
||||
initHandshaker();
|
||||
break;
|
||||
@ -966,7 +971,13 @@ final public class SSLEngineImpl extends SSLEngine {
|
||||
handshaker.process_record(inputRecord, expectingFinished);
|
||||
expectingFinished = false;
|
||||
|
||||
if (handshaker.isDone()) {
|
||||
if (handshaker.invalidated) {
|
||||
handshaker = null;
|
||||
// if state is cs_RENEGOTIATE, revert it to cs_DATA
|
||||
if (connectionState == cs_RENEGOTIATE) {
|
||||
connectionState = cs_DATA;
|
||||
}
|
||||
} else if (handshaker.isDone()) {
|
||||
sess = handshaker.getSession();
|
||||
if (!writer.hasOutboundData()) {
|
||||
hsStatus = HandshakeStatus.FINISHED;
|
||||
|
@ -907,7 +907,13 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
|
||||
handshaker.process_record(r, expectingFinished);
|
||||
expectingFinished = false;
|
||||
|
||||
if (handshaker.isDone()) {
|
||||
if (handshaker.invalidated) {
|
||||
handshaker = null;
|
||||
// if state is cs_RENEGOTIATE, revert it to cs_DATA
|
||||
if (connectionState == cs_RENEGOTIATE) {
|
||||
connectionState = cs_DATA;
|
||||
}
|
||||
} else if (handshaker.isDone()) {
|
||||
sess = handshaker.getSession();
|
||||
handshaker = null;
|
||||
connectionState = cs_DATA;
|
||||
@ -925,6 +931,7 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
if (needAppData || connectionState != cs_DATA) {
|
||||
continue;
|
||||
} else {
|
||||
@ -1083,11 +1090,12 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
|
||||
connectionState = cs_RENEGOTIATE;
|
||||
}
|
||||
if (roleIsServer) {
|
||||
handshaker = new ServerHandshaker
|
||||
(this, sslContext, enabledProtocols, doClientAuth);
|
||||
handshaker = new ServerHandshaker(this, sslContext,
|
||||
enabledProtocols, doClientAuth,
|
||||
connectionState == cs_RENEGOTIATE, protocolVersion);
|
||||
} else {
|
||||
handshaker = new ClientHandshaker
|
||||
(this, sslContext, enabledProtocols);
|
||||
handshaker = new ClientHandshaker(this, sslContext,
|
||||
enabledProtocols, protocolVersion);
|
||||
}
|
||||
handshaker.enabledCipherSuites = enabledCipherSuites;
|
||||
handshaker.setEnableSessionCreation(enableSessionCreation);
|
||||
@ -1192,6 +1200,10 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
|
||||
break;
|
||||
|
||||
case cs_DATA:
|
||||
if (!Handshaker.renegotiable) {
|
||||
throw new SSLHandshakeException("renegotiation is not allowed");
|
||||
}
|
||||
|
||||
// initialize the handshaker, move to cs_RENEGOTIATE
|
||||
initHandshaker();
|
||||
break;
|
||||
@ -1840,6 +1852,11 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
|
||||
return host;
|
||||
}
|
||||
|
||||
// ONLY used by HttpsClient to setup the URI specified hostname
|
||||
synchronized public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an input stream to read from the peer on the other side.
|
||||
* Data read from this stream was always integrity protected in
|
||||
|
@ -69,6 +69,9 @@ final class ServerHandshaker extends Handshaker {
|
||||
// flag to check for clientCertificateVerify message
|
||||
private boolean needClientVerify = false;
|
||||
|
||||
// indicate a renegotiation handshaking
|
||||
private boolean isRenegotiation = false;
|
||||
|
||||
/*
|
||||
* For exportable ciphersuites using non-exportable key sizes, we use
|
||||
* ephemeral RSA keys. We could also do anonymous RSA in the same way
|
||||
@ -96,20 +99,28 @@ final class ServerHandshaker extends Handshaker {
|
||||
* Constructor ... use the keys found in the auth context.
|
||||
*/
|
||||
ServerHandshaker(SSLSocketImpl socket, SSLContextImpl context,
|
||||
ProtocolList enabledProtocols, byte clientAuth) {
|
||||
ProtocolList enabledProtocols, byte clientAuth,
|
||||
boolean isRenegotiation, ProtocolVersion activeProtocolVersion) {
|
||||
|
||||
super(socket, context, enabledProtocols,
|
||||
(clientAuth != SSLEngineImpl.clauth_none), false);
|
||||
doClientAuth = clientAuth;
|
||||
this.isRenegotiation = isRenegotiation;
|
||||
this.activeProtocolVersion = activeProtocolVersion;
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor ... use the keys found in the auth context.
|
||||
*/
|
||||
ServerHandshaker(SSLEngineImpl engine, SSLContextImpl context,
|
||||
ProtocolList enabledProtocols, byte clientAuth) {
|
||||
ProtocolList enabledProtocols, byte clientAuth,
|
||||
boolean isRenegotiation, ProtocolVersion activeProtocolVersion) {
|
||||
|
||||
super(engine, context, enabledProtocols,
|
||||
(clientAuth != SSLEngineImpl.clauth_none), false);
|
||||
doClientAuth = clientAuth;
|
||||
this.isRenegotiation = isRenegotiation;
|
||||
this.activeProtocolVersion = activeProtocolVersion;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -257,6 +268,45 @@ final class ServerHandshaker extends Handshaker {
|
||||
if (debug != null && Debug.isOn("handshake")) {
|
||||
mesg.print(System.out);
|
||||
}
|
||||
|
||||
// if it is a renegotiation request and renegotiation is not allowed
|
||||
if (isRenegotiation && !renegotiable) {
|
||||
if (activeProtocolVersion.v >= ProtocolVersion.TLS10.v) {
|
||||
// response with a no_negotiation warning,
|
||||
warningSE(Alerts.alert_no_negotiation);
|
||||
|
||||
// invalidate the handshake so that the caller can
|
||||
// dispose this object.
|
||||
invalidated = true;
|
||||
|
||||
// If there is still unread block in the handshake
|
||||
// input stream, it would be truncated with the disposal
|
||||
// and the next handshake message will become incomplete.
|
||||
//
|
||||
// However, according to SSL/TLS specifications, no more
|
||||
// handshake message could immediately follow ClientHello
|
||||
// or HelloRequest. But in case of any improper messages,
|
||||
// we'd better check to ensure there is no remaining bytes
|
||||
// in the handshake input stream.
|
||||
if (input.available() > 0) {
|
||||
fatalSE(Alerts.alert_unexpected_message,
|
||||
"ClientHello followed by an unexpected " +
|
||||
"handshake message");
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
// For SSLv3, send the handshake_failure fatal error.
|
||||
// Note that SSLv3 does not define a no_negotiation alert
|
||||
// like TLSv1. However we cannot ignore the message
|
||||
// simply, otherwise the other side was waiting for a
|
||||
// response that would never come.
|
||||
fatalSE(Alerts.alert_handshake_failure,
|
||||
"renegotiation is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Always make sure this entire record has been digested before we
|
||||
* start emitting output, to ensure correct digesting order.
|
||||
|
@ -977,46 +977,35 @@ public final class KeyTool {
|
||||
if (filename != null) {
|
||||
inStream = new FileInputStream(filename);
|
||||
}
|
||||
// Read the full stream before feeding to X509Factory,
|
||||
// otherwise, keytool -gencert | keytool -importcert
|
||||
// might not work properly, since -gencert is slow
|
||||
// and there's no data in the pipe at the beginning.
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
String importAlias = (alias!=null)?alias:keyAlias;
|
||||
try {
|
||||
byte[] b = new byte[4096];
|
||||
while (true) {
|
||||
int len = inStream.read(b);
|
||||
if (len < 0) break;
|
||||
bout.write(b, 0, len);
|
||||
if (keyStore.entryInstanceOf(
|
||||
importAlias, KeyStore.PrivateKeyEntry.class)) {
|
||||
kssave = installReply(importAlias, inStream);
|
||||
if (kssave) {
|
||||
System.err.println(rb.getString
|
||||
("Certificate reply was installed in keystore"));
|
||||
} else {
|
||||
System.err.println(rb.getString
|
||||
("Certificate reply was not installed in keystore"));
|
||||
}
|
||||
} else if (!keyStore.containsAlias(importAlias) ||
|
||||
keyStore.entryInstanceOf(importAlias,
|
||||
KeyStore.TrustedCertificateEntry.class)) {
|
||||
kssave = addTrustedCert(importAlias, inStream);
|
||||
if (kssave) {
|
||||
System.err.println(rb.getString
|
||||
("Certificate was added to keystore"));
|
||||
} else {
|
||||
System.err.println(rb.getString
|
||||
("Certificate was not added to keystore"));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (inStream != System.in) {
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
inStream = new ByteArrayInputStream(bout.toByteArray());
|
||||
String importAlias = (alias!=null)?alias:keyAlias;
|
||||
if (keyStore.entryInstanceOf(importAlias, KeyStore.PrivateKeyEntry.class)) {
|
||||
kssave = installReply(importAlias, inStream);
|
||||
if (kssave) {
|
||||
System.err.println(rb.getString
|
||||
("Certificate reply was installed in keystore"));
|
||||
} else {
|
||||
System.err.println(rb.getString
|
||||
("Certificate reply was not installed in keystore"));
|
||||
}
|
||||
} else if (!keyStore.containsAlias(importAlias) ||
|
||||
keyStore.entryInstanceOf(importAlias,
|
||||
KeyStore.TrustedCertificateEntry.class)) {
|
||||
kssave = addTrustedCert(importAlias, inStream);
|
||||
if (kssave) {
|
||||
System.err.println(rb.getString
|
||||
("Certificate was added to keystore"));
|
||||
} else {
|
||||
System.err.println(rb.getString
|
||||
("Certificate was not added to keystore"));
|
||||
}
|
||||
}
|
||||
} else if (command == IMPORTKEYSTORE) {
|
||||
doImportKeyStore();
|
||||
kssave = true;
|
||||
@ -2149,18 +2138,7 @@ public final class KeyTool {
|
||||
inStream = new FileInputStream(filename);
|
||||
}
|
||||
try {
|
||||
// Read the full stream before feeding to X509Factory,
|
||||
// otherwise, keytool -gencert | keytool -printcert
|
||||
// might not work properly, since -gencert is slow
|
||||
// and there's no data in the pipe at the beginning.
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
byte[] b = new byte[4096];
|
||||
while (true) {
|
||||
int len = inStream.read(b);
|
||||
if (len < 0) break;
|
||||
bout.write(b, 0, len);
|
||||
}
|
||||
printCertFromStream(new ByteArrayInputStream(bout.toByteArray()), out);
|
||||
printCertFromStream(inStream, out);
|
||||
} finally {
|
||||
if (inStream != System.in) {
|
||||
inStream.close();
|
||||
|
@ -40,7 +40,7 @@ bool bytes::inBounds(const void* p) {
|
||||
|
||||
void bytes::malloc(size_t len_) {
|
||||
len = len_;
|
||||
ptr = NEW(byte, len_+1); // add trailing zero byte always
|
||||
ptr = NEW(byte, add_size(len_, 1)); // add trailing zero byte always
|
||||
if (ptr == null) {
|
||||
// set ptr to some victim memory, to ease escape
|
||||
set(dummy, sizeof(dummy)-1);
|
||||
@ -56,7 +56,7 @@ void bytes::realloc(size_t len_) {
|
||||
return;
|
||||
}
|
||||
byte* oldptr = ptr;
|
||||
ptr = (len_ >= PSIZE_MAX) ? null : (byte*)::realloc(ptr, len_+1);
|
||||
ptr = (len_ >= PSIZE_MAX) ? null : (byte*)::realloc(ptr, add_size(len_, 1));
|
||||
if (ptr != null) {
|
||||
mtrace('r', oldptr, 0);
|
||||
mtrace('m', ptr, len_+1);
|
||||
|
@ -507,7 +507,7 @@ void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) {
|
||||
|
||||
maybe_inline
|
||||
void unpacker::saveTo(bytes& b, byte* ptr, size_t len) {
|
||||
b.ptr = U_NEW(byte, len+1);
|
||||
b.ptr = U_NEW(byte, add_size(len,1));
|
||||
if (aborting()) {
|
||||
b.len = 0;
|
||||
return;
|
||||
@ -1154,7 +1154,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||
*fillp = 0; // bigbuf must contain a well-formed Utf8 string
|
||||
int length = (int)(fillp - bigbuf.ptr);
|
||||
bytes& value = cpMap[i].value.b;
|
||||
value.set(U_NEW(byte, length+1), length);
|
||||
value.set(U_NEW(byte, add_size(length,1)), length);
|
||||
value.copyFrom(bigbuf.ptr, length);
|
||||
CHECK;
|
||||
// Index all Utf8 strings
|
||||
@ -1626,7 +1626,7 @@ unpacker::attr_definitions::popBody(int bs_base) {
|
||||
return no_bands;
|
||||
} else {
|
||||
int nb = bs_limit - bs_base;
|
||||
band** res = U_NEW(band*, nb+1);
|
||||
band** res = U_NEW(band*, add_size(nb, 1));
|
||||
CHECK_(no_bands);
|
||||
for (int i = 0; i < nb; i++) {
|
||||
band* b = (band*) band_stack.get(bs_base + i);
|
||||
@ -1735,7 +1735,7 @@ unpacker::attr_definitions::parseLayout(const char* lp, band** &res,
|
||||
}
|
||||
// save away the case labels
|
||||
int ntags = band_stack.length() - case_base;
|
||||
int* tags = U_NEW(int, 1+ntags);
|
||||
int* tags = U_NEW(int, add_size(ntags, 1));
|
||||
CHECK_(lp);
|
||||
k_case.le_casetags = tags;
|
||||
*tags++ = ntags;
|
||||
@ -3139,8 +3139,8 @@ void cpool::initMemberIndexes() {
|
||||
int* field_counts = T_NEW(int, nclasses);
|
||||
int* method_counts = T_NEW(int, nclasses);
|
||||
cpindex* all_indexes = U_NEW(cpindex, nclasses*2);
|
||||
entry** field_ix = U_NEW(entry*, nfields+nclasses);
|
||||
entry** method_ix = U_NEW(entry*, nmethods+nclasses);
|
||||
entry** field_ix = U_NEW(entry*, add_size(nfields, nclasses));
|
||||
entry** method_ix = U_NEW(entry*, add_size(nmethods, nclasses));
|
||||
|
||||
for (j = 0; j < nfields; j++) {
|
||||
entry& f = fields[j];
|
||||
@ -4132,7 +4132,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||
}
|
||||
const char* suffix = ".java";
|
||||
int len = (int)(prefix.len + strlen(suffix));
|
||||
bytes name; name.set(T_NEW(byte, len + 1), len);
|
||||
bytes name; name.set(T_NEW(byte, add_size(len, 1)), len);
|
||||
name.strcat(prefix).strcat(suffix);
|
||||
ref = cp.ensureUtf8(name);
|
||||
}
|
||||
@ -4647,7 +4647,7 @@ unpacker::file* unpacker::get_next_file() {
|
||||
bytes& prefix = cur_class->ref(0)->value.b;
|
||||
const char* suffix = ".class";
|
||||
int len = (int)(prefix.len + strlen(suffix));
|
||||
bytes name; name.set(T_NEW(byte, len + 1), len);
|
||||
bytes name; name.set(T_NEW(byte, add_size(len, 1)), len);
|
||||
cur_file.name = name.strcat(prefix).strcat(suffix).strval();
|
||||
}
|
||||
} else {
|
||||
@ -4714,6 +4714,7 @@ void unpacker::write_file_to_jar(unpacker::file* f) {
|
||||
input.ensureSize(fleft);
|
||||
}
|
||||
rplimit = rp = input.base();
|
||||
CHECK;
|
||||
input.setLimit(rp + fleft);
|
||||
if (!ensure_input(fleft))
|
||||
abort("EOF reading resource file");
|
||||
|
@ -67,10 +67,13 @@ Java_java_lang_System_identityHashCode(JNIEnv *env, jobject this, jobject x)
|
||||
(*env)->DeleteLocalRef(env, r); \
|
||||
} else ((void) 0)
|
||||
|
||||
#define PUTPROP_ForPlatformCString(props, key, val) \
|
||||
/* "key" is a char type string with only ASCII character in it.
|
||||
"val" is a nchar (typedefed in java_props.h) type string */
|
||||
|
||||
#define PUTPROP_ForPlatformNString(props, key, val) \
|
||||
if (1) { \
|
||||
jstring jkey = JNU_NewStringPlatform(env, key); \
|
||||
jstring jval = JNU_NewStringPlatform(env, val); \
|
||||
jstring jkey = (*env)->NewStringUTF(env, key); \
|
||||
jstring jval = GetStringPlatform(env, val); \
|
||||
jobject r = (*env)->CallObjectMethod(env, props, putID, jkey, jval); \
|
||||
if ((*env)->ExceptionOccurred(env)) return NULL; \
|
||||
(*env)->DeleteLocalRef(env, jkey); \
|
||||
@ -150,7 +153,7 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
|
||||
(sprops->cpu_isalist ? sprops->cpu_isalist : ""));
|
||||
PUTPROP(props, "sun.cpu.endian", sprops->cpu_endian);
|
||||
|
||||
/* !!! DO NOT call PUTPROP_ForPlatformCString before this line !!!
|
||||
/* !!! DO NOT call PUTPROP_ForPlatformNString before this line !!!
|
||||
* !!! I18n properties have not been set up yet !!!
|
||||
*/
|
||||
|
||||
@ -195,18 +198,18 @@ Java_java_lang_System_initProperties(JNIEnv *env, jclass cla, jobject props)
|
||||
*/
|
||||
PUTPROP(props, "java.awt.graphicsenv", sprops->graphics_env);
|
||||
if (sprops->font_dir != NULL) {
|
||||
PUTPROP_ForPlatformCString(props,
|
||||
PUTPROP_ForPlatformNString(props,
|
||||
"sun.java2d.fontpath", sprops->font_dir);
|
||||
}
|
||||
|
||||
PUTPROP_ForPlatformCString(props, "java.io.tmpdir", sprops->tmp_dir);
|
||||
PUTPROP_ForPlatformNString(props, "java.io.tmpdir", sprops->tmp_dir);
|
||||
|
||||
PUTPROP_ForPlatformCString(props, "user.name", sprops->user_name);
|
||||
PUTPROP_ForPlatformCString(props, "user.home", sprops->user_home);
|
||||
PUTPROP_ForPlatformNString(props, "user.name", sprops->user_name);
|
||||
PUTPROP_ForPlatformNString(props, "user.home", sprops->user_home);
|
||||
|
||||
PUTPROP(props, "user.timezone", sprops->timezone);
|
||||
|
||||
PUTPROP_ForPlatformCString(props, "user.dir", sprops->user_dir);
|
||||
PUTPROP_ForPlatformNString(props, "user.dir", sprops->user_dir);
|
||||
|
||||
/* This is a sun. property as it is currently only set for Gnome and
|
||||
* Windows desktops.
|
||||
|
@ -28,21 +28,29 @@
|
||||
|
||||
#include <jni_util.h>
|
||||
|
||||
/* The preferred native type for storing text on the current OS */
|
||||
#ifdef WIN32
|
||||
#include <tchar.h>
|
||||
typedef WCHAR nchar;
|
||||
#else
|
||||
typedef char nchar;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char *os_name;
|
||||
char *os_version;
|
||||
char *os_arch;
|
||||
|
||||
char *tmp_dir;
|
||||
char *font_dir;
|
||||
char *user_dir;
|
||||
nchar *tmp_dir;
|
||||
nchar *font_dir;
|
||||
nchar *user_dir;
|
||||
|
||||
char *file_separator;
|
||||
char *path_separator;
|
||||
char *line_separator;
|
||||
|
||||
char *user_name;
|
||||
char *user_home;
|
||||
nchar *user_name;
|
||||
nchar *user_home;
|
||||
|
||||
char *language;
|
||||
char *country;
|
||||
@ -71,5 +79,6 @@ typedef struct {
|
||||
} java_props_t;
|
||||
|
||||
java_props_t *GetJavaProperties(JNIEnv *env);
|
||||
jstring GetStringPlatform(JNIEnv *env, nchar* str);
|
||||
|
||||
#endif /* _JAVA_PROPS_H */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1997-2005 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
|
||||
@ -38,7 +38,6 @@
|
||||
|
||||
#define DEF_MEM_LEVEL 8
|
||||
|
||||
static jfieldID strmID;
|
||||
static jfieldID levelID;
|
||||
static jfieldID strategyID;
|
||||
static jfieldID setParamsID;
|
||||
@ -49,7 +48,6 @@ static jfieldID bufID, offID, lenID;
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Deflater_initIDs(JNIEnv *env, jclass cls)
|
||||
{
|
||||
strmID = (*env)->GetFieldID(env, cls, "strm", "J");
|
||||
levelID = (*env)->GetFieldID(env, cls, "level", "I");
|
||||
strategyID = (*env)->GetFieldID(env, cls, "strategy", "I");
|
||||
setParamsID = (*env)->GetFieldID(env, cls, "setParams", "Z");
|
||||
@ -94,7 +92,7 @@ Java_java_util_zip_Deflater_init(JNIEnv *env, jclass cls, jint level,
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Deflater_setDictionary(JNIEnv *env, jclass cls, jlong strm,
|
||||
Java_java_util_zip_Deflater_setDictionary(JNIEnv *env, jclass cls, jlong addr,
|
||||
jarray b, jint off, jint len)
|
||||
{
|
||||
Bytef *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0);
|
||||
@ -102,7 +100,7 @@ Java_java_util_zip_Deflater_setDictionary(JNIEnv *env, jclass cls, jlong strm,
|
||||
if (buf == 0) {/* out of memory */
|
||||
return;
|
||||
}
|
||||
res = deflateSetDictionary((z_stream *)jlong_to_ptr(strm), buf + off, len);
|
||||
res = deflateSetDictionary((z_stream *)jlong_to_ptr(addr), buf + off, len);
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0);
|
||||
switch (res) {
|
||||
case Z_OK:
|
||||
@ -111,151 +109,144 @@ Java_java_util_zip_Deflater_setDictionary(JNIEnv *env, jclass cls, jlong strm,
|
||||
JNU_ThrowIllegalArgumentException(env, 0);
|
||||
break;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, ((z_stream *)jlong_to_ptr(strm))->msg);
|
||||
JNU_ThrowInternalError(env, ((z_stream *)jlong_to_ptr(addr))->msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this,
|
||||
Java_java_util_zip_Deflater_deflateBytes(JNIEnv *env, jobject this, jlong addr,
|
||||
jarray b, jint off, jint len, jint flush)
|
||||
{
|
||||
z_stream *strm = jlong_to_ptr((*env)->GetLongField(env, this, strmID));
|
||||
z_stream *strm = jlong_to_ptr(addr);
|
||||
|
||||
if (strm == 0) {
|
||||
JNU_ThrowNullPointerException(env, 0);
|
||||
return 0;
|
||||
jarray this_buf = (*env)->GetObjectField(env, this, bufID);
|
||||
jint this_off = (*env)->GetIntField(env, this, offID);
|
||||
jint this_len = (*env)->GetIntField(env, this, lenID);
|
||||
jbyte *in_buf;
|
||||
jbyte *out_buf;
|
||||
int res;
|
||||
if ((*env)->GetBooleanField(env, this, setParamsID)) {
|
||||
int level = (*env)->GetIntField(env, this, levelID);
|
||||
int strategy = (*env)->GetIntField(env, this, strategyID);
|
||||
|
||||
in_buf = (jbyte *) malloc(this_len);
|
||||
if (in_buf == 0) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||
out_buf = (jbyte *) malloc(len);
|
||||
if (out_buf == 0) {
|
||||
free(in_buf);
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strm->next_in = (Bytef *) in_buf;
|
||||
strm->next_out = (Bytef *) out_buf;
|
||||
strm->avail_in = this_len;
|
||||
strm->avail_out = len;
|
||||
res = deflateParams(strm, level, strategy);
|
||||
|
||||
if (res == Z_OK) {
|
||||
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
|
||||
}
|
||||
free(out_buf);
|
||||
free(in_buf);
|
||||
|
||||
switch (res) {
|
||||
case Z_OK:
|
||||
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return len - strm->avail_out;
|
||||
case Z_BUF_ERROR:
|
||||
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
|
||||
return 0;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, strm->msg);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
jarray this_buf = (*env)->GetObjectField(env, this, bufID);
|
||||
jint this_off = (*env)->GetIntField(env, this, offID);
|
||||
jint this_len = (*env)->GetIntField(env, this, lenID);
|
||||
jbyte *in_buf;
|
||||
jbyte *out_buf;
|
||||
int res;
|
||||
if ((*env)->GetBooleanField(env, this, setParamsID)) {
|
||||
int level = (*env)->GetIntField(env, this, levelID);
|
||||
int strategy = (*env)->GetIntField(env, this, strategyID);
|
||||
jboolean finish = (*env)->GetBooleanField(env, this, finishID);
|
||||
in_buf = (jbyte *) malloc(this_len);
|
||||
if (in_buf == 0) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||
|
||||
in_buf = (jbyte *) malloc(this_len);
|
||||
if (in_buf == 0) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||
|
||||
out_buf = (jbyte *) malloc(len);
|
||||
if (out_buf == 0) {
|
||||
free(in_buf);
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strm->next_in = (Bytef *) in_buf;
|
||||
strm->next_out = (Bytef *) out_buf;
|
||||
strm->avail_in = this_len;
|
||||
strm->avail_out = len;
|
||||
res = deflateParams(strm, level, strategy);
|
||||
|
||||
if (res == Z_OK) {
|
||||
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
|
||||
}
|
||||
free(out_buf);
|
||||
out_buf = (jbyte *) malloc(len);
|
||||
if (out_buf == 0) {
|
||||
free(in_buf);
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (res) {
|
||||
case Z_OK:
|
||||
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return len - strm->avail_out;
|
||||
case Z_BUF_ERROR:
|
||||
(*env)->SetBooleanField(env, this, setParamsID, JNI_FALSE);
|
||||
return 0;
|
||||
strm->next_in = (Bytef *) in_buf;
|
||||
strm->next_out = (Bytef *) out_buf;
|
||||
strm->avail_in = this_len;
|
||||
strm->avail_out = len;
|
||||
res = deflate(strm, finish ? Z_FINISH : flush);
|
||||
|
||||
if (res == Z_STREAM_END || res == Z_OK) {
|
||||
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
|
||||
}
|
||||
free(out_buf);
|
||||
free(in_buf);
|
||||
|
||||
switch (res) {
|
||||
case Z_STREAM_END:
|
||||
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
|
||||
/* fall through */
|
||||
case Z_OK:
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return len - strm->avail_out;
|
||||
case Z_BUF_ERROR:
|
||||
return 0;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, strm->msg);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
jboolean finish = (*env)->GetBooleanField(env, this, finishID);
|
||||
|
||||
in_buf = (jbyte *) malloc(this_len);
|
||||
if (in_buf == 0) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||
|
||||
out_buf = (jbyte *) malloc(len);
|
||||
if (out_buf == 0) {
|
||||
free(in_buf);
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strm->next_in = (Bytef *) in_buf;
|
||||
strm->next_out = (Bytef *) out_buf;
|
||||
strm->avail_in = this_len;
|
||||
strm->avail_out = len;
|
||||
res = deflate(strm, finish ? Z_FINISH : flush);
|
||||
|
||||
if (res == Z_STREAM_END || res == Z_OK) {
|
||||
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
|
||||
}
|
||||
free(out_buf);
|
||||
free(in_buf);
|
||||
|
||||
switch (res) {
|
||||
case Z_STREAM_END:
|
||||
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
|
||||
/* fall through */
|
||||
case Z_OK:
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return len - strm->avail_out;
|
||||
case Z_BUF_ERROR:
|
||||
return 0;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, strm->msg);
|
||||
return 0;
|
||||
}
|
||||
JNU_ThrowInternalError(env, strm->msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_java_util_zip_Deflater_getAdler(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Deflater_getAdler(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
return ((z_stream *)jlong_to_ptr(strm))->adler;
|
||||
return ((z_stream *)jlong_to_ptr(addr))->adler;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_util_zip_Deflater_getBytesRead(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Deflater_getBytesRead(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
return ((z_stream *)jlong_to_ptr(strm))->total_in;
|
||||
return ((z_stream *)jlong_to_ptr(addr))->total_in;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_util_zip_Deflater_getBytesWritten(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Deflater_getBytesWritten(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
return ((z_stream *)jlong_to_ptr(strm))->total_out;
|
||||
return ((z_stream *)jlong_to_ptr(addr))->total_out;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Deflater_reset(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Deflater_reset(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
if (deflateReset((z_stream *)jlong_to_ptr(strm)) != Z_OK) {
|
||||
if (deflateReset((z_stream *)jlong_to_ptr(addr)) != Z_OK) {
|
||||
JNU_ThrowInternalError(env, 0);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Deflater_end(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Deflater_end(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
if (deflateEnd((z_stream *)jlong_to_ptr(strm)) == Z_STREAM_ERROR) {
|
||||
if (deflateEnd((z_stream *)jlong_to_ptr(addr)) == Z_STREAM_ERROR) {
|
||||
JNU_ThrowInternalError(env, 0);
|
||||
} else {
|
||||
free((z_stream *)jlong_to_ptr(strm));
|
||||
free((z_stream *)jlong_to_ptr(addr));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1997-2005 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
|
||||
@ -41,7 +41,6 @@
|
||||
#define ThrowDataFormatException(env, msg) \
|
||||
JNU_ThrowByName(env, "java/util/zip/DataFormatException", msg)
|
||||
|
||||
static jfieldID strmID;
|
||||
static jfieldID needDictID;
|
||||
static jfieldID finishedID;
|
||||
static jfieldID bufID, offID, lenID;
|
||||
@ -49,7 +48,6 @@ static jfieldID bufID, offID, lenID;
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Inflater_initIDs(JNIEnv *env, jclass cls)
|
||||
{
|
||||
strmID = (*env)->GetFieldID(env, cls, "strm", "J");
|
||||
needDictID = (*env)->GetFieldID(env, cls, "needDict", "Z");
|
||||
finishedID = (*env)->GetFieldID(env, cls, "finished", "Z");
|
||||
bufID = (*env)->GetFieldID(env, cls, "buf", "[B");
|
||||
@ -84,134 +82,129 @@ Java_java_util_zip_Inflater_init(JNIEnv *env, jclass cls, jboolean nowrap)
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Inflater_setDictionary(JNIEnv *env, jclass cls, jlong strm,
|
||||
Java_java_util_zip_Inflater_setDictionary(JNIEnv *env, jclass cls, jlong addr,
|
||||
jarray b, jint off, jint len)
|
||||
{
|
||||
Bytef *buf = (*env)->GetPrimitiveArrayCritical(env, b, 0);
|
||||
int res;
|
||||
if (buf == 0) /* out of memory */
|
||||
return;
|
||||
res = inflateSetDictionary(jlong_to_ptr(strm), buf + off, len);
|
||||
res = inflateSetDictionary(jlong_to_ptr(addr), buf + off, len);
|
||||
(*env)->ReleasePrimitiveArrayCritical(env, b, buf, 0);
|
||||
switch (res) {
|
||||
case Z_OK:
|
||||
break;
|
||||
case Z_STREAM_ERROR:
|
||||
case Z_DATA_ERROR:
|
||||
JNU_ThrowIllegalArgumentException(env, ((z_stream *)jlong_to_ptr(strm))->msg);
|
||||
JNU_ThrowIllegalArgumentException(env, ((z_stream *)jlong_to_ptr(addr))->msg);
|
||||
break;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, ((z_stream *)jlong_to_ptr(strm))->msg);
|
||||
JNU_ThrowInternalError(env, ((z_stream *)jlong_to_ptr(addr))->msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this,
|
||||
Java_java_util_zip_Inflater_inflateBytes(JNIEnv *env, jobject this, jlong addr,
|
||||
jarray b, jint off, jint len)
|
||||
{
|
||||
z_stream *strm = jlong_to_ptr((*env)->GetLongField(env, this, strmID));
|
||||
z_stream *strm = jlong_to_ptr(addr);
|
||||
|
||||
if (strm == 0) {
|
||||
JNU_ThrowNullPointerException(env, 0);
|
||||
jarray this_buf = (jarray)(*env)->GetObjectField(env, this, bufID);
|
||||
jint this_off = (*env)->GetIntField(env, this, offID);
|
||||
jint this_len = (*env)->GetIntField(env, this, lenID);
|
||||
jbyte *in_buf;
|
||||
jbyte *out_buf;
|
||||
int ret;
|
||||
|
||||
in_buf = (jbyte *) malloc(this_len);
|
||||
if (in_buf == 0) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
} else {
|
||||
jarray this_buf = (jarray)(*env)->GetObjectField(env, this, bufID);
|
||||
jint this_off = (*env)->GetIntField(env, this, offID);
|
||||
jint this_len = (*env)->GetIntField(env, this, lenID);
|
||||
jbyte *in_buf;
|
||||
jbyte *out_buf;
|
||||
int ret;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||
|
||||
in_buf = (jbyte *) malloc(this_len);
|
||||
if (in_buf == 0) {
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, this_buf, this_off, this_len, in_buf);
|
||||
|
||||
out_buf = (jbyte *) malloc(len);
|
||||
if (out_buf == 0) {
|
||||
free(in_buf);
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
strm->next_in = (Bytef *) in_buf;
|
||||
strm->next_out = (Bytef *) out_buf;
|
||||
strm->avail_in = this_len;
|
||||
strm->avail_out = len;
|
||||
ret = inflate(strm, Z_PARTIAL_FLUSH);
|
||||
|
||||
if (ret == Z_STREAM_END || ret == Z_OK) {
|
||||
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
|
||||
}
|
||||
free(out_buf);
|
||||
out_buf = (jbyte *) malloc(len);
|
||||
if (out_buf == 0) {
|
||||
free(in_buf);
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (ret) {
|
||||
case Z_STREAM_END:
|
||||
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
|
||||
/* fall through */
|
||||
case Z_OK:
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return len - strm->avail_out;
|
||||
case Z_NEED_DICT:
|
||||
(*env)->SetBooleanField(env, this, needDictID, JNI_TRUE);
|
||||
/* Might have consumed some input here! */
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return 0;
|
||||
case Z_BUF_ERROR:
|
||||
return 0;
|
||||
case Z_DATA_ERROR:
|
||||
ThrowDataFormatException(env, strm->msg);
|
||||
return 0;
|
||||
case Z_MEM_ERROR:
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, strm->msg);
|
||||
return 0;
|
||||
}
|
||||
strm->next_in = (Bytef *) in_buf;
|
||||
strm->next_out = (Bytef *) out_buf;
|
||||
strm->avail_in = this_len;
|
||||
strm->avail_out = len;
|
||||
ret = inflate(strm, Z_PARTIAL_FLUSH);
|
||||
|
||||
if (ret == Z_STREAM_END || ret == Z_OK) {
|
||||
(*env)->SetByteArrayRegion(env, b, off, len - strm->avail_out, out_buf);
|
||||
}
|
||||
free(out_buf);
|
||||
free(in_buf);
|
||||
|
||||
switch (ret) {
|
||||
case Z_STREAM_END:
|
||||
(*env)->SetBooleanField(env, this, finishedID, JNI_TRUE);
|
||||
/* fall through */
|
||||
case Z_OK:
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return len - strm->avail_out;
|
||||
case Z_NEED_DICT:
|
||||
(*env)->SetBooleanField(env, this, needDictID, JNI_TRUE);
|
||||
/* Might have consumed some input here! */
|
||||
this_off += this_len - strm->avail_in;
|
||||
(*env)->SetIntField(env, this, offID, this_off);
|
||||
(*env)->SetIntField(env, this, lenID, strm->avail_in);
|
||||
return 0;
|
||||
case Z_BUF_ERROR:
|
||||
return 0;
|
||||
case Z_DATA_ERROR:
|
||||
ThrowDataFormatException(env, strm->msg);
|
||||
return 0;
|
||||
case Z_MEM_ERROR:
|
||||
JNU_ThrowOutOfMemoryError(env, 0);
|
||||
return 0;
|
||||
default:
|
||||
JNU_ThrowInternalError(env, strm->msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Inflater_getAdler(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
return ((z_stream *)jlong_to_ptr(strm))->adler;
|
||||
return ((z_stream *)jlong_to_ptr(addr))->adler;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_util_zip_Inflater_getBytesRead(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Inflater_getBytesRead(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
return ((z_stream *)jlong_to_ptr(strm))->total_in;
|
||||
return ((z_stream *)jlong_to_ptr(addr))->total_in;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_util_zip_Inflater_getBytesWritten(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Inflater_getBytesWritten(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
return ((z_stream *)jlong_to_ptr(strm))->total_out;
|
||||
return ((z_stream *)jlong_to_ptr(addr))->total_out;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Inflater_reset(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Inflater_reset(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
if (inflateReset(jlong_to_ptr(strm)) != Z_OK) {
|
||||
if (inflateReset(jlong_to_ptr(addr)) != Z_OK) {
|
||||
JNU_ThrowInternalError(env, 0);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_util_zip_Inflater_end(JNIEnv *env, jclass cls, jlong strm)
|
||||
Java_java_util_zip_Inflater_end(JNIEnv *env, jclass cls, jlong addr)
|
||||
{
|
||||
if (inflateEnd(jlong_to_ptr(strm)) == Z_STREAM_ERROR) {
|
||||
if (inflateEnd(jlong_to_ptr(addr)) == Z_STREAM_ERROR) {
|
||||
JNU_ThrowInternalError(env, 0);
|
||||
} else {
|
||||
free(jlong_to_ptr(strm));
|
||||
free(jlong_to_ptr(addr));
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,8 @@ ThrowZipException(JNIEnv *env, const char *msg)
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
|
||||
jint mode, jlong lastModified)
|
||||
jint mode, jlong lastModified,
|
||||
jboolean usemmap)
|
||||
{
|
||||
const char *path = JNU_GetStringPlatformChars(env, name, 0);
|
||||
char *msg = 0;
|
||||
@ -109,7 +110,7 @@ Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
|
||||
goto finally;
|
||||
}
|
||||
#endif
|
||||
zip = ZIP_Put_In_Cache(path, zfd, &msg, lastModified);
|
||||
zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap);
|
||||
}
|
||||
|
||||
if (zip != 0) {
|
||||
|
@ -251,11 +251,16 @@ freeZip(jzfile *zip)
|
||||
if (zip->lock != NULL) MDESTROY(zip->lock);
|
||||
free(zip->name);
|
||||
freeCEN(zip);
|
||||
|
||||
#ifdef USE_MMAP
|
||||
if (zip->maddr != NULL) munmap((char *)zip->maddr, zip->mlen);
|
||||
#else
|
||||
free(zip->cencache.data);
|
||||
if (zip->usemmap) {
|
||||
if (zip->maddr != NULL)
|
||||
munmap((char *)zip->maddr, zip->mlen);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
free(zip->cencache.data);
|
||||
}
|
||||
if (zip->comment != NULL)
|
||||
free(zip->comment);
|
||||
if (zip->zfd != -1) ZFILE_Close(zip->zfd);
|
||||
@ -585,49 +590,53 @@ readCEN(jzfile *zip, jint knownTotal)
|
||||
ZIP_FORMAT_ERROR("invalid END header (bad central directory offset)");
|
||||
|
||||
#ifdef USE_MMAP
|
||||
/* On Solaris & Linux prior to JDK 6, we used to mmap the whole jar file to
|
||||
* read the jar file contents. However, this greatly increased the perceived
|
||||
* footprint numbers because the mmap'ed pages were adding into the totals shown
|
||||
* by 'ps' and 'top'. We switched to mmaping only the central directory of jar
|
||||
* file while calling 'read' to read the rest of jar file. Here are a list of
|
||||
* reasons apart from above of why we are doing so:
|
||||
* 1. Greatly reduces mmap overhead after startup complete;
|
||||
* 2. Avoids dual path code maintainance;
|
||||
* 3. Greatly reduces risk of address space (not virtual memory) exhaustion.
|
||||
*/
|
||||
if (pagesize == 0) {
|
||||
pagesize = (jlong)sysconf(_SC_PAGESIZE);
|
||||
if (pagesize == 0) goto Catch;
|
||||
}
|
||||
if (cenpos > pagesize) {
|
||||
offset = cenpos & ~(pagesize - 1);
|
||||
} else {
|
||||
offset = 0;
|
||||
}
|
||||
/* When we are not calling recursively, knownTotal is -1. */
|
||||
if (knownTotal == -1) {
|
||||
void* mappedAddr;
|
||||
/* Mmap the CEN and END part only. We have to figure
|
||||
out the page size in order to make offset to be multiples of
|
||||
page size.
|
||||
*/
|
||||
zip->mlen = cenpos - offset + cenlen + endhdrlen;
|
||||
zip->offset = offset;
|
||||
mappedAddr = mmap64(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, (off64_t) offset);
|
||||
zip->maddr = (mappedAddr == (void*) MAP_FAILED) ? NULL :
|
||||
(unsigned char*)mappedAddr;
|
||||
|
||||
if (zip->maddr == NULL) {
|
||||
jio_fprintf(stderr, "mmap failed for CEN and END part of zip file\n");
|
||||
goto Catch;
|
||||
if (zip->usemmap) {
|
||||
/* On Solaris & Linux prior to JDK 6, we used to mmap the whole jar file to
|
||||
* read the jar file contents. However, this greatly increased the perceived
|
||||
* footprint numbers because the mmap'ed pages were adding into the totals shown
|
||||
* by 'ps' and 'top'. We switched to mmaping only the central directory of jar
|
||||
* file while calling 'read' to read the rest of jar file. Here are a list of
|
||||
* reasons apart from above of why we are doing so:
|
||||
* 1. Greatly reduces mmap overhead after startup complete;
|
||||
* 2. Avoids dual path code maintainance;
|
||||
* 3. Greatly reduces risk of address space (not virtual memory) exhaustion.
|
||||
*/
|
||||
if (pagesize == 0) {
|
||||
pagesize = (jlong)sysconf(_SC_PAGESIZE);
|
||||
if (pagesize == 0) goto Catch;
|
||||
}
|
||||
}
|
||||
cenbuf = zip->maddr + cenpos - offset;
|
||||
#else
|
||||
if ((cenbuf = malloc((size_t) cenlen)) == NULL ||
|
||||
(readFullyAt(zip->zfd, cenbuf, cenlen, cenpos) == -1))
|
||||
goto Catch;
|
||||
if (cenpos > pagesize) {
|
||||
offset = cenpos & ~(pagesize - 1);
|
||||
} else {
|
||||
offset = 0;
|
||||
}
|
||||
/* When we are not calling recursively, knownTotal is -1. */
|
||||
if (knownTotal == -1) {
|
||||
void* mappedAddr;
|
||||
/* Mmap the CEN and END part only. We have to figure
|
||||
out the page size in order to make offset to be multiples of
|
||||
page size.
|
||||
*/
|
||||
zip->mlen = cenpos - offset + cenlen + endhdrlen;
|
||||
zip->offset = offset;
|
||||
mappedAddr = mmap64(0, zip->mlen, PROT_READ, MAP_SHARED, zip->zfd, (off64_t) offset);
|
||||
zip->maddr = (mappedAddr == (void*) MAP_FAILED) ? NULL :
|
||||
(unsigned char*)mappedAddr;
|
||||
|
||||
if (zip->maddr == NULL) {
|
||||
jio_fprintf(stderr, "mmap failed for CEN and END part of zip file\n");
|
||||
goto Catch;
|
||||
}
|
||||
}
|
||||
cenbuf = zip->maddr + cenpos - offset;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if ((cenbuf = malloc((size_t) cenlen)) == NULL ||
|
||||
(readFullyAt(zip->zfd, cenbuf, cenlen, cenpos) == -1))
|
||||
goto Catch;
|
||||
}
|
||||
|
||||
cenend = cenbuf + cenlen;
|
||||
|
||||
/* Initialize zip file data structures based on the total number
|
||||
@ -700,9 +709,11 @@ readCEN(jzfile *zip, jint knownTotal)
|
||||
cenpos = -1;
|
||||
|
||||
Finally:
|
||||
#ifndef USE_MMAP
|
||||
free(cenbuf);
|
||||
#ifdef USE_MMAP
|
||||
if (!zip->usemmap)
|
||||
#endif
|
||||
free(cenbuf);
|
||||
|
||||
return cenpos;
|
||||
}
|
||||
|
||||
@ -782,8 +793,16 @@ ZIP_Get_From_Cache(const char *name, char **pmsg, jlong lastModified)
|
||||
* If a zip error occurs, then *pmsg will be set to the error message text if
|
||||
* pmsg != 0. Otherwise, *pmsg will be set to NULL.
|
||||
*/
|
||||
|
||||
jzfile *
|
||||
ZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified)
|
||||
{
|
||||
return ZIP_Put_In_Cache0(name, zfd, pmsg, lastModified, JNI_TRUE);
|
||||
}
|
||||
|
||||
jzfile *
|
||||
ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified,
|
||||
jboolean usemmap)
|
||||
{
|
||||
static char errbuf[256];
|
||||
jlong len;
|
||||
@ -793,6 +812,9 @@ ZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef USE_MMAP
|
||||
zip->usemmap = usemmap;
|
||||
#endif
|
||||
zip->refs = 1;
|
||||
zip->lastModified = lastModified;
|
||||
|
||||
@ -877,8 +899,6 @@ ZIP_Close(jzfile *zip)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef USE_MMAP
|
||||
|
||||
/* Empirically, most CEN headers are smaller than this. */
|
||||
#define AMPLE_CEN_HEADER_SIZE 160
|
||||
|
||||
@ -928,7 +948,6 @@ sequentialAccessReadCENHeader(jzfile *zip, jlong cenpos)
|
||||
cache->pos = cenpos;
|
||||
return cen;
|
||||
}
|
||||
#endif /* not USE_MMAP */
|
||||
|
||||
typedef enum { ACCESS_RANDOM, ACCESS_SEQUENTIAL } AccessHint;
|
||||
|
||||
@ -953,14 +972,17 @@ newEntry(jzfile *zip, jzcell *zc, AccessHint accessHint)
|
||||
ze->comment = NULL;
|
||||
|
||||
#ifdef USE_MMAP
|
||||
cen = (char*) zip->maddr + zc->cenpos - zip->offset;
|
||||
#else
|
||||
if (accessHint == ACCESS_RANDOM)
|
||||
cen = readCENHeader(zip, zc->cenpos, AMPLE_CEN_HEADER_SIZE);
|
||||
else
|
||||
cen = sequentialAccessReadCENHeader(zip, zc->cenpos);
|
||||
if (cen == NULL) goto Catch;
|
||||
if (zip->usemmap) {
|
||||
cen = (char*) zip->maddr + zc->cenpos - zip->offset;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (accessHint == ACCESS_RANDOM)
|
||||
cen = readCENHeader(zip, zc->cenpos, AMPLE_CEN_HEADER_SIZE);
|
||||
else
|
||||
cen = sequentialAccessReadCENHeader(zip, zc->cenpos);
|
||||
if (cen == NULL) goto Catch;
|
||||
}
|
||||
|
||||
nlen = CENNAM(cen);
|
||||
elen = CENEXT(cen);
|
||||
@ -976,7 +998,6 @@ newEntry(jzfile *zip, jzcell *zc, AccessHint accessHint)
|
||||
if ((ze->name = malloc(nlen + 1)) == NULL) goto Catch;
|
||||
memcpy(ze->name, cen + CENHDR, nlen);
|
||||
ze->name[nlen] = '\0';
|
||||
|
||||
if (elen > 0) {
|
||||
char *extra = cen + CENHDR + nlen;
|
||||
|
||||
@ -1037,9 +1058,10 @@ newEntry(jzfile *zip, jzcell *zc, AccessHint accessHint)
|
||||
ze = NULL;
|
||||
|
||||
Finally:
|
||||
#ifndef USE_MMAP
|
||||
if (cen != NULL && accessHint == ACCESS_RANDOM) free(cen);
|
||||
#ifdef USE_MMAP
|
||||
if (!zip->usemmap)
|
||||
#endif
|
||||
if (cen != NULL && accessHint == ACCESS_RANDOM) free(cen);
|
||||
return ze;
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,6 @@
|
||||
* Header sizes including signatures
|
||||
*/
|
||||
|
||||
#ifdef USE_MMAP
|
||||
#define SIGSIZ 4
|
||||
#endif
|
||||
#define LOCHDR 30
|
||||
#define EXTHDR 16
|
||||
#define CENHDR 46
|
||||
@ -211,9 +208,9 @@ typedef struct jzfile { /* Zip file */
|
||||
jlong mlen; /* length (in bytes) mmaped */
|
||||
jlong offset; /* offset of the mmapped region from the
|
||||
start of the file. */
|
||||
#else
|
||||
cencache cencache; /* CEN header cache */
|
||||
jboolean usemmap; /* if mmap is used. */
|
||||
#endif
|
||||
cencache cencache; /* CEN header cache */
|
||||
ZFILE zfd; /* open file descriptor */
|
||||
void *lock; /* read lock */
|
||||
char *comment; /* zip file comment */
|
||||
@ -259,6 +256,9 @@ ZIP_Get_From_Cache(const char *name, char **pmsg, jlong lastModified);
|
||||
jzfile *
|
||||
ZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified);
|
||||
|
||||
jzfile *
|
||||
ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified, jboolean usemmap);
|
||||
|
||||
void JNICALL
|
||||
ZIP_Close(jzfile *zip);
|
||||
|
||||
|
@ -258,6 +258,7 @@ static void clearStreamBuffer(streamBufferPtr sb) {
|
||||
|
||||
typedef struct pixelBufferStruct {
|
||||
jobject hpixelObject; // Usually a DataBuffer bank as a byte array
|
||||
unsigned int byteBufferLength;
|
||||
union pixptr {
|
||||
INT32 *ip; // Pinned buffer pointer, as 32-bit ints
|
||||
unsigned char *bp; // Pinned buffer pointer, as bytes
|
||||
@ -270,6 +271,7 @@ typedef struct pixelBufferStruct {
|
||||
*/
|
||||
static void initPixelBuffer(pixelBufferPtr pb) {
|
||||
pb->hpixelObject = NULL;
|
||||
pb->byteBufferLength = 0;
|
||||
pb->buf.ip = NULL;
|
||||
}
|
||||
|
||||
@ -279,13 +281,13 @@ static void initPixelBuffer(pixelBufferPtr pb) {
|
||||
*/
|
||||
static int setPixelBuffer(JNIEnv *env, pixelBufferPtr pb, jobject obj) {
|
||||
pb->hpixelObject = (*env)->NewGlobalRef(env, obj);
|
||||
|
||||
if (pb->hpixelObject == NULL) {
|
||||
JNU_ThrowByName( env,
|
||||
"java/lang/OutOfMemoryError",
|
||||
"Setting Pixel Buffer");
|
||||
return NOT_OK;
|
||||
}
|
||||
pb->byteBufferLength = (*env)->GetArrayLength(env, pb->hpixelObject);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -302,6 +304,7 @@ static void resetPixelBuffer(JNIEnv *env, pixelBufferPtr pb) {
|
||||
unpinPixelBuffer(env, pb);
|
||||
(*env)->DeleteGlobalRef(env, pb->hpixelObject);
|
||||
pb->hpixelObject = NULL;
|
||||
pb->byteBufferLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1828,6 +1831,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage
|
||||
boolean orderedBands = TRUE;
|
||||
imageIODataPtr data = (imageIODataPtr) ptr;
|
||||
j_decompress_ptr cinfo;
|
||||
unsigned int numBytes;
|
||||
|
||||
/* verify the inputs */
|
||||
|
||||
@ -2027,15 +2031,22 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage
|
||||
// scanline buffer into the raster.
|
||||
in = scanLinePtr + (sourceXStart * cinfo->output_components);
|
||||
if (pixelLimit > in) {
|
||||
memcpy(out, in, pixelLimit - in);
|
||||
numBytes = pixelLimit - in;
|
||||
if (numBytes > data->pixelBuf.byteBufferLength) {
|
||||
numBytes = data->pixelBuf.byteBufferLength;
|
||||
}
|
||||
memcpy(out, in, numBytes);
|
||||
}
|
||||
} else {
|
||||
numBytes = numBands;
|
||||
for (in = scanLinePtr+sourceXStart*cinfo->output_components;
|
||||
in < pixelLimit;
|
||||
in < pixelLimit &&
|
||||
numBytes <= data->pixelBuf.byteBufferLength;
|
||||
in += pixelStride) {
|
||||
for (i = 0; i < numBands; i++) {
|
||||
*out++ = *(in+bands[i]);
|
||||
}
|
||||
numBytes += numBands;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2239,7 +2239,8 @@ allocateRasterArray(JNIEnv *env, RasterS_t *rasterP,
|
||||
int dataType = BYTE_DATA_TYPE;
|
||||
int width;
|
||||
int height;
|
||||
int size = rasterP->width * rasterP->height * rasterP->numBands;
|
||||
int dataSize;
|
||||
int offset;
|
||||
|
||||
*dataPP = NULL;
|
||||
|
||||
@ -2292,6 +2293,22 @@ allocateRasterArray(JNIEnv *env, RasterS_t *rasterP,
|
||||
#endif
|
||||
switch (rasterP->type) {
|
||||
case sun_awt_image_IntegerComponentRaster_TYPE_INT_8BIT_SAMPLES:
|
||||
if (!((rasterP->chanOffsets[0] == 0 || SAFE_TO_ALLOC_2(rasterP->chanOffsets[0], 4)) &&
|
||||
SAFE_TO_ALLOC_2(width, 4) &&
|
||||
SAFE_TO_ALLOC_3(height, rasterP->scanlineStride, 4)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
offset = 4 * rasterP->chanOffsets[0];
|
||||
dataSize = 4 * (*env)->GetArrayLength(env, rasterP->jdata);
|
||||
|
||||
if (offset < 0 || offset >= dataSize ||
|
||||
width > rasterP->scanlineStride ||
|
||||
height * rasterP->scanlineStride * 4 > dataSize - offset)
|
||||
{
|
||||
// raster data buffer is too short
|
||||
return -1;
|
||||
}
|
||||
dataP = (void *) (*env)->GetPrimitiveArrayCritical(env, rasterP->jdata,
|
||||
NULL);
|
||||
if (dataP == NULL) {
|
||||
@ -2300,11 +2317,25 @@ allocateRasterArray(JNIEnv *env, RasterS_t *rasterP,
|
||||
*mlibImagePP = (*sMlibSysFns.createStructFP)(MLIB_BYTE, 4,
|
||||
width, height,
|
||||
rasterP->scanlineStride*4,
|
||||
(unsigned char *)dataP
|
||||
+ rasterP->chanOffsets[0]*4);
|
||||
(unsigned char *)dataP + offset);
|
||||
*dataPP = dataP;
|
||||
return 0;
|
||||
case sun_awt_image_IntegerComponentRaster_TYPE_BYTE_SAMPLES:
|
||||
if (!(SAFE_TO_ALLOC_2(width, rasterP->numBands) &&
|
||||
SAFE_TO_ALLOC_2(height, rasterP->scanlineStride)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
offset = rasterP->chanOffsets[0];
|
||||
dataSize = (*env)->GetArrayLength(env, rasterP->jdata);
|
||||
|
||||
if (offset < 0 || offset >= dataSize ||
|
||||
width * rasterP->numBands > rasterP->scanlineStride ||
|
||||
height * rasterP->scanlineStride > dataSize - offset)
|
||||
{
|
||||
// raster data buffer is too short
|
||||
return -1;
|
||||
}
|
||||
dataP = (void *) (*env)->GetPrimitiveArrayCritical(env, rasterP->jdata,
|
||||
NULL);
|
||||
if (dataP == NULL) {
|
||||
@ -2313,11 +2344,26 @@ allocateRasterArray(JNIEnv *env, RasterS_t *rasterP,
|
||||
*mlibImagePP = (*sMlibSysFns.createStructFP)(MLIB_BYTE, rasterP->numBands,
|
||||
width, height,
|
||||
rasterP->scanlineStride,
|
||||
(unsigned char *)dataP
|
||||
+ rasterP->chanOffsets[0]);
|
||||
(unsigned char *)dataP + offset);
|
||||
*dataPP = dataP;
|
||||
return 0;
|
||||
case sun_awt_image_IntegerComponentRaster_TYPE_USHORT_SAMPLES:
|
||||
if (!((rasterP->chanOffsets[0] == 0 || SAFE_TO_ALLOC_2(rasterP->chanOffsets[0], 2)) &&
|
||||
SAFE_TO_ALLOC_3(width, rasterP->numBands, 2) &&
|
||||
SAFE_TO_ALLOC_3(height, rasterP->scanlineStride, 2)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
offset = rasterP->chanOffsets[0] * 2;
|
||||
dataSize = 2 * (*env)->GetArrayLength(env, rasterP->jdata);
|
||||
|
||||
if (offset < 0 || offset >= dataSize ||
|
||||
width * rasterP->numBands > rasterP->scanlineStride ||
|
||||
height * rasterP->scanlineStride * 2 > dataSize - offset)
|
||||
{
|
||||
// raster data buffer is too short
|
||||
return -1;
|
||||
}
|
||||
dataP = (void *) (*env)->GetPrimitiveArrayCritical(env, rasterP->jdata,
|
||||
NULL);
|
||||
if (dataP == NULL) {
|
||||
@ -2327,8 +2373,7 @@ allocateRasterArray(JNIEnv *env, RasterS_t *rasterP,
|
||||
rasterP->numBands,
|
||||
width, height,
|
||||
rasterP->scanlineStride*2,
|
||||
(unsigned char *)dataP
|
||||
+ rasterP->chanOffsets[0]*2);
|
||||
(unsigned char *)dataP + offset);
|
||||
*dataPP = dataP;
|
||||
return 0;
|
||||
|
||||
|
@ -35,11 +35,11 @@
|
||||
*/
|
||||
#define SAFE_TO_ALLOC_2(c, sz) \
|
||||
(((c) > 0) && ((sz) > 0) && \
|
||||
((0xffffffffu / ((juint)(c))) > (sz)))
|
||||
((0xffffffffu / ((juint)(c))) > ((juint)(sz))))
|
||||
|
||||
#define SAFE_TO_ALLOC_3(w, h, sz) \
|
||||
(((w) > 0) && ((h) > 0) && ((sz) > 0) && \
|
||||
(((0xffffffffu / ((juint)(w))) / ((juint)(h))) > (sz)))
|
||||
(((0xffffffffu / ((juint)(w))) / ((juint)(h))) > ((juint)(sz))))
|
||||
|
||||
|
||||
#endif // __SAFE_ALLOC_H__
|
||||
|
@ -1433,6 +1433,9 @@ LPLUT LCMSEXPORT cmsReadICCLut(cmsHPROFILE hProfile, icTagSignature sig)
|
||||
|
||||
// If is in memory, the LUT is already there, so throw a copy
|
||||
if (Icc -> TagPtrs[n]) {
|
||||
if (!_cmsValidateLUT((LPLUT) Icc ->TagPtrs[n])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cmsDupLUT((LPLUT) Icc ->TagPtrs[n]);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user