Skip to content

Commit f0b1198

Browse files
committed
Simplify control example browser tab content loading
Going symbol by symbol nowadays is just time lost and even makes code harder to read.
1 parent 6842283 commit f0b1198

File tree

1 file changed

+4
-17
lines changed
  • examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample

1 file changed

+4
-17
lines changed

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.InputStream;
2222
import java.io.InputStreamReader;
23+
import java.util.stream.Collectors;
2324

2425
import org.eclipse.swt.SWT;
2526
import org.eclipse.swt.SWTError;
@@ -118,17 +119,13 @@ void createExampleWidgets () {
118119
} else if (lastText != null) {
119120
browser.setText(lastText);
120121
} else {
121-
StringBuilder sb= new StringBuilder(300);
122-
122+
String text= "";
123123
try (InputStream htmlStream = ControlExample.class.getResourceAsStream("browser-content.html");
124124
BufferedReader br = new BufferedReader(new InputStreamReader(htmlStream))) {
125-
int read = 0;
126-
while ((read = br.read()) != -1)
127-
sb.append((char) read);
125+
text= br.lines().collect(Collectors.joining("\n"));
128126
} catch (IOException e) {
129127
log(e.getMessage());
130128
}
131-
String text= sb.toString();
132129
browser.setText(text);
133130
}
134131
lastText = lastUrl = null;
@@ -229,16 +226,6 @@ void disposeExampleWidgets () {
229226
super.disposeExampleWidgets();
230227
}
231228

232-
public static String getContents(InputStream in) throws IOException {
233-
StringBuilder sb= new StringBuilder(300);
234-
try (BufferedReader br= new BufferedReader(new InputStreamReader(in))) {
235-
int read= 0;
236-
while ((read= br.read()) != -1)
237-
sb.append((char) read);
238-
}
239-
return sb.toString();
240-
}
241-
242229
/**
243230
* Gets the list of custom event names.
244231
*

0 commit comments

Comments
 (0)