diff options
Diffstat (limited to 'src/share/classes/java')
-rw-r--r-- | src/share/classes/java/awt/Font.java | 4 | ||||
-rw-r--r-- | src/share/classes/java/beans/DefaultPersistenceDelegate.java | 19 | ||||
-rw-r--r-- | src/share/classes/java/beans/MetaData.java | 98 | ||||
-rw-r--r-- | src/share/classes/java/beans/XMLEncoder.java | 25 | ||||
-rw-r--r-- | src/share/classes/java/lang/AbstractStringBuilder.java | 2 | ||||
-rw-r--r-- | src/share/classes/java/lang/Character.java | 1283 | ||||
-rw-r--r-- | src/share/classes/java/lang/CharacterName.java | 106 | ||||
-rw-r--r-- | src/share/classes/java/net/URI.java | 2 | ||||
-rw-r--r-- | src/share/classes/java/util/jar/JarVerifier.java | 2 | ||||
-rw-r--r-- | src/share/classes/java/util/regex/Pattern.java | 101 | ||||
-rw-r--r-- | src/share/classes/java/util/zip/GZIPInputStream.java | 87 | ||||
-rw-r--r-- | src/share/classes/java/util/zip/GZIPOutputStream.java | 90 | ||||
-rw-r--r-- | src/share/classes/java/util/zip/ZipException.java | 6 | ||||
-rw-r--r-- | src/share/classes/java/util/zip/package.html | 15 |
14 files changed, 1665 insertions, 175 deletions
diff --git a/src/share/classes/java/awt/Font.java b/src/share/classes/java/awt/Font.java index 44aac6da1..0657391e0 100644 --- a/src/share/classes/java/awt/Font.java +++ b/src/share/classes/java/awt/Font.java @@ -343,6 +343,10 @@ public class Font implements java.io.Serializable * Identify a font resource of type TRUETYPE. * Used to specify a TrueType font resource to the * {@link #createFont} method. + * The TrueType format was extended to become the OpenType + * format, which adds support for fonts with Postscript outlines, + * this tag therefore references these fonts, as well as those + * with TrueType outlines. * @since 1.3 */ diff --git a/src/share/classes/java/beans/DefaultPersistenceDelegate.java b/src/share/classes/java/beans/DefaultPersistenceDelegate.java index a02588f29..d5c24edcb 100644 --- a/src/share/classes/java/beans/DefaultPersistenceDelegate.java +++ b/src/share/classes/java/beans/DefaultPersistenceDelegate.java @@ -222,6 +222,25 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { // Write out the properties of this instance. private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) { + for (Field field : type.getFields()) { + int mod = field.getModifiers(); + if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) { + continue; + } + try { + Expression oldGetExp = new Expression(field, "get", new Object[] { oldInstance }); + Expression newGetExp = new Expression(field, "get", new Object[] { newInstance }); + Object oldValue = oldGetExp.getValue(); + Object newValue = newGetExp.getValue(); + out.writeExpression(oldGetExp); + if (!equals(newValue, out.get(oldValue))) { + out.writeStatement(new Statement(field, "set", new Object[] { oldInstance, oldValue })); + } + } + catch (Exception exception) { + out.getExceptionListener().exceptionThrown(exception); + } + } BeanInfo info; try { info = Introspector.getBeanInfo(type); diff --git a/src/share/classes/java/beans/MetaData.java b/src/share/classes/java/beans/MetaData.java index 578402129..12c4f81ec 100644 --- a/src/share/classes/java/beans/MetaData.java +++ b/src/share/classes/java/beans/MetaData.java @@ -701,56 +701,6 @@ class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java // AWT /** - * The persistence delegate for {@link Dimension}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because all getters have return types that differ from parameter types - * of the constructor {@link Dimension#Dimension(int, int)}. - * - * @author Sergey A. Malenkov - */ -final class java_awt_Dimension_PersistenceDelegate extends PersistenceDelegate { - protected boolean mutatesTo(Object oldInstance, Object newInstance) { - return oldInstance.equals(newInstance); - } - - protected Expression instantiate(Object oldInstance, Encoder out) { - Dimension dimension = (Dimension) oldInstance; - Object[] args = new Object[] { - dimension.width, - dimension.height, - }; - return new Expression(dimension, dimension.getClass(), "new", args); - } -} - -/** - * The persistence delegate for {@link GridBagConstraints}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because this class does not have any properties. - * - * @author Sergey A. Malenkov - */ -final class java_awt_GridBagConstraints_PersistenceDelegate extends PersistenceDelegate { - protected Expression instantiate(Object oldInstance, Encoder out) { - GridBagConstraints gbc = (GridBagConstraints) oldInstance; - Object[] args = new Object[] { - gbc.gridx, - gbc.gridy, - gbc.gridwidth, - gbc.gridheight, - gbc.weightx, - gbc.weighty, - gbc.anchor, - gbc.fill, - gbc.insets, - gbc.ipadx, - gbc.ipady, - }; - return new Expression(gbc, gbc.getClass(), "new", args); - } -} - -/** * The persistence delegate for {@link Insets}. * It is impossible to use {@link DefaultPersistenceDelegate} * because this class does not have any properties. @@ -775,54 +725,6 @@ final class java_awt_Insets_PersistenceDelegate extends PersistenceDelegate { } /** - * The persistence delegate for {@link Point}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because all getters have return types that differ from parameter types - * of the constructor {@link Point#Point(int, int)}. - * - * @author Sergey A. Malenkov - */ -final class java_awt_Point_PersistenceDelegate extends PersistenceDelegate { - protected boolean mutatesTo(Object oldInstance, Object newInstance) { - return oldInstance.equals(newInstance); - } - - protected Expression instantiate(Object oldInstance, Encoder out) { - Point point = (Point) oldInstance; - Object[] args = new Object[] { - point.x, - point.y, - }; - return new Expression(point, point.getClass(), "new", args); - } -} - -/** - * The persistence delegate for {@link Rectangle}. - * It is impossible to use {@link DefaultPersistenceDelegate} - * because all getters have return types that differ from parameter types - * of the constructor {@link Rectangle#Rectangle(int, int, int, int)}. - * - * @author Sergey A. Malenkov - */ -final class java_awt_Rectangle_PersistenceDelegate extends PersistenceDelegate { - protected boolean mutatesTo(Object oldInstance, Object newInstance) { - return oldInstance.equals(newInstance); - } - - protected Expression instantiate(Object oldInstance, Encoder out) { - Rectangle rectangle = (Rectangle) oldInstance; - Object[] args = new Object[] { - rectangle.x, - rectangle.y, - rectangle.width, - rectangle.height, - }; - return new Expression(rectangle, rectangle.getClass(), "new", args); - } -} - -/** * The persistence delegate for {@link Font}. * It is impossible to use {@link DefaultPersistenceDelegate} * because size of the font can be float value. diff --git a/src/share/classes/java/beans/XMLEncoder.java b/src/share/classes/java/beans/XMLEncoder.java index 970b86e25..d4b37da58 100644 --- a/src/share/classes/java/beans/XMLEncoder.java +++ b/src/share/classes/java/beans/XMLEncoder.java @@ -407,7 +407,20 @@ public class XMLEncoder extends Encoder { os.writeObject(this); */ mark(oldStm); - statementList(oldStm.getTarget()).add(oldStm); + Object target = oldStm.getTarget(); + if (target instanceof Field) { + String method = oldStm.getMethodName(); + Object[] args = oldStm.getArguments(); + if ((method == null) || (args == null)) { + } + else if (method.equals("get") && (args.length == 1)) { + target = args[0]; + } + else if (method.equals("set") && (args.length == 2)) { + target = args[0]; + } + } + statementList(target).add(oldStm); } catch (Exception e) { getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e)); @@ -703,7 +716,9 @@ public class XMLEncoder extends Encoder { statements.add(exp); } outputValue(target, outer, false); - outputValue(value, outer, isArgument); + if (expression) { + outputValue(value, outer, isArgument); + } return; } if (expression && (d.refs > 1)) { @@ -722,8 +737,10 @@ public class XMLEncoder extends Encoder { } else if ((!expression && methodName.startsWith("set") && args.length == 1) || (expression && methodName.startsWith("get") && args.length == 0)) { - attributes = attributes + " property=" + - quote(Introspector.decapitalize(methodName.substring(3))); + if (3 < methodName.length()) { + attributes = attributes + " property=" + + quote(Introspector.decapitalize(methodName.substring(3))); + } } else if (!methodName.equals("new") && !methodName.equals("newInstance")) { attributes = attributes + " method=" + quote(methodName); diff --git a/src/share/classes/java/lang/AbstractStringBuilder.java b/src/share/classes/java/lang/AbstractStringBuilder.java index 156937c37..f83da439c 100644 --- a/src/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/share/classes/java/lang/AbstractStringBuilder.java @@ -117,7 +117,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * size check or synchronization. */ void expandCapacity(int minimumCapacity) { - int newCapacity = value.length * 2; + int newCapacity = value.length * 2 + 2; if (newCapacity - minimumCapacity < 0) newCapacity = minimumCapacity; if (newCapacity < 0) { diff --git a/src/share/classes/java/lang/Character.java b/src/share/classes/java/lang/Character.java index 48488825d..14fce5581 100644 --- a/src/share/classes/java/lang/Character.java +++ b/src/share/classes/java/lang/Character.java @@ -24,6 +24,7 @@ */ package java.lang; +import java.util.Arrays; import java.util.Map; import java.util.HashMap; import java.util.Locale; @@ -2547,6 +2548,1241 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara /** + * A family of character subsets representing the character scripts + * defined in the <a href="http://www.unicode.org/reports/tr24/"> + * <i>Unicode Standard Annex #24: Script Names</i></a>. Every Unicode + * character is assigned to a single Unicode script, either a specific + * script, such as {@link Character.UnicodeScript#LATIN Latin}, or + * one of the following three special values, + * {@link Character.UnicodeScript#INHERITED Inherited}, + * {@link Character.UnicodeScript#COMMON Common} or + * {@link Character.UnicodeScript#UNKNOWN Unknown}. + * + * @since 1.7 + */ + public static enum UnicodeScript { + /** + * Unicode script "Common". + */ + COMMON, + + /** + * Unicode script "Latin". + */ + LATIN, + + /** + * Unicode script "Greek". + */ + GREEK, + + /** + * Unicode script "Cyrillic". + */ + CYRILLIC, + + /** + * Unicode script "Armenian". + */ + ARMENIAN, + + /** + * Unicode script "Hebrew". + */ + HEBREW, + + /** + * Unicode script "Arabic". + */ + ARABIC, + + /** + * Unicode script "Syriac". + */ + SYRIAC, + + /** + * Unicode script "Thaana". + */ + THAANA, + + /** + * Unicode script "Devanagari". + */ + DEVANAGARI, + + /** + * Unicode script "Bengali". + */ + BENGALI, + + /** + * Unicode script "Gurmukhi". + */ + GURMUKHI, + + /** + * Unicode script "Gujarati". + */ + GUJARATI, + + /** + * Unicode script "Oriya". + */ + ORIYA, + + /** + * Unicode script "Tamil". + */ + TAMIL, + + /** + * Unicode script "Telugu". + */ + TELUGU, + + /** + * Unicode script "Kannada". + */ + KANNADA, + + /** + * Unicode script "Malayalam". + */ + MALAYALAM, + + /** + * Unicode script "Sinhala". + */ + SINHALA, + + /** + * Unicode script "Thai". + */ + THAI, + + /** + * Unicode script "Lao". + */ + LAO, + + /** + * Unicode script "Tibetan". + */ + TIBETAN, + + /** + * Unicode script "Myanmar". + */ + MYANMAR, + + /** + * Unicode script "Georgian". + */ + GEORGIAN, + + /** + * Unicode script "Hangul". + */ + HANGUL, + + /** + * Unicode script "Ethiopic". + */ + ETHIOPIC, + + /** + * Unicode script "Cherokee". + */ + CHEROKEE, + + /** + * Unicode script "Canadian_Aboriginal". + */ + CANADIAN_ABORIGINAL, + + /** + * Unicode script "Ogham". + */ + OGHAM, + + /** + * Unicode script "Runic". + */ + RUNIC, + + /** + * Unicode script "Khmer". + */ + KHMER, + + /** + * Unicode script "Mongolian". + */ + MONGOLIAN, + + /** + * Unicode script "Hiragana". + */ + HIRAGANA, + + /** + * Unicode script "Katakana". + */ + KATAKANA, + + /** + * Unicode script "Bopomofo". + */ + BOPOMOFO, + + /** + * Unicode script "Han". + */ + HAN, + + /** + * Unicode script "Yi". + */ + YI, + + /** + * Unicode script "Old_Italic". + */ + OLD_ITALIC, + + /** + * Unicode script "Gothic". + */ + GOTHIC, + + /** + * Unicode script "Deseret". + */ + DESERET, + + /** + * Unicode script "Inherited". + */ + INHERITED, + + /** + * Unicode script "Tagalog". + */ + TAGALOG, + + /** + * Unicode script "Hanunoo". + */ + HANUNOO, + + /** + * Unicode script "Buhid". + */ + BUHID, + + /** + * Unicode script "Tagbanwa". + */ + TAGBANWA, + + /** + * Unicode script "Limbu". + */ + LIMBU, + + /** + * Unicode script "Tai_Le". + */ + TAI_LE, + + /** + * Unicode script "Linear_B". + */ + LINEAR_B, + + /** + * Unicode script "Ugaritic". + */ + UGARITIC, + + /** + * Unicode script "Shavian". + */ + SHAVIAN, + + /** + * Unicode script "Osmanya". + */ + OSMANYA, + + /** + * Unicode script "Cypriot". + */ + CYPRIOT, + + /** + * Unicode script "Braille". + */ + BRAILLE, + + /** + * Unicode script "Buginese". + */ + BUGINESE, + + /** + * Unicode script "Coptic". + */ + COPTIC, + + /** + * Unicode script "New_Tai_Lue". + */ + NEW_TAI_LUE, + + /** + * Unicode script "Glagolitic". + */ + GLAGOLITIC, + + /** + * Unicode script "Tifinagh". + */ + TIFINAGH, + + /** + * Unicode script "Syloti_Nagri". + */ + SYLOTI_NAGRI, + + /** + * Unicode script "Old_Persian". + */ + OLD_PERSIAN, + + /** + * Unicode script "Kharoshthi". + */ + KHAROSHTHI, + + /** + * Unicode script "Balinese". + */ + BALINESE, + + /** + * Unicode script "Cuneiform". + */ + CUNEIFORM, + + /** + * Unicode script "Phoenician". + */ + PHOENICIAN, + + /** + * Unicode script "Phags_Pa". + */ + PHAGS_PA, + + /** + * Unicode script "Nko". + */ + NKO, + + /** + * Unicode script "Sundanese". + */ + SUNDANESE, + + /** + * Unicode script "Lepcha". + */ + LEPCHA, + + /** + * Unicode script "Ol_Chiki". + */ + OL_CHIKI, + + /** + * Unicode script "Vai". + */ + VAI, + + /** + * Unicode script "Saurashtra". + */ + SAURASHTRA, + + /** + * Unicode script "Kayah_Li". + */ + KAYAH_LI, + + /** + * Unicode script "Rejang". + */ + REJANG, + + /** + * Unicode script "Lycian". + */ + LYCIAN, + + /** + * Unicode script "Carian". + */ + CARIAN, + + /** + * Unicode script "Lydian". + */ + LYDIAN, + + /** + * Unicode script "Cham". + */ + CHAM, + + /** + * Unicode script "Tai_Tham". + */ + TAI_THAM, + + /** + * Unicode script "Tai_Viet". + */ + TAI_VIET, + + /** + * Unicode script "Avestan". + */ + AVESTAN, + + /** + * Unicode script "Egyptian_Hieroglyphs". + */ + EGYPTIAN_HIEROGLYPHS, + + /** + * Unicode script "Samaritan". + */ + SAMARITAN, + + /** + * Unicode script "Lisu". + */ + LISU, + + /** + * Unicode script "Bamum". + */ + BAMUM, + + /** + * Unicode script "Javanese". + */ + JAVANESE, + + /** + * Unicode script "Meetei_Mayek". + */ + MEETEI_MAYEK, + + /** + * Unicode script "Imperial_Aramaic". + */ + IMPERIAL_ARAMAIC, + + /** + * Unicode script "Old_South_Arabian". + */ + OLD_SOUTH_ARABIAN, + + /** + * Unicode script "Inscriptional_Parthian". + */ + INSCRIPTIONAL_PARTHIAN, + + /** + * Unicode script "Inscriptional_Pahlavi". + */ + INSCRIPTIONAL_PAHLAVI, + + /** + * Unicode script "Old_Turkic". + */ + OLD_TURKIC, + + /** + * Unicode script "Kaithi". + */ + KAITHI, + + /** + * Unicode script "Unknown". + */ + UNKNOWN; + + private static final int[] scriptStarts = { + 0x0000, // 0000..0040; COMMON + 0x0041, // 0041..005A; LATIN + 0x005B, // 005B..0060; COMMON + 0x0061, // 0061..007A; LATIN + 0x007B, // 007B..00A9; COMMON + 0x00AA, // 00AA..00AA; LATIN + 0x00AB, // 00AB..00B9; COMMON + 0x00BA, // 00BA..00BA; LATIN + 0x00BB, // 00BB..00BF; COMMON + 0x00C0, // 00C0..00D6; LATIN + 0x00D7, // 00D7..00D7; COMMON + 0x00D8, // 00D8..00F6; LATIN + 0x00F7, // 00F7..00F7; COMMON + 0x00F8, // 00F8..02B8; LATIN + 0x02B9, // 02B9..02DF; COMMON + 0x02E0, // 02E0..02E4; LATIN + 0x02E5, // 02E5..02FF; COMMON + 0x0300, // 0300..036F; INHERITED + 0x0370, // 0370..0373; GREEK + 0x0374, // 0374..0374; COMMON + 0x0375, // 0375..037D; GREEK + 0x037E, // 037E..0383; COMMON + 0x0384, // 0384..0384; GREEK + 0x0385, // 0385..0385; COMMON + 0x0386, // 0386..0386; GREEK + 0x0387, // 0387..0387; COMMON + 0x0388, // 0388..03E1; GREEK + 0x03E2, // 03E2..03EF; COPTIC + 0x03F0, // 03F0..03FF; GREEK + 0x0400, // 0400..0484; CYRILLIC + 0x0485, // 0485..0486; INHERITED + 0x0487, // 0487..0530; CYRILLIC + 0x0531, // 0531..0588; ARMENIAN + 0x0589, // 0589..0589; COMMON + 0x058A, // 058A..0590; ARMENIAN + 0x0591, // 0591..05FF; HEBREW + 0x0600, // 0600..0605; COMMON + 0x0606, // 0606..060B; ARABIC + 0x060C, // 060C..060C; COMMON + 0x060D, // 060D..061A; ARABIC + 0x061B, // 061B..061D; COMMON + 0x061E, // 061E..061E; ARABIC + 0x061F, // 061F..0620; COMMON + 0x0621, // 0621..063F; ARABIC + 0x0640, // 0640..0640; COMMON + 0x0641, // 0641..064A; ARABIC + 0x064B, // 064B..0655; INHERITED + 0x0656, // 0656..065F; ARABIC + 0x0660, // 0660..0669; COMMON + 0x066A, // 066A..066F; ARABIC + 0x0670, // 0670..0670; INHERITED + 0x0671, // 0671..06DC; ARABIC + 0x06DD, // 06DD..06DD; COMMON + 0x06DE, // 06DE..06FF; ARABIC + 0x0700, // 0700..074F; SYRIAC + 0x0750, // 0750..077F; ARABIC + 0x0780, // 0780..07BF; THAANA + 0x07C0, // 07C0..07FF; NKO + 0x0800, // 0800..08FF; SAMARITAN + 0x0900, // 0900..0950; DEVANAGARI + 0x0951, // 0951..0952; INHERITED + 0x0953, // 0953..0963; DEVANAGARI + 0x0964, // 0964..0965; COMMON + 0x0966, // 0966..096F; DEVANAGARI + 0x0970, // 0970..0970; COMMON + 0x0971, // 0971..0980; DEVANAGARI + 0x0981, // 0981..0A00; BENGALI + 0x0A01, // 0A01..0A80; GURMUKHI + 0x0A81, // 0A81..0B00; GUJARATI + 0x0B01, // 0B01..0B81; ORIYA + 0x0B82, // 0B82..0C00; TAMIL + 0x0C01, // 0C01..0C81; TELUGU + 0x0C82, // 0C82..0CF0; KANNADA + 0x0CF1, // 0CF1..0D01; COMMON + 0x0D02, // 0D02..0D81; MALAYALAM + 0x0D82, // 0D82..0E00; SINHALA + 0x0E01, // 0E01..0E3E; THAI + 0x0E3F, // 0E3F..0E3F; COMMON + 0x0E40, // 0E40..0E80; THAI + 0x0E81, // 0E81..0EFF; LAO + 0x0F00, // 0F00..0FD4; TIBETAN + 0x0FD5, // 0FD5..0FFF; COMMON + 0x1000, // 1000..109F; MYANMAR + 0x10A0, // 10A0..10FA; GEORGIAN + 0x10FB, // 10FB..10FB; COMMON + 0x10FC, // 10FC..10FF; GEORGIAN + 0x1100, // 1100..11FF; HANGUL + 0x1200, // 1200..139F; ETHIOPIC + 0x13A0, // 13A0..13FF; CHEROKEE + 0x1400, // 1400..167F; CANADIAN_ABORIGINAL + 0x1680, // 1680..169F; OGHAM + 0x16A0, // 16A0..16EA; RUNIC + 0x16EB, // 16EB..16ED; COMMON + 0x16EE, // 16EE..16FF; RUNIC + 0x1700, // 1700..171F; TAGALOG + 0x1720, // 1720..1734; HANUNOO + 0x1735, // 1735..173F; COMMON + 0x1740, // 1740..175F; BUHID + 0x1760, // 1760..177F; TAGBANWA + 0x1780, // 1780..17FF; KHMER + 0x1800, // 1800..1801; MONGOLIAN + 0x1802, // 1802..1803; COMMON + 0x1804, // 1804..1804; MONGOLIAN + 0x1805, // 1805..1805; COMMON + 0x1806, // 1806..18AF; MONGOLIAN + 0x18B0, // 18B0..18FF; CANADIAN_ABORIGINAL + 0x1900, // 1900..194F; LIMBU + 0x1950, // 1950..197F; TAI_LE + 0x1980, // 1980..19DF; NEW_TAI_LUE + 0x19E0, // 19E0..19FF; KHMER + 0x1A00, // 1A00..1A1F; BUGINESE + 0x1A20, // 1A20..1AFF; TAI_THAM + 0x1B00, // 1B00..1B7F; BALINESE + 0x1B80, // 1B80..1BFF; SUNDANESE + 0x1C00, // 1C00..1C4F; LEPCHA + 0x1C50, // 1C50..1CCF; OL_CHIKI + 0x1CD0, // 1CD0..1CD2; INHERITED + 0x1CD3, // 1CD3..1CD3; COMMON + 0x1CD4, // 1CD4..1CE0; INHERITED + 0x1CE1, // 1CE1..1CE1; COMMON + 0x1CE2, // 1CE2..1CE8; INHERITED + 0x1CE9, // 1CE9..1CEC; COMMON + 0x1CED, // 1CED..1CED; INHERITED + 0x1CEE, // 1CEE..1CFF; COMMON + 0x1D00, // 1D00..1D25; LATIN + 0x1D26, // 1D26..1D2A; GREEK + 0x1D2B, // 1D2B..1D2B; CYRILLIC + 0x1D2C, // 1D2C..1D5C; LATIN + 0x1D5D, // 1D5D..1D61; GREEK + 0x1D62, // 1D62..1D65; LATIN + 0x1D66, // 1D66..1D6A; GREEK + 0x1D6B, // 1D6B..1D77; LATIN + 0x1D78, // 1D78..1D78; CYRILLIC + 0x1D79, // 1D79..1DBE; LATIN + 0x1DBF, // 1DBF..1DBF; GREEK + 0x1DC0, // 1DC0..1DFF; INHERITED + 0x1E00, // 1E00..1EFF; LATIN + 0x1F00, // 1F00..1FFF; GREEK + 0x2000, // 2000..200B; COMMON + 0x200C, // 200C..200D; INHERITED + 0x200E, // 200E..2070; COMMON + 0x2071, // 2071..2073; LATIN + 0x2074, // 2074..207E; COMMON + 0x207F, // 207F..207F; LATIN + 0x2080, // 2080..208F; COMMON + 0x2090, // 2090..209F; LATIN + 0x20A0, // 20A0..20CF; COMMON + 0x20D0, // 20D0..20FF; INHERITED + 0x2100, // 2100..2125; COMMON + 0x2126, // 2126..2126; GREEK + 0x2127, // 2127..2129; COMMON + 0x212A, // 212A..212B; LATIN + 0x212C, // 212C..2131; COMMON + 0x2132, // 2132..2132; LATIN + 0x2133, // 2133..214D; COMMON + 0x214E, // 214E..214E; LATIN + 0x214F, // 214F..215F; COMMON + 0x2160, // 2160..2188; LATIN + 0x2189, // 2189..27FF; COMMON + 0x2800, // 2800..28FF; BRAILLE + 0x2900, // 2900..2BFF; COMMON + 0x2C00, // 2C00..2C5F; GLAGOLITIC + 0x2C60, // 2C60..2C7F; LATIN + 0x2C80, // 2C80..2CFF; COPTIC + 0x2D00, // 2D00..2D2F; GEORGIAN + 0x2D30, // 2D30..2D7F; TIFINAGH + 0x2D80, // 2D80..2DDF; ETHIOPIC + 0x2DE0, // 2DE0..2DFF; CYRILLIC + 0x2E00, // 2E00..2E7F; COMMON + 0x2E80, // 2E80..2FEF; HAN + 0x2FF0, // 2FF0..3004; COMMON + 0x3005, // 3005..3005; HAN + 0x3006, // 3006..3006; COMMON + 0x3007, // 3007..3007; HAN + 0x3008, // 3008..3020; COMMON + 0x3021, // 3021..3029; HAN + 0x302A, // 302A..302F; INHERITED + 0x3030, // 3030..3037; COMMON + 0x3038, // 3038..303B; HAN + 0x303C, // 303C..3040; COMMON + 0x3041, // 3041..3098; HIRAGANA + 0x3099, // 3099..309A; INHERITED + 0x309B, // 309B..309C; COMMON + 0x309D, // 309D..309F; HIRAGANA + 0x30A0, // 30A0..30A0; COMMON + 0x30A1, // 30A1..30FA; KATAKANA + 0x30FB, // 30FB..30FC; COMMON + 0x30FD, // 30FD..3104; KATAKANA + 0x3105, // 3105..3130; BOPOMOFO + 0x3131, // 3131..318F; HANGUL + 0x3190, // 3190..319F; COMMON + 0x31A0, // 31A0..31BF; BOPOMOFO + 0x31C0, // 31C0..31EF; COMMON + 0x31F0, // 31F0..31FF; KATAKANA + 0x3200, // 3200..321F; HANGUL + 0x3220, // 3220..325F; COMMON + 0x3260, // 3260..327E; HANGUL + 0x327F, // 327F..32CF; COMMON + 0x32D0, // 32D0..3357; KATAKANA + 0x3358, // 3358..33FF; COMMON + 0x3400, // 3400..4DBF; HAN + 0x4DC0, // 4DC0..4DFF; COMMON + 0x4E00, // 4E00..9FFF; HAN + 0xA000, // A000..A4CF; YI + 0xA4D0, // A4D0..A4FF; LISU + 0xA500, // A500..A63F; VAI + 0xA640, // A640..A69F; CYRILLIC + 0xA6A0, // A6A0..A6FF; BAMUM + 0xA700, // A700..A721; COMMON + 0xA722, // A722..A787; LATIN + 0xA788, // A788..A78A; COMMON + 0xA78B, // A78B..A7FF; LATIN + 0xA800, // A800..A82F; SYLOTI_NAGRI + 0xA830, // A830..A83F; COMMON + 0xA840, // A840..A87F; PHAGS_PA + 0xA880, // A880..A8DF; SAURASHTRA + 0xA8E0, // A8E0..A8FF; DEVANAGARI + 0xA900, // A900..A92F; KAYAH_LI + 0xA930, // A930..A95F; REJANG + 0xA960, // A960..A97F; HANGUL + 0xA980, // A980..A9FF; JAVANESE + 0xAA00, // AA00..AA5F; CHAM + 0xAA60, // AA60..AA7F; MYANMAR + 0xAA80, // AA80..ABBF; TAI_VIET + 0xABC0, // ABC0..ABFF; MEETEI_MAYEK + 0xAC00, // AC00..D7FB; HANGUL + 0xD7FC, // D7FC..F8FF; UNKNOWN + 0xF900, // F900..FAFF; HAN + 0xFB00, // FB00..FB12; LATIN + 0xFB13, // FB13..FB1C; ARMENIAN + 0xFB1D, // FB1D..FB4F; HEBREW + 0xFB50, // FB50..FD3D; ARABIC + 0xFD3E, // FD3E..FD4F; COMMON + 0xFD50, // FD50..FDFC; ARABIC + 0xFDFD, // FDFD..FDFF; COMMON + 0xFE00, // FE00..FE0F; INHERITED + 0xFE10, // FE10..FE1F; COMMON + 0xFE20, // FE20..FE2F; INHERITED + 0xFE30, // FE30..FE6F; COMMON + 0xFE70, // FE70..FEFE; ARABIC + 0xFEFF, // FEFF..FF20; COMMON + 0xFF21, // FF21..FF3A; LATIN + 0xFF3B, // FF3B..FF40; COMMON + 0xFF41, // FF41..FF5A; LATIN + 0xFF5B, // FF5B..FF65; COMMON + 0xFF66, // FF66..FF6F; KATAKANA + 0xFF70, // FF70..FF70; COMMON + 0xFF71, // FF71..FF9D; KATAKANA + 0xFF9E, // FF9E..FF9F; COMMON + 0xFFA0, // FFA0..FFDF; HANGUL + 0xFFE0, // FFE0..FFFF; COMMON + 0x10000, // 10000..100FF; LINEAR_B + 0x10100, // 10100..1013F; COMMON + 0x10140, // 10140..1018F; GREEK + 0x10190, // 10190..101FC; COMMON + 0x101FD, // 101FD..1027F; INHERITED + 0x10280, // 10280..1029F; LYCIAN + 0x102A0, // 102A0..102FF; CARIAN + 0x10300, // 10300..1032F; OLD_ITALIC + 0x10330, // 10330..1037F; GOTHIC + 0x10380, // 10380..1039F; UGARITIC + 0x103A0, // 103A0..103FF; OLD_PERSIAN + 0x10400, // 10400..1044F; DESERET + 0x10450, // 10450..1047F; SHAVIAN + 0x10480, // 10480..107FF; OSMANYA + 0x10800, // 10800..1083F; CYPRIOT + 0x10840, // 10840..108FF; IMPERIAL_ARAMAIC + 0x10900, // 10900..1091F; PHOENICIAN + 0x10920, // 10920..109FF; LYDIAN + 0x10A00, // 10A00..10A5F; KHAROSHTHI + 0x10A60, // 10A60..10AFF; OLD_SOUTH_ARABIAN + 0x10B00, // 10B00..10B3F; AVESTAN + 0x10B40, // 10B40..10B5F; INSCRIPTIONAL_PARTHIAN + 0x10B60, // 10B60..10BFF; INSCRIPTIONAL_PAHLAVI + 0x10C00, // 10C00..10E5F; OLD_TURKIC + 0x10E60, // 10E60..1107F; ARABIC + 0x11080, // 11080..11FFF; KAITHI + 0x12000, // 12000..12FFF; CUNEIFORM + 0x13000, // 13000..1CFFF; EGYPTIAN_HIEROGLYPHS + 0x1D000, // 1D000..1D166; COMMON + 0x1D167, // 1D167..1D169; INHERITED + 0x1D16A, // 1D16A..1D17A; COMMON + 0x1D17B, // 1D17B..1D182; INHERITED + 0x1D183, // 1D183..1D184; COMMON + 0x1D185, // 1D185..1D18B; INHERITED + 0x1D18C, // 1D18C..1D1A9; COMMON + 0x1D1AA, // 1D1AA..1D1AD; INHERITED + 0x1D1AE, // 1D1AE..1D1FF; COMMON + 0x1D200, // 1D200..1D2FF; GREEK + 0x1D300, // 1D300..1F1FF; COMMON + 0x1F200, // 1F200..1F20F; HIRAGANA + 0x1F210, // 1F210..1FFFF; COMMON + 0x20000, // 20000..E0000; HAN + 0xE0001, // E0001..E00FF; COMMON + 0xE0100, // E0100..E01EF; INHERITED + 0xE01F0 // E01F0..10FFFF; UNKNOWN + + }; + + private static final UnicodeScript[] scripts = { + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + INHERITED, + GREEK, + COMMON, + GREEK, + COMMON, + GREEK, + COMMON, + GREEK, + COMMON, + GREEK, + COPTIC, + GREEK, + CYRILLIC, + INHERITED, + CYRILLIC, + ARMENIAN, + COMMON, + ARMENIAN, + HEBREW, + COMMON, + ARABIC, + COMMON, + ARABIC, + COMMON, + ARABIC, + COMMON, + ARABIC, + COMMON, + ARABIC, + INHERITED, + ARABIC, + COMMON, + ARABIC, + INHERITED, + ARABIC, + COMMON, + ARABIC, + SYRIAC, + ARABIC, + THAANA, + NKO, + SAMARITAN, + DEVANAGARI, + INHERITED, + DEVANAGARI, + COMMON, + DEVANAGARI, + COMMON, + DEVANAGARI, + BENGALI, + GURMUKHI, + GUJARATI, + ORIYA, + TAMIL, + TELUGU, + KANNADA, + COMMON, + MALAYALAM, + SINHALA, + THAI, + COMMON, + THAI, + LAO, + TIBETAN, + COMMON, + MYANMAR, + GEORGIAN, + COMMON, + GEORGIAN, + HANGUL, + ETHIOPIC, + CHEROKEE, + CANADIAN_ABORIGINAL, + OGHAM, + RUNIC, + COMMON, + RUNIC, + TAGALOG, + HANUNOO, + COMMON, + BUHID, + TAGBANWA, + KHMER, + MONGOLIAN, + COMMON, + MONGOLIAN, + COMMON, + MONGOLIAN, + CANADIAN_ABORIGINAL, + LIMBU, + TAI_LE, + NEW_TAI_LUE, + KHMER, + BUGINESE, + TAI_THAM, + BALINESE, + SUNDANESE, + LEPCHA, + OL_CHIKI, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + LATIN, + GREEK, + CYRILLIC, + LATIN, + GREEK, + LATIN, + GREEK, + LATIN, + CYRILLIC, + LATIN, + GREEK, + INHERITED, + LATIN, + GREEK, + COMMON, + INHERITED, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + INHERITED, + COMMON, + GREEK, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + BRAILLE, + COMMON, + GLAGOLITIC, + LATIN, + COPTIC, + GEORGIAN, + TIFINAGH, + ETHIOPIC, + CYRILLIC, + COMMON, + HAN, + COMMON, + HAN, + COMMON, + HAN, + COMMON, + HAN, + INHERITED, + COMMON, + HAN, + COMMON, + HIRAGANA, + INHERITED, + COMMON, + HIRAGANA, + COMMON, + KATAKANA, + COMMON, + KATAKANA, + BOPOMOFO, + HANGUL, + COMMON, + BOPOMOFO, + COMMON, + KATAKANA, + HANGUL, + COMMON, + HANGUL, + COMMON, + KATAKANA, + COMMON, + HAN, + COMMON, + HAN, + YI, + LISU, + VAI, + CYRILLIC, + BAMUM, + COMMON, + LATIN, + COMMON, + LATIN, + SYLOTI_NAGRI, + COMMON, + PHAGS_PA, + SAURASHTRA, + DEVANAGARI, + KAYAH_LI, + REJANG, + HANGUL, + JAVANESE, + CHAM, + MYANMAR, + TAI_VIET, + MEETEI_MAYEK, + HANGUL, + UNKNOWN, + HAN, + LATIN, + ARMENIAN, + HEBREW, + ARABIC, + COMMON, + ARABIC, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + ARABIC, + COMMON, + LATIN, + COMMON, + LATIN, + COMMON, + KATAKANA, + COMMON, + KATAKANA, + COMMON, + HANGUL, + COMMON, + LINEAR_B, + COMMON, + GREEK, + COMMON, + INHERITED, + LYCIAN, + CARIAN, + OLD_ITALIC, + GOTHIC, + UGARITIC, + OLD_PERSIAN, + DESERET, + SHAVIAN, + OSMANYA, + CYPRIOT, + IMPERIAL_ARAMAIC, + PHOENICIAN, + LYDIAN, + KHAROSHTHI, + OLD_SOUTH_ARABIAN, + AVESTAN, + INSCRIPTIONAL_PARTHIAN, + INSCRIPTIONAL_PAHLAVI, + OLD_TURKIC, + ARABIC, + KAITHI, + CUNEIFORM, + EGYPTIAN_HIEROGLYPHS, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + INHERITED, + COMMON, + GREEK, + COMMON, + HIRAGANA, + COMMON, + HAN, + COMMON, + INHERITED, + UNKNOWN + }; + + private static HashMap<String, Character.UnicodeScript> aliases; + static { + aliases = new HashMap<String, UnicodeScript>(); + aliases.put("ARAB", ARABIC); + aliases.put("ARMI", IMPERIAL_ARAMAIC); + aliases.put("ARMN", ARMENIAN); + aliases.put("AVST", AVESTAN); + aliases.put("BALI", BALINESE); + aliases.put("BAMU", BAMUM); + aliases.put("BENG", BENGALI); + aliases.put("BOPO", BOPOMOFO); + aliases.put("BRAI", BRAILLE); + aliases.put("BUGI", BUGINESE); + aliases.put("BUHD", BUHID); + aliases.put("CANS", CANADIAN_ABORIGINAL); + aliases.put("CARI", CARIAN); + aliases.put("CHAM", CHAM); + aliases.put("CHER", CHEROKEE); + aliases.put("COPT", COPTIC); + aliases.put("CPRT", CYPRIOT); + aliases.put("CYRL", CYRILLIC); + aliases.put("DEVA", DEVANAGARI); + aliases.put("DSRT", DESERET); + aliases.put("EGYP", EGYPTIAN_HIEROGLYPHS); + aliases.put("ETHI", ETHIOPIC); + aliases.put("GEOR", GEORGIAN); + aliases.put("GLAG", GLAGOLITIC); + aliases.put("GOTH", GOTHIC); + aliases.put("GREK", GREEK); + aliases.put("GUJR", GUJARATI); + aliases.put("GURU", GURMUKHI); + aliases.put("HANG", HANGUL); + aliases.put("HANI", HAN); + aliases.put("HANO", HANUNOO); + aliases.put("HEBR", HEBREW); + aliases.put("HIRA", HIRAGANA); + // it appears we don't have the KATAKANA_OR_HIRAGANA + //aliases.put("HRKT", KATAKANA_OR_HIRAGANA); + aliases.put("ITAL", OLD_ITALIC); + aliases.put("JAVA", JAVANESE); + aliases.put("KALI", KAYAH_LI); + aliases.put("KANA", KATAKANA); + aliases.put("KHAR", KHAROSHTHI); + aliases.put("KHMR", KHMER); + aliases.put("KNDA", KANNADA); + aliases.put("KTHI", KAITHI); + aliases.put("LANA", TAI_THAM); + aliases.put("LAOO", LAO); + aliases.put("LATN", LATIN); + aliases.put("LEPC", LEPCHA); + aliases.put("LIMB", LIMBU); + aliases.put("LINB", LINEAR_B); + aliases.put("LISU", LISU); + aliases.put("LYCI", LYCIAN); + aliases.put("LYDI", LYDIAN); + aliases.put("MLYM", MALAYALAM); + aliases.put("MONG", MONGOLIAN); + aliases.put("MTEI", MEETEI_MAYEK); + aliases.put("MYMR", MYANMAR); + aliases.put("NKOO", NKO); + aliases.put("OGAM", OGHAM); + aliases.put("OLCK", OL_CHIKI); + aliases.put("ORKH", OLD_TURKIC); + aliases.put("ORYA", ORIYA); + aliases.put("OSMA", OSMANYA); + aliases.put("PHAG", PHAGS_PA); + aliases.put("PHLI", INSCRIPTIONAL_PAHLAVI); + aliases.put("PHNX", PHOENICIAN); + aliases.put("PRTI", INSCRIPTIONAL_PARTHIAN); + aliases.put("RJNG", REJANG); + aliases.put("RUNR", RUNIC); + aliases.put("SAMR", SAMARITAN); + aliases.put("SARB", OLD_SOUTH_ARABIAN); + aliases.put("SAUR", SAURASHTRA); + aliases.put("SHAW", SHAVIAN); + aliases.put("SINH", SINHALA); + aliases.put("SUND", SUNDANESE); + aliases.put("SYLO", SYLOTI_NAGRI); + aliases.put("SYRC", SYRIAC); + aliases.put("TAGB", TAGBANWA); + aliases.put("TALE", TAI_LE); + aliases.put("TALU", NEW_TAI_LUE); + aliases.put("TAML", TAMIL); + aliases.put("TAVT", TAI_VIET); + aliases.put("TELU", TELUGU); + aliases.put("TFNG", TIFINAGH); + aliases.put("TGLG", TAGALOG); + aliases.put("THAA", THAANA); + aliases.put("THAI", THAI); + aliases.put("TIBT", TIBETAN); + aliases.put("UGAR", UGARITIC); + aliases.put("VAII", VAI); + aliases.put("XPEO", OLD_PERSIAN); + aliases.put("XSUX", CUNEIFORM); + aliases.put("YIII", YI); + aliases.put("ZINH", INHERITED); + aliases.put("ZYYY", COMMON); + aliases.put("ZZZZ", UNKNOWN); + } + + /** + * Returns the enum constant representing the Unicode script of which + * the given character (Unicode code point) is assigned to. + * + * @param codePoint the character (Unicode code point) in question. + * @return The <code>UnicodeScript</code> constant representing the + * Unicode script of which this character is assigned to. + * + * @exception IllegalArgumentException if the specified + * <code>codePoint</code> is an invalid Unicode code point. + * @see Character#isValidCodePoint(int) + * + */ + public static UnicodeScript of(int codePoint) { + if (!isValidCodePoint(codePoint)) + throw new IllegalArgumentException(); + int type = getType(codePoint); + // leave SURROGATE and PRIVATE_USE for table lookup + if (type == UNASSIGNED) + return UNKNOWN; + int index = Arrays.binarySearch(scriptStarts, codePoint); + if (index < 0) + index = -index - 2; + return scripts[index]; + } + + /** + * Returns the UnicodeScript constant with the given Unicode script + * name or the script name alias. Script names and their aliases are + * determined by The Unicode Standard. The files Scripts<version>.txt + * and PropertyValueAliases<version>.txt define script names + * and the script name aliases for a particular version of the + * standard. The {@link Character} class specifies the version of + * the standard that it supports. + * <p> + * Character case is ignored for all of the valid script names. + * The en_US locale's case mapping rules are used to provide + * case-insensitive string comparisons for script name validation. + * <p> + * + * @param scriptName A <code>UnicodeScript</code> name. + * @return The <code>UnicodeScript</code> constant identified + * by <code>scriptName</code> + * @throws IllegalArgumentException if <code>scriptName</code> is an + * invalid name + * @throws NullPointerException if <code>scriptName</code> is null + */ + public static final UnicodeScript forName(String scriptName) { + scriptName = scriptName.toUpperCase(Locale.ENGLISH); + //.replace(' ', '_')); + UnicodeScript sc = aliases.get(scriptName); + if (sc != null) + return sc; + return valueOf(scriptName); + } + } + + /** * The value of the <code>Character</code>. * * @serial @@ -5042,4 +6278,51 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara public static char reverseBytes(char ch) { return (char) (((ch & 0xFF00) >> 8) | (ch << 8)); } + + /** + * Returns the Unicode name of the specified character + * <code>codePoint</code>, or null if the code point is + * {@link #UNASSIGNED unassigned}. + * <p> + * Note: if the specified character is not assigned a name by + * the <i>UnicodeData</i> file (part of the Unicode Character + * Database maintained by the Unicode Consortium), the returned + * name is the same as the result of expression + * + * <blockquote><code> + * Character.UnicodeBlock.of(codePoint) + * .toString() + * .replace('_', ' ') + * + " " + * + Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH); + * + * </code></blockquote> + * + * @param codePoint the character (Unicode code point) + * + * @return the Unicode name of the specified character, or null if + * the code point is unassigned. + * + * @exception IllegalArgumentException if the specified + * <code>codePoint</code> is not a valid Unicode + * code point. + * + * @since 1.7 + */ + public static String getName(int codePoint) { + if (!isValidCodePoint(codePoint)) { + throw new IllegalArgumentException(); + } + String name = CharacterName.get(codePoint); + if (name != null) + return name; + if (getType(codePoint) == UNASSIGNED) + return null; + UnicodeBlock block = UnicodeBlock.of(codePoint); + if (block != null) + return block.toString().replace('_', ' ') + " " + + Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH); + // should never come here + return Integer.toHexString(codePoint).toUpperCase(Locale.ENGLISH); + } } diff --git a/src/share/classes/java/lang/CharacterName.java b/src/share/classes/java/lang/CharacterName.java new file mode 100644 index 000000000..d09734087 --- /dev/null +++ b/src/share/classes/java/lang/CharacterName.java @@ -0,0 +1,106 @@ +/* + * 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 java.lang; + +import java.io.DataInputStream; +import java.io.InputStream; +import java.lang.ref.SoftReference; +import java.util.Arrays; +import java.util.zip.InflaterInputStream; +import java.security.AccessController; +import java.security.PrivilegedAction; + +class CharacterName { + + private static SoftReference<byte[]> refStrPool; + private static int[][] lookup; + + private static synchronized byte[] initNamePool() { + byte[] strPool = null; + if (refStrPool != null && (strPool = refStrPool.get()) != null) + return strPool; + DataInputStream dis = null; + try { + dis = new DataInputStream(new InflaterInputStream( + AccessController.doPrivileged(new PrivilegedAction<InputStream>() + { + public InputStream run() { + return getClass().getResourceAsStream("uniName.dat"); + } + }))); + + lookup = new int[(Character.MAX_CODE_POINT + 1) >> 8][]; + int total = dis.readInt(); + int cpEnd = dis.readInt(); + byte ba[] = new byte[cpEnd]; + dis.readFully(ba); + + int nameOff = 0; + int cpOff = 0; + int cp = 0; + do { + int len = ba[cpOff++] & 0xff; + if (len == 0) { + len = ba[cpOff++] & 0xff; + // always big-endian + cp = ((ba[cpOff++] & 0xff) << 16) | + ((ba[cpOff++] & 0xff) << 8) | + ((ba[cpOff++] & 0xff)); + } else { + cp++; + } + int hi = cp >> 8; + if (lookup[hi] == null) { + lookup[hi] = new int[0x100]; + } + lookup[hi][cp&0xff] = (nameOff << 8) | len; + nameOff += len; + } while (cpOff < cpEnd); + strPool = new byte[total - cpEnd]; + dis.readFully(strPool); + refStrPool = new SoftReference<byte[]>(strPool); + } catch (Exception x) { + throw new InternalError(x.getMessage()); + } finally { + try { + if (dis != null) + dis.close(); + } catch (Exception xx) {} + } + return strPool; + } + + public static String get(int cp) { + byte[] strPool = null; + if (refStrPool == null || (strPool = refStrPool.get()) == null) + strPool = initNamePool(); + int off = 0; + if (lookup[cp>>8] == null || + (off = lookup[cp>>8][cp&0xff]) == 0) + return null; + return new String(strPool, 0, off >>> 8, off & 0xff); // ASCII + } +} diff --git a/src/share/classes/java/net/URI.java b/src/share/classes/java/net/URI.java index 41968832a..ed8c27b12 100644 --- a/src/share/classes/java/net/URI.java +++ b/src/share/classes/java/net/URI.java @@ -2491,6 +2491,8 @@ public final class URI // Tell whether the given character is permitted by the given mask pair private static boolean match(char c, long lowMask, long highMask) { + if (c == 0) // 0 doesn't have a slot in the mask. So, it never matches. + return false; if (c < 64) return ((1L << c) & lowMask) != 0; if (c < 128) diff --git a/src/share/classes/java/util/jar/JarVerifier.java b/src/share/classes/java/util/jar/JarVerifier.java index bd5b489b2..33c67c15a 100644 --- a/src/share/classes/java/util/jar/JarVerifier.java +++ b/src/share/classes/java/util/jar/JarVerifier.java @@ -76,7 +76,7 @@ class JarVerifier { private ByteArrayOutputStream baos; /** The ManifestDigester object */ - private ManifestDigester manDig; + private volatile ManifestDigester manDig; /** the bytes for the manDig object */ byte manifestRawBytes[] = null; diff --git a/src/share/classes/java/util/regex/Pattern.java b/src/share/classes/java/util/regex/Pattern.java index 50a381f41..9f326c24d 100644 --- a/src/share/classes/java/util/regex/Pattern.java +++ b/src/share/classes/java/util/regex/Pattern.java @@ -29,6 +29,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.text.CharacterIterator; import java.text.Normalizer; +import java.util.Locale; import java.util.Map; import java.util.ArrayList; import java.util.HashMap; @@ -200,8 +201,9 @@ import java.util.Arrays; * <td>Equivalent to java.lang.Character.isMirrored()</td></tr> * * <tr><th> </th></tr> - * <tr align="left"><th colspan="2" id="unicode">Classes for Unicode blocks and categories</th></tr> - * + * <tr align="left"><th colspan="2" id="unicode">Classes for Unicode scripts, blocks and categories</th></tr> + * * <tr><td valign="top" headers="construct unicode"><tt>\p{IsLatin}</tt></td> + * <td headers="matches">A Latin script character (simple <a href="#ubc">script</a>)</td></tr> * <tr><td valign="top" headers="construct unicode"><tt>\p{InGreek}</tt></td> * <td headers="matches">A character in the Greek block (simple <a href="#ubc">block</a>)</td></tr> * <tr><td valign="top" headers="construct unicode"><tt>\p{Lu}</tt></td> @@ -527,25 +529,40 @@ import java.util.Arrays; * while not equal, compile into the same pattern, which matches the character * with hexadecimal value <tt>0x2014</tt>. * - * <a name="ubc"> <p>Unicode blocks and categories are written with the - * <tt>\p</tt> and <tt>\P</tt> constructs as in - * Perl. <tt>\p{</tt><i>prop</i><tt>}</tt> matches if the input has the - * property <i>prop</i>, while <tt>\P{</tt><i>prop</i><tt>}</tt> does not match if - * the input has that property. Blocks are specified with the prefix - * <tt>In</tt>, as in <tt>InMongolian</tt>. Categories may be specified with - * the optional prefix <tt>Is</tt>: Both <tt>\p{L}</tt> and <tt>\p{IsL}</tt> - * denote the category of Unicode letters. Blocks and categories can be used - * both inside and outside of a character class. - * + * <a name="ubc"> + * <p>Unicode scripts, blocks and categories are written with the <tt>\p</tt> and + * <tt>\P</tt> constructs as in Perl. <tt>\p{</tt><i>prop</i><tt>}</tt> matches if + * the input has the property <i>prop</i>, while <tt>\P{</tt><i>prop</i><tt>}</tt> + * does not match if the input has that property. + * <p> + * Scripts are specified either with the prefix {@code Is}, as in + * {@code IsHiragana}, or by using the {@code script} keyword (or its short + * form {@code sc})as in {@code script=Hiragana} or {@code sc=Hiragana}. + * <p> + * Blocks are specified with the prefix {@code In}, as in + * {@code InMongolian}, or by using the keyword {@code block} (or its short + * form {@code blk}) as in {@code block=Mongolian} or {@code blk=Mongolian}. + * <p> + * Categories may be specified with the optional prefix {@code Is}: + * Both {@code \p{L}} and {@code \p{IsL}} denote the category of Unicode + * letters. Same as scripts and blocks, categories can also be specified + * by using the keyword {@code general_category} (or its short form + * {@code gc}) as in {@code general_category=Lu} or {@code gc=Lu}. + * <p> + * Scripts, blocks and categories can be used both inside and outside of a + * character class. * <p> The supported categories are those of * <a href="http://www.unicode.org/unicode/standard/standard.html"> * <i>The Unicode Standard</i></a> in the version specified by the * {@link java.lang.Character Character} class. The category names are those * defined in the Standard, both normative and informative. + * The script names supported by <code>Pattern</code> are the valid script names + * accepted and defined by + * {@link java.lang.Character.UnicodeScript#forName(String) UnicodeScript.forName}. * The block names supported by <code>Pattern</code> are the valid block names * accepted and defined by * {@link java.lang.Character.UnicodeBlock#forName(String) UnicodeBlock.forName}. - * + * <p> * <a name="jcc"> <p>Categories that behave like the java.lang.Character * boolean is<i>methodname</i> methods (except for the deprecated ones) are * available through the same <tt>\p{</tt><i>prop</i><tt>}</tt> syntax where @@ -2488,12 +2505,34 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { name = new String(temp, i, j-i-1); } - if (name.startsWith("In")) { - node = unicodeBlockPropertyFor(name.substring(2)); + int i = name.indexOf('='); + if (i != -1) { + // property construct \p{name=value} + String value = name.substring(i + 1); + name = name.substring(0, i).toLowerCase(Locale.ENGLISH); + if ("sc".equals(name) || "script".equals(name)) { + node = unicodeScriptPropertyFor(value); + } else if ("blk".equals(name) || "block".equals(name)) { + node = unicodeBlockPropertyFor(value); + } else if ("gc".equals(name) || "general_category".equals(name)) { + node = charPropertyNodeFor(value); + } else { + throw error("Unknown Unicode property {name=<" + name + ">, " + + "value=<" + value + ">}"); + } } else { - if (name.startsWith("Is")) + if (name.startsWith("In")) { + // \p{inBlockName} + node = unicodeBlockPropertyFor(name.substring(2)); + } else if (name.startsWith("Is")) { + // \p{isGeneralCategory} and \p{isScriptName} name = name.substring(2); - node = charPropertyNodeFor(name); + node = CharPropertyNames.charPropertyFor(name); + if (node == null) + node = unicodeScriptPropertyFor(name); + } else { + node = charPropertyNodeFor(name); + } } if (maybeComplement) { if (node instanceof Category || node instanceof Block) @@ -2503,6 +2542,21 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { return node; } + + /** + * Returns a CharProperty matching all characters belong to + * a UnicodeScript. + */ + private CharProperty unicodeScriptPropertyFor(String name) { + final Character.UnicodeScript script; + try { + script = Character.UnicodeScript.forName(name); + } catch (IllegalArgumentException iae) { + throw error("Unknown character script name {" + name + "}"); + } + return new Script(script); + } + /** * Returns a CharProperty matching all characters in a UnicodeBlock. */ @@ -3567,6 +3621,19 @@ loop: for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { } /** + * Node class that matches a Unicode script + */ + static final class Script extends CharProperty { + final Character.UnicodeScript script; + Script(Character.UnicodeScript script) { + this.script = script; + } + boolean isSatisfiedBy(int ch) { + return script == Character.UnicodeScript.of(ch); + } + } + + /** * Node class that matches a Unicode category. */ static final class Category extends CharProperty { diff --git a/src/share/classes/java/util/zip/GZIPInputStream.java b/src/share/classes/java/util/zip/GZIPInputStream.java index 1140c38b3..8d60d1996 100644 --- a/src/share/classes/java/util/zip/GZIPInputStream.java +++ b/src/share/classes/java/util/zip/GZIPInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. 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 @@ -66,19 +66,24 @@ class GZIPInputStream extends InflaterInputStream { * Creates a new input stream with the specified buffer size. * @param in the input stream * @param size the input buffer size + * + * @exception ZipException if a GZIP format error has occurred or the + * compression method used is unsupported * @exception IOException if an I/O error has occurred * @exception IllegalArgumentException if size is <= 0 */ public GZIPInputStream(InputStream in, int size) throws IOException { super(in, new Inflater(true), size); usesDefaultInflater = true; - readHeader(); - crc.reset(); + readHeader(in); } /** * Creates a new input stream with a default buffer size. * @param in the input stream + * + * @exception ZipException if a GZIP format error has occurred or the + * compression method used is unsupported * @exception IOException if an I/O error has occurred */ public GZIPInputStream(InputStream in) throws IOException { @@ -94,26 +99,30 @@ class GZIPInputStream extends InflaterInputStream { * @param len the maximum number of bytes read * @return the actual number of bytes read, or -1 if the end of the * compressed input stream is reached + * * @exception NullPointerException If <code>buf</code> is <code>null</code>. * @exception IndexOutOfBoundsException If <code>off</code> is negative, * <code>len</code> is negative, or <code>len</code> is greater than * <code>buf.length - off</code> - * @exception IOException if an I/O error has occurred or the compressed - * input data is corrupt + * @exception ZipException if the compressed input data is corrupt. + * @exception IOException if an I/O error has occurred. + * */ public int read(byte[] buf, int off, int len) throws IOException { ensureOpen(); if (eos) { return -1; } - len = super.read(buf, off, len); - if (len == -1) { - readTrailer(); - eos = true; + int n = super.read(buf, off, len); + if (n == -1) { + if (readTrailer()) + eos = true; + else + return this.read(buf, off, len); } else { - crc.update(buf, off, len); + crc.update(buf, off, n); } - return len; + return n; } /** @@ -144,48 +153,61 @@ class GZIPInputStream extends InflaterInputStream { private final static int FCOMMENT = 16; // File comment /* - * Reads GZIP member header. + * Reads GZIP member header and returns the total byte number + * of this member header. */ - private void readHeader() throws IOException { - CheckedInputStream in = new CheckedInputStream(this.in, crc); + private int readHeader(InputStream this_in) throws IOException { + CheckedInputStream in = new CheckedInputStream(this_in, crc); crc.reset(); // Check header magic if (readUShort(in) != GZIP_MAGIC) { - throw new IOException("Not in GZIP format"); + throw new ZipException("Not in GZIP format"); } // Check compression method if (readUByte(in) != 8) { - throw new IOException("Unsupported compression method"); + throw new ZipException("Unsupported compression method"); } // Read flags int flg = readUByte(in); // Skip MTIME, XFL, and OS fields skipBytes(in, 6); + int n = 2 + 2 + 6; // Skip optional extra field if ((flg & FEXTRA) == FEXTRA) { - skipBytes(in, readUShort(in)); + int m = readUShort(in); + skipBytes(in, m); + n += m + 2; } // Skip optional file name if ((flg & FNAME) == FNAME) { - while (readUByte(in) != 0) ; + do { + n++; + } while (readUByte(in) != 0); } // Skip optional file comment if ((flg & FCOMMENT) == FCOMMENT) { - while (readUByte(in) != 0) ; + do { + n++; + } while (readUByte(in) != 0); } // Check optional header CRC if ((flg & FHCRC) == FHCRC) { int v = (int)crc.getValue() & 0xffff; if (readUShort(in) != v) { - throw new IOException("Corrupt GZIP header"); + throw new ZipException("Corrupt GZIP header"); } + n += 2; } + crc.reset(); + return n; } /* - * Reads GZIP member trailer. + * Reads GZIP member trailer and returns true if the eos + * reached, false if there are more (concatenated gzip + * data set) */ - private void readTrailer() throws IOException { + private boolean readTrailer() throws IOException { InputStream in = this.in; int n = inf.getRemaining(); if (n > 0) { @@ -196,7 +218,25 @@ class GZIPInputStream extends InflaterInputStream { if ((readUInt(in) != crc.getValue()) || // rfc1952; ISIZE is the input size modulo 2^32 (readUInt(in) != (inf.getBytesWritten() & 0xffffffffL))) - throw new IOException("Corrupt GZIP trailer"); + throw new ZipException("Corrupt GZIP trailer"); + + // If there are more bytes available in "in" or + // the leftover in the "inf" is > 26 bytes: + // this.trailer(8) + next.header.min(10) + next.trailer(8) + // try concatenated case + if (this.in.available() > 0 || n > 26) { + int m = 8; // this.trailer + try { + m += readHeader(in); // next.header + } catch (IOException ze) { + return true; // ignore any malformed, do nothing + } + inf.reset(); + if (n > m) + inf.setInput(buf, len - n + m, n - m); + return false; + } + return true; } /* @@ -231,7 +271,6 @@ class GZIPInputStream extends InflaterInputStream { return b; } - private byte[] tmpbuf = new byte[128]; /* diff --git a/src/share/classes/java/util/zip/GZIPOutputStream.java b/src/share/classes/java/util/zip/GZIPOutputStream.java index 4473f78db..d5edcf122 100644 --- a/src/share/classes/java/util/zip/GZIPOutputStream.java +++ b/src/share/classes/java/util/zip/GZIPOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. 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 @@ -54,25 +54,82 @@ class GZIPOutputStream extends DeflaterOutputStream { /** * Creates a new output stream with the specified buffer size. + * + * <p>The new output stream instance is created as if by invoking + * the 3-argument constructor GZIPOutputStream(out, size, false). + * * @param out the output stream * @param size the output buffer size * @exception IOException If an I/O error has occurred. * @exception IllegalArgumentException if size is <= 0 + */ public GZIPOutputStream(OutputStream out, int size) throws IOException { - super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size); + this(out, size, false); + } + + /** + * Creates a new output stream with the specified buffer size and + * flush mode. + * + * @param out the output stream + * @param size the output buffer size + * @param syncFlush + * if {@code true} invocation of the inherited + * {@link DeflaterOutputStream#flush() flush()} method of + * this instance flushes the compressor with flush mode + * {@link Deflater#SYNC_FLUSH} before flushing the output + * stream, otherwise only flushes the output stream + * @exception IOException If an I/O error has occurred. + * @exception IllegalArgumentException if size is <= 0 + * + * @since 1.7 + */ + public GZIPOutputStream(OutputStream out, int size, boolean syncFlush) + throws IOException + { + super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true), + size, + syncFlush); usesDefaultDeflater = true; writeHeader(); crc.reset(); } + /** * Creates a new output stream with a default buffer size. + * + * <p>The new output stream instance is created as if by invoking + * the 2-argument constructor GZIPOutputStream(out, false). + * * @param out the output stream * @exception IOException If an I/O error has occurred. */ public GZIPOutputStream(OutputStream out) throws IOException { - this(out, 512); + this(out, 512, false); + } + + /** + * Creates a new output stream with a default buffer size and + * the specified flush mode. + * + * @param out the output stream + * @param syncFlush + * if {@code true} invocation of the inherited + * {@link DeflaterOutputStream#flush() flush()} method of + * this instance flushes the compressor with flush mode + * {@link Deflater#SYNC_FLUSH} before flushing the output + * stream, otherwise only flushes the output stream + * + * @exception IOException If an I/O error has occurred. + * + * @since 1.7 + */ + public GZIPOutputStream(OutputStream out, boolean syncFlush) + throws IOException + { + this(out, 512, syncFlush); } /** @@ -122,22 +179,19 @@ class GZIPOutputStream extends DeflaterOutputStream { /* * Writes GZIP member header. */ - - private final static byte[] header = { - (byte) GZIP_MAGIC, // Magic number (short) - (byte)(GZIP_MAGIC >> 8), // Magic number (short) - Deflater.DEFLATED, // Compression method (CM) - 0, // Flags (FLG) - 0, // Modification time MTIME (int) - 0, // Modification time MTIME (int) - 0, // Modification time MTIME (int) - 0, // Modification time MTIME (int) - 0, // Extra flags (XFLG) - 0 // Operating system (OS) - }; - private void writeHeader() throws IOException { - out.write(header); + out.write(new byte[] { + (byte) GZIP_MAGIC, // Magic number (short) + (byte)(GZIP_MAGIC >> 8), // Magic number (short) + Deflater.DEFLATED, // Compression method (CM) + 0, // Flags (FLG) + 0, // Modification time MTIME (int) + 0, // Modification time MTIME (int) + 0, // Modification time MTIME (int) + 0, // Modification time MTIME (int) + 0, // Extra flags (XFLG) + 0 // Operating system (OS) + }); } /* diff --git a/src/share/classes/java/util/zip/ZipException.java b/src/share/classes/java/util/zip/ZipException.java index 4c5fb99c2..4bcfe0368 100644 --- a/src/share/classes/java/util/zip/ZipException.java +++ b/src/share/classes/java/util/zip/ZipException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. 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 @@ -40,7 +40,7 @@ class ZipException extends IOException { private static final long serialVersionUID = 8000196834066748623L; /** - * Constructs an <code>ZipException</code> with <code>null</code> + * Constructs a <code>ZipException</code> with <code>null</code> * as its error detail message. */ public ZipException() { @@ -48,7 +48,7 @@ class ZipException extends IOException { } /** - * Constructs an <code>ZipException</code> with the specified detail + * Constructs a <code>ZipException</code> with the specified detail * message. * * @param s the detail message. diff --git a/src/share/classes/java/util/zip/package.html b/src/share/classes/java/util/zip/package.html index 9365f15f0..e83f98fde 100644 --- a/src/share/classes/java/util/zip/package.html +++ b/src/share/classes/java/util/zip/package.html @@ -58,25 +58,22 @@ input streams. PKWARE ZIP File Format Specification</a> - Language Encoding Flag (EFS) to encode ZIP entry filename and comment fields using UTF-8. <p> - <li><a href="http://www.isi.edu/in-notes/rfc1950.txt"> + <li><a href="http://www.ietf.org/rfc/rfc1950.txt"> ZLIB Compressed Data Format Specification version 3.3</a> - <a href="http://www.isi.edu/in-notes/rfc1950.ps"> - (PostScript)</a> + <a href="http://www.ietf.org/rfc/rfc1950.txt.pdf">(pdf)</a> (RFC 1950) <p> - <li><a href="http://www.isi.edu/in-notes/rfc1951.txt"> + <li><a href="http://www.ietf.org/rfc/rfc1951.txt"> DEFLATE Compressed Data Format Specification version 1.3</a> - <a href="http://www.isi.edu/in-notes/rfc1951.ps"> - (PostScript)</a> + <a href="http://www.ietf.org/rfc/rfc1951.txt.pdf">(pdf)</a> (RFC 1951) <p> - <li><a href="http://www.isi.edu/in-notes/rfc1952.txt"> + <li><a href="http://www.ietf.org/rfc/rfc1952.txt"> GZIP file format specification version 4.3</a> - <a href="http://www.isi.edu/in-notes/rfc1952.ps"> - (PostScript)</a> + <a href="http://www.ietf.org/rfc/rfc1952.txt.pdf">(pdf)</a> (RFC 1952) <p> <li>CRC-32 checksum is described in RFC 1952 (above) |