Skip to content

Commit 526f990

Browse files
committed
8239138: StyleManager should use a BufferedInputStream
Reviewed-by: kcr, pbansal
1 parent 5e6d442 commit 526f990

File tree

4 files changed

+181
-1
lines changed

4 files changed

+181
-1
lines changed

modules/javafx.graphics/src/main/java/com/sun/javafx/css/StyleManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,8 @@ static byte[] calculateCheckSum(String fname) {
923923
try (final InputStream stream = url.openStream();
924924
final DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("MD5")); ) {
925925
dis.getMessageDigest().reset();
926-
while (dis.read() != -1) { /* empty loop body is intentional */ }
926+
byte[] buffer = new byte[4096];
927+
while (dis.read(buffer) != -1) { /* empty loop body is intentional */ }
927928
return dis.getMessageDigest().digest();
928929
}
929930

modules/javafx.graphics/src/shims/java/com/sun/javafx/css/StyleManagerShim.java

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public StyleMap findMatchingStyles(Node node, SubScene subScene, Set<PseudoClass
161161
return sm.findMatchingStyles(node, subScene, triggerStates);
162162
}
163163

164+
public byte[] calculateCheckSum(String fname) {
165+
return sm.calculateCheckSum(fname);
166+
}
167+
164168
public boolean stylesheetContainerMap_containsKey(String k) {
165169
return sm.stylesheetContainerMap.containsKey(k);
166170
}

modules/javafx.graphics/src/test/java/test/com/sun/javafx/css/StyleManagerTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
import java.net.URL;
4949
import java.util.ArrayList;
50+
import java.util.Arrays;
5051
import java.util.Collections;
5152
import java.util.List;
5253
import java.util.Map;
@@ -1109,4 +1110,14 @@ public void testConcurrentAccess() {
11091110
assertFalse("Exception during CSS processing on BG thread", err.get());
11101111
}
11111112

