Skip to content

Commit fe60b56

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 fe60b56

File tree

1 file changed

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

1 file changed

+4
-22
lines changed

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

Lines changed: 4 additions & 22 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
@@ -16,10 +16,8 @@
1616

1717
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
1818

19-
import java.io.BufferedReader;
2019
import java.io.IOException;
2120
import java.io.InputStream;
22-
import java.io.InputStreamReader;
2321

2422
import org.eclipse.swt.SWT;
2523
import org.eclipse.swt.SWTError;
@@ -118,18 +116,12 @@ void createExampleWidgets () {
118116
} else if (lastText != null) {
119117
browser.setText(lastText);
120118
} else {
121-
StringBuilder sb= new StringBuilder(300);
122-
123-
try (InputStream htmlStream = ControlExample.class.getResourceAsStream("browser-content.html");
124-
BufferedReader br = new BufferedReader(new InputStreamReader(htmlStream))) {
125-
int read = 0;
126-
while ((read = br.read()) != -1)
127-
sb.append((char) read);
119+
try (InputStream htmlStream = ControlExample.class.getResourceAsStream("browser-content.html")) {
120+
browser.setText( new String (htmlStream.readAllBytes()));
128121
} catch (IOException e) {
129122
log(e.getMessage());
123+
browser.setText("Loading failed, see log for details!");
130124
}
131-
String text= sb.toString();
132-
browser.setText(text);
133125
}
134126
lastText = lastUrl = null;
135127
}
@@ -229,16 +221,6 @@ void disposeExampleWidgets () {
229221
super.disposeExampleWidgets();
230222
}
231223

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-
242224
/**
243225
* Gets the list of custom event names.
244226
*

0 commit comments

Comments
 (0)