Skip to content

Commit 3a62d65

Browse files
committed
Improve SnippetLauncher output
Remove one extra "/* \n" output for each snippet. Streamline files reading into string by using newer Java APIs.
1 parent c0a965a commit 3a62d65

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/SnippetLauncher.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
import java.io.*;
2626
import java.lang.reflect.*;
27+
import java.nio.charset.*;
28+
import java.nio.file.*;
2729

2830
import org.eclipse.swt.*;
2931

@@ -47,15 +49,13 @@ public static void main (String [] args) {
4749
if (clazz != null) {
4850
System.out.println("\n" + clazz.getName());
4951
if (hasSource) {
50-
File sourceFile = new File(sourceDir, className + ".java");
51-
try (FileReader reader = new FileReader(sourceFile);){
52-
char [] buffer = new char [(int)sourceFile.length()];
53-
reader.read(buffer);
54-
String source = String.valueOf(buffer);
52+
Path sourceFile = Path.of(sourceDir.getPath(), className + ".java");
53+
try {
54+
String source = Files.readString(sourceFile, StandardCharsets.UTF_8);
5555
int start = source.indexOf("package");
5656
start = source.indexOf("/*", start);
5757
int end = source.indexOf("* For a list of all");
58-
System.out.println(source.substring(start, end-3));
58+
System.out.println(source.substring(start+3, end-3));
5959
boolean skip = false;
6060
String platform = SWT.getPlatform();
6161
if (source.contains("OpenGL")) {

0 commit comments

Comments
 (0)