1113+
@Test
1114+
public void testCalculateCheckSum() {
1115+
StyleManagerShim sm = StyleManagerShim.getInstance();
1116+
byte[] checksum = sm.calculateCheckSum(getClass().getResource("checksum.css").toExternalForm());
1117+
1118+
byte[] expectedChecksum = {60, 26, 67, 14, 103, -63, -62, 42, 14, 40, -44, -103, 1, -60, -90, 18};
1119+
// "3c1a430e67c1c22a0e28d49901c4a612" // Generated using command 'md5sum checksum.css'
1120+
1121+
assertTrue(Arrays.equals(expectedChecksum, checksum));
1122+
}
11121123
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
.root {
27+
/***************************************************************************
28+
* *
29+
* The main color palette from which the rest of the colors are derived. *
30+
* *
31+
**************************************************************************/
32+
33+
/* A light grey that is the base color for objects. Instead of using
34+
* -fx-base directly, the sections in this file will typically use -fx-color.
35+
*/
36+
-fx-base: #ececec;
37+
38+
/* A very light grey used for the background of windows. See also
39+
* -fx-text-background-color, which should be used as the -fx-text-fill
40+
* value for text painted on top of backgrounds colored with -fx-background.
41+
*/
42+
-fx-background: derive(-fx-base,26.4%);
43+
44+
/* Used for the inside of text boxes, password boxes, lists, trees, and
45+
* tables. See also -fx-text-inner-color, which should be used as the
46+
* -fx-text-fill value for text painted on top of backgrounds colored
47+
* with -fx-control-inner-background.
48+
*/
49+
-fx-control-inner-background: derive(-fx-base,80%);
50+
/* Version of -fx-control-inner-background for alternative rows */
51+
-fx-control-inner-background-alt: derive(-fx-control-inner-background,-2%);
52+
53+
/* One of these colors will be chosen based upon a ladder calculation
54+
* that uses the brightness of a background color. Instead of using these
55+
* colors directly as -fx-text-fill values, the sections in this file should
56+
* use a derived color to match the background in use. See also:
57+
*
58+
* -fx-text-base-color for text on top of -fx-base, -fx-color, and -fx-body-color
59+
* -fx-text-background-color for text on top of -fx-background
60+
* -fx-text-inner-color for text on top of -fx-control-inner-color
61+
* -fx-selection-bar-text for text on top of -fx-selection-bar
62+
*/
63+
-fx-dark-text-color: black;
64+
-fx-mid-text-color: #333;
65+
-fx-light-text-color: white;
66+
67+
/* A bright blue for highlighting/accenting objects. For example: selected
68+
* text; selected items in menus, lists, trees, and tables; progress bars */
69+
-fx-accent: #0096C9;
70+
71+
/* Default buttons color, this is similar to accent but more subtle */
72+
-fx-default-button: #ABD8ED;
73+
74+
/* A bright blue for the focus indicator of objects. Typically used as the
75+
* first color in -fx-background-color for the "focused" pseudo-class. Also
76+
* typically used with insets of -1.4 to provide a glowing effect.
77+
*/
78+
-fx-focus-color: #039ED3;
79+
-fx-faint-focus-color: #039ED322;
80+
81+
/* The color that is used in styling controls. The default value is based
82+
* on -fx-base, but is changed by pseudoclasses to change the base color.
83+
* For example, the "hover" pseudoclass will typically set -fx-color to
84+
* -fx-hover-base (see below) and the "armed" pseudoclass will typically
85+
* set -fx-color to -fx-pressed-base.
86+
*/
87+
-fx-color: -fx-base;
88+
89+
/* Chart Color Palette */
90+
CHART_COLOR_1: #f3622d;
91+
CHART_COLOR_2: #fba71b;
92+
CHART_COLOR_3: #57b757;
93+
CHART_COLOR_4: #41a9c9;
94+
CHART_COLOR_5: #4258c9;
95+
CHART_COLOR_6: #9a42c8;
96+
CHART_COLOR_7: #c84164;
97+
CHART_COLOR_8: #888888;
98+
/* Chart Color Palette Semi-Transparent
99+
* These are used by charts that need semi transparent versions of the above colors, such as BubbleChart. They
100+
* are exactly the same colors as above just with alpha
101+
*
102+
* 20% opacity
103+
*/
104+
CHART_COLOR_1_TRANS_20: #f3622d33;
105+
CHART_COLOR_2_TRANS_20: #fba71b33;
106+
CHART_COLOR_3_TRANS_20: #57b75733;
107+
CHART_COLOR_4_TRANS_20: #41a9c933;
108+
CHART_COLOR_5_TRANS_20: #4258c933;
109+
CHART_COLOR_6_TRANS_20: #9a42c833;
110+
CHART_COLOR_7_TRANS_20: #c8416433;
111+
CHART_COLOR_8_TRANS_20: #88888833;
112+
/* 70% opacity */
113+
CHART_COLOR_1_TRANS_70: #f3622db3;
114+
CHART_COLOR_2_TRANS_70: #fba71bb3;
115+
CHART_COLOR_3_TRANS_70: #57b757b3;
116+
CHART_COLOR_4_TRANS_70: #41a9c9b3;
117+
CHART_COLOR_5_TRANS_70: #4258c9b3;
118+
CHART_COLOR_6_TRANS_70: #9a42c8b3;
119+
CHART_COLOR_7_TRANS_70: #c84164b3;
120+
CHART_COLOR_8_TRANS_70: #888888b3;
121+
122+
/***************************************************************************
123+
* *
124+
* Colors that are derived from the main color palette. *
125+
* *
126+
**************************************************************************/
127+
128+
/* A little lighter than -fx-base and used as the -fx-color for the
129+
* "hovered" pseudoclass state.
130+
*/
131+
-fx-hover-base: ladder(
132+
-fx-base,
133+
derive(-fx-base,20%) 20%,
134+
derive(-fx-base,30%) 35%,
135+
derive(-fx-base,40%) 50%
136+
);
137+
138+
/* A little darker than -fx-base and used as the -fx-color for the
139+
* "armed" pseudoclass state.
140+
*
141+
* TODO: should this be renamed to -fx-armed-base?
142+
*/
143+
-fx-pressed-base: derive(-fx-base,-6%);
144+
145+
/* The color to use for -fx-text-fill when text is to be painted on top of
146+
* a background filled with the -fx-background color.
147+
*/
148+
-fx-text-background-color: ladder(
149+
-fx-background,
150+
-fx-light-text-color 45%,
151+
-fx-dark-text-color 46%,
152+
-fx-dark-text-color 59%,
153+
-fx-mid-text-color 60%
154+
);
155+
156+
/* A little darker than -fx-color and used to draw boxes around objects such
157+
* as progress bars, scroll bars, scroll panes, trees, tables, and lists.
158+
*/
159+
-fx-box-border: ladder(
160+
-fx-color,
161+
black 20%,
162+
derive(-fx-color,-15%) 30%
163+
);
164+
}

0 commit comments

Comments
 (0)