Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/org.eclipse.swt.examples/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.SWTStandaloneExampleSet.name
Bundle-SymbolicName: org.eclipse.swt.examples; singleton:=true
Bundle-Version: 3.108.900.qualifier
Bundle-Version: 3.108.1000.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-17
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -17,14 +17,15 @@
import static org.eclipse.swt.events.SelectionListener.widgetDefaultSelectedAdapter;
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.ResourceBundle;

import org.eclipse.swt.SWT;
Expand Down Expand Up @@ -287,18 +288,9 @@ private void openAddressBook() {
Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
shell.setCursor(waitCursor);

String[] data = new String[0];
try (FileReader fileReader = new FileReader(file.getAbsolutePath());
BufferedReader bufferedReader = new BufferedReader(fileReader);){

String nextLine = bufferedReader.readLine();
while (nextLine != null){
String[] newData = new String[data.length + 1];
System.arraycopy(data, 0, newData, 0, data.length);
newData[data.length] = nextLine;
data = newData;
nextLine = bufferedReader.readLine();
}
List<String> data = new ArrayList<>();
try {
data = Files.readAllLines(file.toPath());
} catch(FileNotFoundException e) {
displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
return;
Expand All @@ -309,13 +301,13 @@ private void openAddressBook() {
shell.setCursor(null);
}

String[][] tableInfo = new String[data.length][table.getColumnCount()];
String[][] tableInfo = new String[data.size()][table.getColumnCount()];
int writeIndex = 0;
for (String element : data) {
String[] line = decodeLine(element);
if (line != null) tableInfo[writeIndex++] = line;
}
if (writeIndex != data.length) {
if (writeIndex != data.size()) {
String[][] result = new String[writeIndex][table.getColumnCount()];
System.arraycopy(tableInfo, 0, result, 0, writeIndex);
tableInfo = result;
Expand Down Expand Up @@ -346,10 +338,8 @@ private boolean save() {
lines[i] = encodeLine(itemText);
}

try (FileWriter fileWriter = new FileWriter(file.getAbsolutePath(), false);){
for (String line : lines) {
fileWriter.write(line);
}
try {
Files.write(file.toPath(), List.of(lines), StandardOpenOption.TRUNCATE_EXISTING);
} catch(FileNotFoundException e) {
displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,13 +15,10 @@

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.util.ResourceBundle;

Expand Down Expand Up @@ -145,28 +142,16 @@ void open(String name) {
}

try {
FileInputStream stream= new FileInputStream(file.getPath());
try (Reader in = new BufferedReader(new InputStreamReader(stream))) {

char[] readBuffer= new char[2048];
StringBuilder buffer= new StringBuilder((int) file.length());
int n;
while ((n = in.read(readBuffer)) > 0) {
buffer.append(readBuffer, 0, n);
}
textString = buffer.toString();
stream.close();
} catch (IOException e) {
// Err_file_io
String message = MessageFormat.format(resources.getString("Err_file_io"), file.getName());
displayError(message);
return;
}
}
catch (FileNotFoundException e) {
textString = Files.readString(file.toPath());
} catch (FileNotFoundException e) {
String message = MessageFormat.format(resources.getString("Err_not_found"), file.getName());
displayError(message);
return;
} catch (IOException e) {
// Err_file_io
String message = MessageFormat.format(resources.getString("Err_file_io"), file.getName());
displayError(message);
return;
}
// Guard against superfluous mouse move events -- defer action until later
Display display = text.getDisplay();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -25,6 +25,7 @@
import static org.eclipse.swt.events.SelectionListener.*;

import java.io.*;
import java.nio.file.*;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
Expand Down Expand Up @@ -109,16 +110,8 @@ void menuOpen() {
return;

File file = new File(name);
try (FileInputStream stream = new FileInputStream(file.getPath())) {
Reader in = new BufferedReader(new InputStreamReader(stream));
char[] readBuffer = new char[2048];
StringBuilder buffer = new StringBuilder((int) file.length());
int n;
while ((n = in.read(readBuffer)) > 0) {
buffer.append(readBuffer, 0, n);
}
textString = buffer.toString();
stream.close();
try {
textString = Files.readString(file.toPath());
} catch (FileNotFoundException e) {
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);
box.setMessage("File not found:\n" + name);
Expand Down
Loading